What do I not understand about the fft and angle functions?
조회 수: 12 (최근 30일)
이전 댓글 표시
EDITED VERSION
I am trying to create an example showing how to use the fft function to approximate the Fourier transform. My example is to calculate the Fourier transform of h(t) = 2*pi*exp(-2*pi*t)u(t). The analytic solution is H(f) = 1/(1+jf). Here is my code:
N=1024; % sample count
T=10; % h(t) very small for t > T
t=linspace(0,T,N); % N sample points
h=2*pi*exp(-2*pi*t); % low pass IR 1 Hz cut-off
H=T*fft(h)/N; % FFT calculation of Fourier transform
Hmag=abs(H(1:N/2)); % Magnitude calculation
Hphase=180*angle(H(1:N/2))/pi; % Phase in degrees
f=(0:N/2-1)/T; % frequency bins thru Nyquist freq
subplot(2,1,1);
semilogx(f,20*log10(Hmag))
grid on
subplot(2,1,2);
semilogx(f,Hphase)
grid on
The results are shown in my response to the answer to an earlier version of my question. The magnitude plot is fairly close to the analytic result, but the phase plot goes a bit crazy at higher frequencies. Where am I going wrong?
To repeat, my goal is to show the relationship between the FFT of a discrete time function and the Fourier transform of its continuous time counterpart. I expected a closer relationship.
댓글 수: 0
채택된 답변
Star Strider
2015년 2월 6일
I have some problems following your code. I invite you to take the analytic approach to see if you get the same result. If you have the Symbolic Math Toolbox, try this:
syms w0 t w L real
h=w0*exp(-w0*t);
H1 = int(h * exp(-j*w*t), t, 0, 2*pi);
H2 = simplify(H1, 'steps', 10);
H3 = rewrite(H1, 'sincos');
ReH3 = simplify(real(H3), 'steps', 10)
ImH3 = simplify(imag(H3), 'steps', 10)
phas = simplify(atan(ImH3/ReH3), 'steps', 10)
fphas = matlabFunction(phas)
The last result is:
fphas = @(w,w0)atan((w.*cos(pi.*w.*2.0)-w.*exp(pi.*w0.*2.0)+w0.*sin(pi.*w.*2.0))./(-w0.*cos(pi.*w.*2.0)+w0.*exp(pi.*w0.*2.0)+w.*sin(pi.*w.*2.0)));
Plug in values for the respective variables and see what you get.
댓글 수: 4
Star Strider
2015년 2월 8일
My pleasure!
The phase plot depends on the atan2 function, and any calculation involving the division of two uncertain floating-point numbers is going to be even more uncertain. (There are a number of computer science professionals here who may have some thoughts on this problem. I invite their contributions.)
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!