why fft of an even and real signal in time domain gives imaginary part?

71 vues (au cours des 30 derniers jours)
2NOR_Kh
2NOR_Kh le 2 Déc 2022
Commenté : 2NOR_Kh le 3 Déc 2022
This is the question:
a. Create a real and even-symmetric signal for use as a test signal. Since this is easiest to do when the length is odd, take N to be odd (e.g., N = 21). Verify that the DFT of this signal is purely real, and that it is also even-symmetric.
This is my attempt:
I have a coine function which is real and even and I expecy its fourier transform to be real and conjugate symmetry. I applied f1=fftshift(abs(fft(x1))); for taking the fft and the imaginary part is zero. But for part b it asks:
b. Now take the FFT of the same signal, but with the length three times the original (i.e., N = 63). Verify that the transform is no longer purely real (unless, of course, your test signal were the impulse).
still with the same procedure the imaginary part is zero. Where did I make a mistake?
This is my code for a:
N = 21;
tmin=-1;
tmax=1;
t = linspace(tmin,tmax,N+1);
t(end) = [] ;
fs=1/abs(t(1)-t(2));
a = 2;
x1 = cos(a*pi*t);
figure,plot(t,x1);xlabel 'x axis', ylabel 'y axis', title 'cos(2*pi*t)'
k = ( (-(N-1)/2) : ((N-1)/2) )/N*fs;
f1=fftshift(abs(fft(x1)));
figure,plot(k,f1);xlabel 'x axis', ylabel 'y axis',
title 'fourier transform of cos(2*pi*t)'
figure,plot(k,imag(f1)),
title 'imaginary part of the fourier transform of cos(2*pi*t)'
xlabel 'x axis', ylabel 'y axis'
code for part b:
%% the same signal with three times more points
N2 = 63;
tmin=-1;
tmax=1;
t2 = linspace(tmin,tmax,N2+1);
t2(end) = [] ;
fs2=1/abs(t2(1)-t2(2));
a = 2;
x2 = cos(a*pi*t2);
figure,plot(t2,x2);xlabel 'x axis', ylabel 'y axis', title 'cos(2*pi*t)'
k2 = ( (-(N2-1)/2) : ((N2-1)/2) )/N2*fs2;
f2=fftshift(abs(fft(x2)));
figure,plot(k2,f2);xlabel 'x axis', ylabel 'y axis',
title 'fourier transform of cos(2*pi*t)'
figure,plot(k2,imag(f2)),
title 'imaginary part of the fourier transform of cos(2*pi*t)'
xlabel 'x axis', ylabel 'y axis';

Réponse acceptée

Walter Roberson
Walter Roberson le 2 Déc 2022
t = linspace(tmin,tmax,N+1);
t(end) = [] ;
Your signal must not return to origin in the final sample. You need a signal such that repmat of the signal would be multiple periods. For example if the signal was triangle 0 1 then if you input 0 1 0 then fft treats it as if it were an indefinite chain of 0 1 0 0 1 0 0 1 0 rather than as 0 1 0 1 0 1...
Also if you are going to use that k then you need to fftshift to plot properly. The negative frequencies are after the positive.
  9 commentaires
Walter Roberson
Walter Roberson le 3 Déc 2022
fft of "the same signal" "with length 63" is probably fft(x1, 63) rather than creating a new signal of length 63
2NOR_Kh
2NOR_Kh le 3 Déc 2022
Thanks for your attention. I fixed it and these are the results:
%%part a:
N = 21;
tmin=-1;
tmax=1;
t = linspace(tmin,tmax,N+1);
t(end) = [] ;
fs=1/abs(t(1)-t(2));
a = 2;
x1 = cos(a*pi*t);
figure,plot(t,x1);xlabel 'x axis', ylabel 'y axis', title 'cos(2*pi*t)'
k = ( (-(N-1)/2) : ((N-1)/2) )/N*fs;
f1=fftshift((fft(x1)));
figure,plot(k,f1);xlabel 'x axis', ylabel 'y axis',
Warning: Imaginary parts of complex X and/or Y arguments ignored.
title 'fourier transform of cos(2*pi*t)'
figure,plot(k,imag(f1)),
title 'imaginary part of the fourier transform of cos(2*pi*t)'
xlabel 'x axis', ylabel 'y axis';
%% partb:the same signal wit
h three times more points
N2=63;
k2 = ( (-(N2-1)/2) : ((N2-1)/2) )/N2*fs;
f2=fftshift((fft(x1,63)));
figure,plot(k2,f2);xlabel 'x axis', ylabel 'y axis',
Warning: Imaginary parts of complex X and/or Y arguments ignored.
title 'fourier transform of cos(2*pi*t)'
figure,plot(k2,imag(f2)),
title 'imaginary part of the fourier transform of cos(2*pi*t)'
xlabel 'x axis', ylabel 'y axis';
So, based on what we discuused so far, I've got to this conclusion that for N=21 the imaginary part is negligible since it in the range of power of -16. Ans as you said this id due to the round-off error.
I learned alot from you in this post and I appreciate it so much.

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 2 Déc 2022
You might like to look at Steve's blog on the topic.
  1 commentaire
2NOR_Kh
2NOR_Kh le 2 Déc 2022
It was a great link, I appreciate your help.
However, I couldnt find the answer for my question. In theory we expect the fourier transform of a real and even function to be real and conjugate symmetric but I cant see that in MATLAB. I chose cosine function from -1 to 1. So, the imaginary part of its fourier transform must be zero but it is not. Why?

Connectez-vous pour commenter.

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by