              # Experiment 3: Open-loop Frequency Response Analysis Connect the motor to the PC and open up MATLAB as in previous experiments

Remember to go to system processes and set the number of cores used by the MATLAB application to one.

(1)    Find the corner frequency of the motor system.

Feed in a small sine wave signal into the input of the motor speed block at a low frequency like 1 rad/sec. Adjust the frequency until the phase of the output signal is about 45 degrees lagging the phase of the input signal. This frequency is one of the corner frequencies of the DC motor. The other corner frequency will be when the phase of the output signal is lagging the input signal by 135 degrees.

(2)    Measure the open-loop frequency response of the motor system.

The input is the input of the motor speed block and the output is the output of the motor speed block.  Feed a sine wave into the input and measure the gain of the velocity of the motor and its phase over the range of frequencies from 1 rad/sec to 1000 rad/s. If possible take a few more measurements beyond the above frequency band.  The further the frequency passes the band from both ends the more accurate results you can get for controller design in a later stage.

(4) Find phase and gain margin of the motor (speed output) for a unit feedback and unit proportional control system

Use the methods described in the terminology section to measure the gain margin and phase margin of the motor (speed output) block We begin by making sure the motor is connected to Hilink control board as shown below.

Note: P0_A could also be red+black and P0_B could also be purple under our new colour code. Once the motor is correctly connected to the Hilink control board and the control board is correctly connected to the PC, open MATLAB. Open windows task manager and set the number of cores that the MATLAB process operates on to only 1. In the MATLAB command window set S = inf and T = 1/2048.

Task 1 - Corner (pole) frequencies

Construct the Simulink model shown below using the template found here and the motor speed block you have used in previous experiments.

Remove the output filter by setting its time constant from 0.01 to zero.  Here, this filter can only be used when the measured frequency is too noisy to measure and less than one tenth of the bandwidth of the filter. Adjust the frequency of the sine wave input so that there is a phase shift of 45 degrees between the input and output. A phase shift of 45 degrees corresponds to a shift of 1/8 of the period of the wave as shown below. This frequency is the frequency of the 1st pole. Since the motor speed block is a second order system there exists another pole. The location of this pole is when the phase shift between the input and output is 135 degrees or 3/8 the period of the wave. Adjust the frequency of the sine wave input until you find the location of the second pole. Record the position of both corner frequencies. If it is too hard to measure the phase shift due to large differences in input and output amplitude adjust the amplitude of the sine wave and the gain of the gain block so that the two sine waves in the scope has approximately the same amplitude.

Note: You can add a DC component  to the sine wave input using a constant block and a sum block in order to avoid  the nonlinearity at zero speed.  If you have difficulty to measure the phase difference simulate sin(t) and sin(t+f) using different f and study the difference between the two waves in order to figure out the relation between the wave forms and their phase difference.

Task 2 - Open loop frequency response

Keep the same Simulink model constructed in task 1 for task 2. This is an open loop model as the goal of this task is to measure the frequency response of the system; an open loop measurement. The gain block between the input and scope is used only to better visualise the signals and should not be used in the peak-to-peak voltage measurement of the input. If the input signal is too small to take measurements off in relation to the output signal (such as time difference in peaks) you may increase the gain of the gain block so as it makes the amplitude of the input roughly the same as the amplitude of the output and vice versa.

Measure the frequency response of the open loop real time control system for the open loop bode plot as follows.  Set the amplitude of the sine wave block to 3 and adjust the frequency to 1 rad/sec. For a number of frequencies ranging from 1 rad/sec up to a frequency at least 10 times higher than the highest pole frequency obtained in Task 1 make a table through experiment in terms of the followings: frequency (rad/sec), frequency (Hz), time difference between adjacent peaks (s), phase shift (degree), input (peak to peak), output (peak to peak) and the gain as a ratio of the peak to peak output over the peak to peak input.  Taking extra measurements close to the pole frequencies and draw a bode plot for the open loop system.

The properties of the output signal can be measured using either the Simulink scope or a MATLAB plot using the method given in experiment 1. It is suggested (in the interest of time) to export your data to MATLAB and then plot it. Using the data cursor measure things like time difference in peaks. If the number of periods in the MATLAB plot is too high adjust the "limit data point to" value to a lower number to effectively zoom in on the waveform. The peak-to-peak voltage of the input should always be 6 assuming the amplitude of the sine wave is 3.

Note: the only measurements that need to be taken whilst conducting this part of the experiment are frequency, time difference between peaks and peak-to-peak voltage of the output.

The other columns in the table can be calculated as such:

Absolute phase shift (degrees) = (Time Difference in the peaks)*(Frequency in Hertz)*(360 degrees)

Gain = (Output voltage)/(Input voltage)

Adjust the frequency of the sine wave input from 1 rad/sec to 400 rad/sec by going up the decades in the semi log axis.

Once all the data is collected produce the bode plots for the motor.

Using what you have learnt in class and in the preparation for this experiment, calculate the transfer function from the experimental results.  It should be a second order system.  If you cannot determine the transfer function from the bode plot try to draw bode plots for a number of second order systems with different gains and corner frequencies in order to figure out the relation between the bode plot and the transfer function.

Compare the bode plots of the motor and the estimated transfer functions from this experiment and experiment 2 and comment on their accuracy.

Compare the step response of the motor and the estimated transfer functions from this experiment and experiment 2 and comment on their accuracy.

Task 3: Phase and Gain margin measurement

Keep the same system as in earlier tasks.

Adjust the frequency of the reference signal until the reference signal and output signal have the same peak-to-peak value. Record the phase shift at the frequency. The phase margin is 180 degrees plus the phase shift at this frequency for a unit feedback and unit P control system.

Now adjust the frequency of the reference signal until the reference signal and output signal is completely out of phase
(phase shift of 180 degrees). Measure the gain of the system at this frequency in dB. The inverse of this gain (negative value in dB) is known as the gain margin for a unit feedback and unit P control system When the phase shift of 180 degrees (out of phase) can only be achieved at an infinite frequency the gain margin will be infinite.

Is this the same as what was expected from the bode plots produced in Task 2?

Task 4: Motor Transfer Function of Position Output

Determine the transfer function of the motor when position is the output in both degrees and radians based on the transfer function for motor velocity determined in Task 2.

Tip: As this process may be tedious you may wish to use a variable frequency MATLAB loop to automate the procedure. A template for this is available here

Note: The motor speed block in this program should be replaced using the one you used in previous experiment with output in rad/sec.  The output filter should be removed by setting its time constant from 0.01 to zero.  The gain at the output of the cos block can be changed for improved measurements.  For example, reduce it at a low frequency in order to avoid saturation and increase it at a high frequency to reduce the effects of encoder noise.

You should run the m file first.  Do not build and connect the Simulink program.  The program in the m file will do it for you.

The following program can be used to view the results.