Mark's Homework 13

From Class Wiki
Jump to navigation Jump to search

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

Figure 1. The sampled signal with only 7 sample points.
Figure 2. The DFT of Figure 1.
Figure 3. The same as Figure 1 but with 600 sample points, and zoomed in.
Figure 4. The DFT of Figure 3.


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.