Prev: Phase-frequency detector with synchronous output?
Next: nonzero phase spectrum from FFT of even function with zero imag part
From: fisico32 on 24 Jun 2010 17:12 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)), so it should give zero.... why not? thanks fisico32
From: robert bristow-johnson on 24 Jun 2010 17:18 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)), so it should give > zero.... > > why not? > you didn't sway the two halves with fftshift(). r b-j
From: dbd on 24 Jun 2010 17:58 On Jun 24, 2:12 pm, "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 give > zero.... > > why not? > > thanks > fisico32 When I try: >> x = fft([1 1 1 1 1 1]) x = 6 0 0 0 0 0 >> atan2(imag(x),real(x)) ans = 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
From: dbd on 24 Jun 2010 18:49 On Jun 24, 3:15 pm, "fisico32" <marcoscipioni1(a)n_o_s_p_a_m.gmail.com> wrote: > >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... That's why people learn to use atan2 in so many languages, including Matlab, as I did in my Matlab example. Dale B. Dalrymple
From: Greg Heath on 25 Jun 2010 08:38
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 |