Mark's Homework: Difference between revisions
Jump to navigation
Jump to search
(New page: ==Problem== Sample <math>sin(2 \pi t)</math> at 3Hz and take the DFT. Explain the results. ==MATLAB script== <pre> clear all; close all; f = 1; %sine wave frequency fs = 3; %sample frequ...) |
|||
Line 24: | Line 24: | ||
ylabel('x(t)') |
ylabel('x(t)') |
||
title('Input Signal') |
title('Input Signal') |
||
legend(' |
legend('Sampled signal', 'Original signal'); |
||
figure(2) |
figure(2) |
||
plot(f, abs(Xs)) |
plot(f, abs(Xs)) |
Revision as of 12:49, 9 November 2007
Problem
Sample at 3Hz and take the DFT. Explain the results.
MATLAB script
clear all; close all; f = 1; %sine wave frequency fs = 3; %sample frequency tmax = 600/fs; %go to tmax seconds -- 600 points T = 1/fs; t = 0:T:tmax; N=length(t); x = sin(2*pi*f*t); % My signal to transform t2 = 0:.01:tmax; x2 = sin(2*pi*f*t2); X=fft(x); Xs((N+1)/2:N) = X(1:(N+1)/2); %The fftshift didn't work for me Xs(1:(N+1)/2) = X((N+1)/2:N); %So this manually shifts the FFT f = -1/(2*T):1/(N*T):1/(2*T)-1/(N*T); figure(1) plot(t, x, '-o', t2, x2, 'r') xlabel('Time (s)') ylabel('x(t)') title('Input Signal') legend('Sampled signal', 'Original signal'); figure(2) plot(f, abs(Xs)) xlabel('Frequency') ylabel('X(f)') title('Graph of F[sin(2 \pi t)]')
Graphs
Explanation
In Figure 1. I took only 7 sample points. As you can see, the DFT (Figure 2) looks nothing like what it should look like (a spike at -1 and 1 Hz). This occurs because the edge effects account for 28% of the points. If you take a whole bunch more points, like that in Figure 3, the DFT looks much more what it should be as in Figure 4. With this many more points, the edge effects are much less noticeable, because the edge points are a small fraction of the total amount of sample points.