Prev: nonzero phase spectrum from FFT of even function with zero imag part
Next: Reply stategy - was [Re: Use of MATLAB fftshift]
From: fisico32 on 24 Jun 2010 17:48 >On Jun 24, 5:12=A0pm, "fisico32" <marcoscipioni1(a)n_o_s_p_a_m.gmail.com> >wrote: >> Hello Forum, >> >> the fft of a rectangular, even, symmetric sequence show a nonzero real pa= >rt >> and a zero imaginary part. All good so far. >> >> However the phase spectrum is nonzero: zero at some frequencies, pi at so= >me >> frequencies , -pi at some others.... >> >> The phase spectrum is given by atan(Imag(fft)/real(fft)), so it should gi= >ve >> zero.... >> >> why not? >> > >you didn't sway the two halves with fftshift(). > >r b-j > Actually, on page 101 of Understanding digital signal processing by Richard Lyon , it is said (at the bottom) that " the particular pattern of pi and -pi values is an artifact of the software used to generate that figure. A different software package may show a different pattern.... as long as the nonzero phase samples are either +pi or -pi the phase results will be correct" Is this related to the fftshift you are mentioning?
From: fisico32 on 24 Jun 2010 18:15 >On Jun 24, 2:12=A0pm, "fisico32" <marcoscipioni1(a)n_o_s_p_a_m.gmail.com> >wrote: >... >> The phase spectrum is given by atan(Imag(fft)/real(fft)), so it should gi= >ve >> zero.... >> >> why not? >> >> thanks >> fisico32 > >When I try: >>> x =3D fft([1 1 1 1 1 1]) > >x =3D > > 6 0 0 0 0 0 > >>> atan2(imag(x),real(x)) > >ans =3D > > 0 0 0 0 0 0 >It works. > >Do you have an example with a problem? In fact, when you discover >magic like this would you always include the example in your initial >post please. > >Dale B. Dalrymple > thanks Dale, here what matlab does: f=[0 1 2 3 3 2 1]; (even sequence). A=fft(f); B=imag(A); (it is all zeros). C=angle(A) (it shows zero and pi values...) The function angle should just implement the inverse tangent...
From: fisico32 on 25 Jun 2010 11:47
>On Jun 24, 5:12 pm, "fisico32" <marcoscipioni1(a)n_o_s_p_a_m.gmail.com> >wrote: >> Hello Forum, >> >> the fft of a rectangular, even, symmetric sequence show a nonzero real part >> and a zero imaginary part. All good so far. >> >> However the phase spectrum is nonzero: zero at some frequencies, pi at some >> frequencies , -pi at some others.... >> >> The phase spectrum is given by atan(Imag(fft)/real(fft)), > >Incorrect. Look at the source code: Enter into the command line. > >type angle >type atan2 > >> so it should give zero.... >> >> why not? > >1. Choose your own examples and compare atan(y/x) with atan2(y,x). > >There are several other possibilities for not obtaining what you >expected. > >2. Was your sequence defined over the symmetric bipolar time interval > >tsb = -tmax : dt : tmax % dt = 1/Fs, N is odd > > = dt* [ -(N-1)/2 : (N-1)/2 ]; > >or the asymmetric bipolar time interval > >tab = -(tmax+dt) : dt : tmax % N is even > > = dt* [ -N/2 : N/2 - 1 ]; > >3. Did you use fft(xb), fft(fftshift(xb) or fft(ifftshift(xb)) ? > All will yield the correct amplitude. However > >a. X = fft(ifftshift(xb)) will always yield the correct phase >b. fft(fftshift(xb) will yield the correct phase if N is even > and you used xb(tab) >c. fft(xb) is not guaranteed to ever yield the correct phase. > >4. Even if you used a, roundoff may have caused > imag(X) to be very small but nonzero. > >An attempt at explaining how to use the correct combination >can be obtained from my post > >http://groups.google.com/group/comp.soft-sys.matlab/msg/ecedcba94094f742 > >Hope this helps. > >Greg >Hello Greg, thanks, that is a good explanation. simple things get complicated. I follow your answer. i am still unsure about why things work the way they do.... I feel like it is hard to trust matlab even on simple function like fft. I am interested in looking a the phase spectrum and its changes... Do you think I should always: if b is a 1D sequence, B=fft(b) and atan(imag(B)./ real(B)). his would give the correct phase. For a 2D matrix a I can use A=fft2(ifftshift(a)). To plot the correct phase using atan2(imag(A), real(A))..... I have tried A=fft2(a) and b=ifft2(A). it turns out that b is kind of equal to a. If I took the A=fft(a) and B=fft(b), they would have different phase spectra, with strange spikes in B... What preventive things can I do to avoid these issues? Just use fft2(ifftshift(a)) ? the magnitude |