DSPRelated.com
Forums

FFT phase

Started by john john December 31, 2006
Well Jerry,

I tend to think of complex numbers as x+iy. It has a nice order.
Obviously the other two posters also like this order.  But basically,
Jerry, I am easily annoyed.

Happy New Year,

Dirk



Jerry Avins wrote:
> dbell wrote: > > Guys, > > > > Much to my annoyance over the years, the convention for atan2() > > actually seems to be atan2(y,x) rather than atan2(x,y). Makes a > > difference. > > Why should that annoy you? Viven V =3D x + jy, |V| =3D sqrt(x^2 + y^2) and > arg(V) =3D arctan(y/z). Opposite over adjacent. > > Jerry > -- > Engineering is the art of making what you want from things you can get. > =AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=
=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF= =AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF
Rune Allnor wrote:
> Jerry Avins skrev: >> robert bristow-johnson wrote: >> >>> one thing to think about is both the concepts of "negative frequency" >>> in the FFT output as well as "negative time" in the FFT input (this is >>> what the MATLAB function "fftshift()" is for). >> I don't know Matlab. Does fftshift() give the same result as inverting >> the sign of all the odd-numbered samples? > > I don't know what effects that sign inversion might have, but I do > know that FFTSHIFT re-arranges the output of the FFT function. > > X = fft(x); > XX = fftshift(X); > > After the first line, X(1) contains the DC component of the spectrum > of x (matlab start indexing at 1, not 0). After the call to FFTSHIFT > the DC coefficient is located near N/2, N being the length of x, and > the spectrum XX is conjugate symmetric around the DC coefficient.
That's what changing the signs of alternate samples does, for the same reason that alternating coefficient signs converts a low-pass FIR to high-pass. Try it: you'll like it. it's like fftshift() for free. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
dbell wrote:
> Well Jerry, > > I tend to think of complex numbers as x+iy. It has a nice order. > Obviously the other two posters also like this order. But basically, > Jerry, I am easily annoyed. > > Happy New Year,
When writing fractions on one line, I tend to put the numerator first. Happy New Year! Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
john john wrote:
> Calculating the FFT of a waveform we have img and real values and is > possible to find magnitude and phase of sines. > > magnitude = (sqrt(real^2 +img^2))/float(number_of_samples); > > phase = (atan2(img/real) * 180) / PI;
This is an illegal function call. atan2() requires 2 parameters.
> I see that the phase is wrong.
Phase is meaningless without a defined reference point. Therefore your phase is likely not wrong, just referenced to a different location or with a different polarity than you expect. I usually flip the sign of alternating fft results to move the 0 phase reference to the center of my fft aperature. This way, any phase interpolation isn't done with reference to a potential discontinuity or window function null at the aperture boundry. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
Jerry Avins wrote:
> Rune Allnor wrote: > > Jerry Avins skrev: > >> robert bristow-johnson wrote: > >> > >>> one thing to think about is both the concepts of "negative frequency" > >>> in the FFT output as well as "negative time" in the FFT input (this is > >>> what the MATLAB function "fftshift()" is for). > >> I don't know Matlab. Does fftshift() give the same result as inverting > >> the sign of all the odd-numbered samples?
it has that effect in the *other* domain. fftshift(x) swaps (using MATLAB's horrible hard-wired 1-origin indexing) x(1:N/2) with x(N/2+1:N). this corresponds with multiplying X(n) with (-1)^(n-1) after the FFT. stated differently, if i am not mistaken, these two versions have the same result: x = x .* hanning(size(x)); X = fft(fftshift(x)); OR x = x .* hanning(size(x)); X = fft(x); X(2:2:N) = -X(2:2:N); % picks out and negates the "odd" elements
> > I don't know what effects that sign inversion might have, but I do > > know that FFTSHIFT re-arranges the output of the FFT function. > > > > X = fft(x); > > XX = fftshift(X); > > > > After the first line, X(1) contains the DC component of the spectrum > > of x (matlab start indexing at 1, not 0). After the call to FFTSHIFT > > the DC coefficient is located near N/2, N being the length of x, and > > the spectrum XX is conjugate symmetric around the DC coefficient. > > That's what changing the signs of alternate samples does, for the same > reason that alternating coefficient signs converts a low-pass FIR to > high-pass. Try it: you'll like it. it's like fftshift() for free.
"free"? i think sign inverting the "odd" half (or is it the "even" half? with MATLAB "only her hairdresser knows for sure"*) of the output is not necessarily cheaper than swapping the two halves in the input. r b-j * you'ld have to be watching TV in the 70s to remember this one.
robert bristow-johnson wrote:

   ...

Thanks.

> * you'ld have to be watching TV in the 70s to remember this one.
"Does she or doesn't she?" Dye her hair, that is. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Jerry Avins wrote:
> robert bristow-johnson wrote: > > ... > > Thanks.
FWIW.
> > * you'ld have to be watching TV in the 70s to remember this one. > > "Does she or doesn't she?" Dye her hair, that is.
George Carlin, in his wonderful old AM/FM (vinyl) album, cited that commercial as one that had subliminal sex in it (along with the plethora of ciggie commercials: "Should a gentleman offer a lady a Tipperello?"). "Does she or doesn't she?" Hope so! :-) r b-j
Jeff Caunter wrote:

> For a real FFT : > > magnitude = (sqrt(real^2 +img^2))/(FFT_Size/2); > > Value will be phasor length i.e. Peak. Remember, this will be modified if > window function used. > > phase = atan2(img/real); > > Value will be +/- PI > > Jeff
At the end of my code I have finally magnitude and phase. The phases are good for some kind of waves and bad for others waves. Seems that need to be adjusted. I have negative and positive phase values. In a different post than google I've seen: ---------------------------------------------- The negative frequencies in the FFT are due to the fact that they are calculated using complex numbers (i.e., numbers that have both real and imaginary components). For the purposes of displaying the calculated frequency levels, you can just ignore the negative frequencies. By the way, if you look at the negative levels, you can see that they are a mirror image of the positive levels. You would need the negative frequency components if you were doing any calculations, however, like if you wanted to perform the inverse FFT and get the original time-series (wave) data back ---------------------------------------------- I'm confused. Have you suggestion about how to adjust the phase in the correct value. I can't understand the phrase "....this will be modified if window function used.". Why?
Ron N. ha scritto:

> Phase is meaningless without a defined reference point. > Therefore your phase is likely not wrong, just referenced to > a different location or with a different polarity than you expect. > > I usually flip the sign of alternating fft results to move the 0 > phase reference to the center of my fft aperature. This way, > any phase interpolation isn't done with reference to a potential > discontinuity or window function null at the aperture boundry. > > > IMHO. YMMV. > -- > rhn A.T nicholson d.0.t C-o-M
You calculations are correct adjusting the phase as you say? You say that if the first phase value is "90" you put there "0" and than subtract at the others value "90"? In this way the first parameter is "0" and the other are rephased to this. Can you post an example about you calculations? At the end of my code I have finally magnitude and phase. The phase is good for some kind of waves and bad for others waves. Seems that need to be adjusted. I have negative and positive phase values. In a different post than google I've seen: ---------------------------------------------- The negative frequencies in the FFT are due to the fact that they are calculated using complex numbers (i.e., numbers that have both real and imaginary components). For the purposes of displaying the calculated frequency levels, you can just ignore the negative frequencies. By the way, if you look at the negative levels, you can see that they are a mirror image of the positive levels. You would need the negative frequency components if you were doing any calculations, however, like if you wanted to perform the inverse FFT and get the original time-series (wave) data back ---------------------------------------------- I'm confused.
Ron N. ha scritto:

> Phase is meaningless without a defined reference point. > Therefore your phase is likely not wrong, just referenced to > a different location or with a different polarity than you expect. > > I usually flip the sign of alternating fft results to move the 0 > phase reference to the center of my fft aperature. This way, > any phase interpolation isn't done with reference to a potential > discontinuity or window function null at the aperture boundry. > > > IMHO. YMMV. > -- > rhn A.T nicholson d.0.t C-o-M
You calculations are correct adjusting the phase as you say? You say that if the first phase value is "90" you put there "0" and than subtract at the others value "90"? In this way the first parameter is "0" and the other are rephased to this. Can you post an example about you calculations? At the end of my code I have finally magnitude and phase. The phase is good for some kind of waves and bad for others waves. Seems that need to be adjusted. I have negative and positive phase values. In a different post than google I've seen: ---------------------------------------------- The negative frequencies in the FFT are due to the fact that they are calculated using complex numbers (i.e., numbers that have both real and imaginary components). For the purposes of displaying the calculated frequency levels, you can just ignore the negative frequencies. By the way, if you look at the negative levels, you can see that they are a mirror image of the positive levels. You would need the negative frequency components if you were doing any calculations, however, like if you wanted to perform the inverse FFT and get the original time-series (wave) data back ---------------------------------------------- I'm confused.