During the Matlab part of this course, you already worked with the Matlab and th
ID: 2079006 • Letter: D
Question
During the Matlab part of this course, you already worked with the Matlab and the DAQ board for: Digital output to control analog motors (ML3.2) Analog input for measuring the voltage (ML3.3) rightarrow LV5DAQ_Analog_In_task.vi Displaying both signal and it's spectrum (ML4.2) rightarrow use of FFT_spectrum vi Dealing with noisy signals (ML4.4) Measuring the frequency response of a differentiator (EL8.3) a) Retrieve the Matlab programs mentioned above Doing measurements with the colorimeter through Matlab has three parts: Controlling all settings of the Colorimeter setup. Acquiring data (voltage versus time) Analyzing the data b) Prepare a Matlab code which measures the voltage versus time (block) signal/waveform, comparable to the signals in FA2c. Store voltage and time data.Explanation / Answer
a) >>>ML 3.2 program for Digital output to control analog motors
% CREATE A SESSION AND ADD 4 OUTPUT CHANNELS
A = daq.createSession('ni');
addDigitalChannel(A,'Dev2','port0/line0:3','OutputOnly')
% DEFINE MOTOT STEPS
% Each cycle of 4 steps turns the motor 72 degrees.
% Repeat this sequence 5 times to rotate the motor 360 degrees.
step1 = [1 0 1 0];
step2 = [1 0 0 1];
step3 = [0 1 0 1];
step4 = [0 1 1 0];
% TURN THE MOTOR COUNTERCLOCKWISE
outputSingleScan(A,step1);
outputSingleScan(A,step2);
outputSingleScan(A,step3);
outputSingleScan(A,step4);
% Repeat sequence 50 times to rotate the motor 10 times counterclockwise.
for motorstep = 1:50
outputSingleScan(A,step1);
outputSingleScan(A,step2);
outputSingleScan(A,step3);
outputSingleScan(A,step4);
end
%ROTATE THE MOTOR 72 DEGREE CLOCKWISE BY REVERSING THE STEPS
outputSingleScan(A,step4);
outputSingleScan(A,step3);
outputSingleScan(A,step2);
outputSingleScan(A,step1);
% Turn off all the lines to allow the motor to rotate freely.
outputSingleScan(A,[0 0 0 0]);
>>>>ML 3.3
readVoltage(A, 'A4')
>>>>>ML4.2
Y = fft(A);
P = abs(Y/L);
P1 = P(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
subplot(2,1,1);plot(t,A);title('ORIGINAL SIGNAL');
xlabel('time');ylabel('Amplitude');
subplot(2,2,1);plot(f,P1);
title('Single-Sided Amplitude Spectrum of S(t)')
xlabel('f (Hz)');ylabel('|P1(f)|');
>>>>>>ML4.4
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
t=0:0.001:1; % time
X = A + 2*randn(size(t)); % A is corrupted by random noise
plot(1000*t(1:50),X(1:50))
title('Signal Corrupted with Random Noise')
xlabel('t (milliseconds)')
ylabel('X(t)')
>>>>EL8.3
Fs = 1000; % sample rate
dt = 1/Fs; % time differential
t = (0:length(drift)-1)*dt; % time vector
df = designfilt('differentiatorfir','FilterOrder',50,...
'PassbandFrequency',100,'StopbandFrequency',120,...
'SampleRate',Fs);
hfvt = fvtool(df,[1 -1],1,'MagnitudeDisplay','zero-phase','Fs',Fs);
legend(hfvt,'50th order FIR differentiator','Response of diff function');
v1 = diff(drift)/dt;
a1 = diff(v1)/dt;
v1 = [0; v1];
a1 = [0; 0; a1];
D = mean(grpdelay(df)); % filter delay
v2 = filter(df,[drift; zeros(D,1)]);
v2 = v2(D+1:end);
a2 = filter(df,[v2; zeros(D,1)]);
a2 = a2(D+1:end);
v2 = v2/dt;
a2 = a2/dt^2;
subplot(4,1,1);plot(t,v1);title('velocity vs time');
xlabel('time');ylabel('velocity');
subplot(4,2,1);plot(t,a1);title('acceleration vs time');
xlabel('time');ylabel('acceleration');
subplot(4,3,1);plot(t,v1);title('velocity vs time');
xlabel('time');ylabel('velocity');
subplot(4,4,1);plot(t,a1);title('acceleration vs time');
xlabel('time');ylabel('acceleration');
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.