Chris' Page for HW 13 (Sampling at 3Hz): Difference between revisions
Jump to navigation
Jump to search
New page: '''Sample <math> sin( 2 \pi nt) </math> at 3Hz; take the DFT, explain the results.''' |
No edit summary |
||
Line 1: | Line 1: | ||
'''Sample <math> sin( 2 \pi nt) </math> at 3Hz; take the DFT, explain the results.''' | '''Sample <math> sin( 2 \pi nt) </math> at 3Hz; take the DFT, explain the results.''' | ||
<pre> | |||
t1 = 0:1/3:3; | |||
t2 = 0:1/1000:3; | |||
y1 = sin(2*pi*t1); | |||
y2 = sin(2*pi*t2); | |||
NFFT1 = 2^nextpow2(length(y1)); | |||
NFFT2 = 2^nextpow2(length(y2)); | |||
Y1 = fft(y1,NFFT1)/length(y1); | |||
Y2 = fft(y2,NFFT2)/length(y2); | |||
f1 = 1/3./(2*linspace(0,1,NFFT1/2)); | |||
f2 = 10000./(2*linspace(0,1,NFFT2/2)); | |||
figure(2) | |||
hold on | |||
h = stem(t1(1:10),y1(1:10),'fill','--'); | |||
set(get(h,'BaseLine'),'LineStyle',':') | |||
set(h,'MarkerFaceColor','green') | |||
plot(t1(1:10),y1(1:10), t2(1:3000), y2(1:3000)) | |||
legend('3Hz Sample Points','Sine sampled at 3Hz','Sine sampled at 1kHz') | |||
xlabel('Time in seconds') | |||
ylabel('Magnitude') | |||
title('Sin(2\pi t) Sampled at 3 Hz') | |||
hold off | |||
</pre> |
Revision as of 15:30, 14 December 2007
Sample at 3Hz; take the DFT, explain the results.
t1 = 0:1/3:3; t2 = 0:1/1000:3; y1 = sin(2*pi*t1); y2 = sin(2*pi*t2); NFFT1 = 2^nextpow2(length(y1)); NFFT2 = 2^nextpow2(length(y2)); Y1 = fft(y1,NFFT1)/length(y1); Y2 = fft(y2,NFFT2)/length(y2); f1 = 1/3./(2*linspace(0,1,NFFT1/2)); f2 = 10000./(2*linspace(0,1,NFFT2/2)); figure(2) hold on h = stem(t1(1:10),y1(1:10),'fill','--'); set(get(h,'BaseLine'),'LineStyle',':') set(h,'MarkerFaceColor','green') plot(t1(1:10),y1(1:10), t2(1:3000), y2(1:3000)) legend('3Hz Sample Points','Sine sampled at 3Hz','Sine sampled at 1kHz') xlabel('Time in seconds') ylabel('Magnitude') title('Sin(2\pi t) Sampled at 3 Hz') hold off