The accuracy of collected data depends on how frequently it is sampled. Suppose
ID: 3814581 • Letter: T
Question
The accuracy of collected data depends on how frequently it is sampled. Suppose you have an underlying signal that is actually a sine wave, but your sampling frequency is low. The real data is y(t) = sin(t), where t is in radians. (a) Make a plot of sin (t), with three different arrays for 't': [0:.01:2*pi], [0:.5:2* pi], [0:1:2* pi] and corresponding arrays for y. You might want to call them t1, t2, t3, y1, y2, y3. Note that Matlab automatically connects the points with straight lines. (b) Use linear interpolation to estimate y2 and y3 at the values pi/2 and 3pi/2. What is the error? (c) Now fit y3 with a cubic spline and plot it. Estimate y3 at the values pi/2 and 3pi/2. What is the error?Explanation / Answer
% Solution for section (a)
% Program to plot sine function values at differeing sample values of time
t1 = [0:0.01:2*pi];
y1 = sin(t1);
t2 = [0:0.5:2*pi];
y2 = sin(t2);
t3 = [0:1:2*pi];
y3 = sin(t3);
%plot the sine functions
subplot(3, 1, 1); stem(t1, y1); title('Sine wave sampled at 0.01');
subplot(3,1, 2); stem(t2, y2); title('Sine wave sampled at 0.5');
subplot(3, 1, 3); stem(t3, y3); title('Sine wave sampled at 1');
% Solution for section (b): Linear Interpolation
%pi/2 approximately equals 3.14/2 = 1.57;
%In y2, the values of y2(1.5) and y2(2) should be used to compute y2(1.57);
y2PiBy2 = (y2(2) - y2(1.5)) * 1.57 / (2 - 1.5) + (y2(1.5)*2 - y2(2)*1.5)/(2-1.5)
Error1 = y2PiBy2 - sin(pi/2);
%In y3, the values of y3(1) and y3(2) should be used
y3PiBy2 = (y3(2) - y3(1)) * 1.57 / (2 - 1) + (y3(1)*2 - y3(2)*1)/(2-1)
Error2 = y3PiBy2 - sin(pi/2);
%3*pi/2 equals 4.71
%In y2, the values of y2(4.5) and y2(5) are used.
y2Pi3By2 = (y2(5) - y2(4.5)) * 4.71 / (5 - 4.5) + (y2(4.5)*5 - y2(5)*4.5)/(5-4.5);
Error3 = y2Pi3By2 - sin(3*pi/2)
%In y3, the values of y3(4) and y3(5) are used.
y3Pi3By2 = (y3(5) - y3(4)) * 4.71 / (5 - 4) + (y3(4)*5 - y3(5)*4)/(5-4);
Error4 = y3Pi3By2 - sin(3*pi/2);
%Solution for section (c): Using Cubic spline
x3 = 0:pi/2:2*pi;
y3CubicIntp = interp1(t3, y3, x3, 'spline');
stem(x3, y3CubicIntp); title('Plot of sine values using Cubic spline interpolation');
xlabel('t'); ylabel('Sine');
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.