Fourier Transform: getting mag + phase then using those to plot original signal

后端 未结 2 1933
感动是毒
感动是毒 2021-01-28 14:45

Hi guy\'s I\'m working on simple signals and I want to calculate the Fourier transform of a signal, get the magnitude and phases, then reconstruct the original signal from that.

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-28 15:09

    The problem is caused by round-off errors in phase, so don't use them when calulating the sine and consine of the phase angles. Instead, use trig identities cos(atan(A))=(1+A^2)^(-1/2), and sin(atan(A))=A*(1+A^2)^(-1/2), and so

    re = mag .* real(F)./sqrt(real(F).^2+imag(F).^2);
    im = mag .* imag(F)./sqrt(real(F).^2+imag(F).^2);
    

    EDIT: I think that if you want to change the phase angle by S, this will do the trick:

    re = mag .* (real(F)*cos(S)-imag(F)*sin(S))./sqrt(real(F).^2+imag(F).^2);
    im = mag .* (real(F)*sin(S)+imag(F)*cos(S))./sqrt(real(F).^2+imag(F).^2);
    

    EDIT2: You will still sometimes get bad results with non-zero imaginary part (e.g. if S=pi), and you will need to plot either stem(real(x_i)) or stem(1:length(x_i),x_i) as Luis suggested.

提交回复
热议问题