In this problem you will use the cursor tracker code from the previous homework
ID: 2291033 • Letter: I
Question
In this problem you will use the cursor tracker code from the previous homework assignment to measure frequency responses to various sinusoidal inputs and then generate a Bode plot. Use the Matlab file track cursor.m provided on Blackboard for a proportional controller with K = 0.1. After the tracker equilibrates, generate a sinusoidal input by moving the cursor back and forth and determine the gain and phase. The gain is the ratio of the amplitude of the output sinusoid over the amplitude of the input sinusoid, so if it tracks perfectly then the gain is 1 (0dB on a Bode plot). The phase is measured in degrees. 0 degrees is perfectly in phase, -180 degrees is perfectly out of phase. A slight lag behind the input will generate a negative phase (e.g. -25 degrees). You should use at least five input sinusoids of different frequencies. The lowest frequency input should be slow enough that the tracker is able to follow well (you may need to increase Nstop to get this data point), the fastest should be rapid enough that the tracker is not able to keep up, and the other three can be in between. Provide the input-output plots you used for each frequency and a table summarizing your estimates of the amplitude (in dB), phase (in degrees), and frequency (in rad/s). Use the data you gather to sketch a Bode plot.
The .m code referenced is as follows:
clear all, close all
% Identify screen resolution
set(0,'units','pixels')
screen_size = get(0,'screensize');
% Make figure the size of screen
figure('units','normalized','outerposition',[0 0 1 1])
% Number of time steps
Nstop = 150;
% Controller gain
K = 0.1;
for i = 1:Nstop
if i == 1 % initialize position of cursor tracker
y = 1;
end
axis([1 screen_size(3) 1 screen_size(4)]) % Set figure axes to size of screen
location = get(0, 'PointerLocation');
r = location(1); % Reference we are trying to track (horizontal position of cursor)
plot(r, 200, 'b.'); hold on % Plot a blue dot on horizontal position of cursor
e = r-y; % Error calculation
u = K*e; % Calculate control signal
y = y + u;
plot(y, 100, 'r.') % Plot a red dot on horizontal position tracking cursor
title([num2str(floor((i/Nstop)*100)), '% of Data Collection Time'])
pause(0.01)
end
Explanation / Answer
clear all, close all
% Identify screen resolution
set(0,'units','pixels')
screen_size = get(0,'screensize');
% Make figure the size of screen
figure('units','normalized','outerposition',[0 0 1 1])
% Number of time steps
Nstop = 150;
% Controller gain
K = 0.1;
for i = 1:Nstop
if i == 1 % initialize position of cursor tracker
y = 1;
end
axis([1 screen_size(3) 1 screen_size(4)]) % Set figure axes to size of screen
location = get(0, 'PointerLocation');
r = location(1); % Reference we are trying to track (horizontal position of cursor)
plot(r, 200, 'b.'); hold on % Plot a blue dot on horizontal position of cursor
e = r-y; % Error calculation
u = K*e; % Calculate control signal
y = y + u;
plot(y, 100, 'r.') % Plot a red dot on horizontal position tracking cursor
title([num2str(floor((i/Nstop)*100)), '% of Data Collection Time'])
pause(0.01)
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.