How to plot the phase response of dft using fft in matlab
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I have a doubt, I was trying to plot the phase response of a sin wave using fft, but I got something that is kind of like noise. The double sided spectrum is symmetric about fs/2. Can anybody help me out? Isn't phase response of a sine wave typically like a slanted line passing through the origin?
Fs=3000;
t=0:1/Fs:(0.5-1/Fs);
S=sin(2*pi*50*t);
figure(1),plot(S);
L=length(S);
f =Fs*(0:(L/2))/L;
Y = fft(S,L);
P2 = abs(Y/L);
f2=Fs*(0:(L-1))/L;
figure(2),stem(f2,fftshift(P2));
phase=angle(Y);
figure(3), stem(f2,phase)
0 Kommentare
Antworten (1)
David Goodmanson
am 2 Jul. 2018
Hi SSG,
The angles look like noise because they are noise. The fft of the sine wave consists of peaks at +-50 Hz and is essentially zero at every other frequency, which is perfectly correct. (There are ways to mess up the fft and not get that exact result, but you avoided the pitfalls). Fftshift is already there in the code so you can see all this with
f2 = Fs*(-L/2:(L/2-1))/L;
figure(2),semilogy(f2,abs(fftshift(P2)));
At frequencies other than +-50 Hz, the amplitude is so small that the angle computed by the code is meaningless. It's noise.
What you may be thinking about for phase response is the following. Suppose you have a real symmetric function g(t)in the time domain. Its transform is a real symmetric function h(f) in the frequency domain. For the time-shifted function g(t-t0), its transform is h(f)*exp(-2*pi*i*f*t0). Using unwrap(angle(... on that function gives -2*pi*f*t0 which is a slanted line. With real data you can do a linear fit to find t0.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Discrete Fourier and Cosine Transforms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!