Why is my fourier transform graph so weird?

5 views (last 30 days)
Rafael
Rafael on 13 Jul 2014
Commented: David Young on 13 Jul 2014
Ok, so I am trying to proof fourier transform properties for discrete signals using MATLAB.
I will try to proof all properties, but I started with reflection on time and time/frequency shift properties.
Here is one of my codes, if you you run it you will see some really weird graphics. I don't quite understand why they are not coming out as sinoids or whatever. And I have to use fft for this, even though its a dft.
% Creating a discrete signal xn
N=15; % total number of elements
L=10; % numers different then 0
xn=[ones(1,L),zeros(1,N-L)];
n = -5:length(xn)-6;
%rectangle, starting at -5, ends at 4
%Creating xn shifted
xn2=[ones( 1,L), zeros(1,N-L)];
n2=0:length(xn2)-1;
% shifted it
%fourier transforms:
x = fft(xn);
t = -5:length(xn)-6;
w = -5*2*pi/N:2*pi/N:((length(xn)-6)*2*pi/N);
% FT for shifted signal:
x2 = fft(xn2);
t2 = 0:1:length(xn2)-1;
w2 = 0:2*pi/N:((length(xn)-1)*2*pi/N);
% Plotting graphs:
subplot(3,2,1);stem(n,xn); title('Signal');xlabel('N');ylabel('x[N]');
subplot(3,2,2);stem(n2,xn2); title('Shifted Signal 5');xlabel('N');ylabel('x[N]');
subplot(3,2,3);plot(t,x);title('FT on original Signal');xlabel('N');ylabel('X(n)');
subplot(3,2,5);plot(w,x);title('FT on original Signal');xlabel('w');ylabel('X(jw)');
subplot(3,2,4);plot(t2,x2);title('FT on shifted Signal');xlabel('N');ylabel('X(n)');
subplot(3,2,6);plot(w2,x2);title('FT on shifted Signal');xlabel('w');ylabel('X(jw)');
  5 Comments
Daniel kiracofe
Daniel kiracofe on 13 Jul 2014
Well, first thing, your calculation of t is probably not correct. You have this:
t = -5:length(xn)-6;
Why start at -5? That's where you started the time vector, but the frequency vector won't start there. For your given parameters, I think t should run from -7 to 7, not from -5 to 9. Similar logic applies for w.
Now let's talk about t2. Why is t2 different than t? t2 should be -7 to 7 as well. It's not clear to me why it should start at 0. When you shift the time of a signal, you do not shift its frequency content. Its the same.
Does that help?
David Young
David Young on 13 Jul 2014
You say: "I have to use fft for this, even though its [sic] a dft." The FFT is just an efficient implementation of the DFT, so that's not an issue.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!