# is normalizing FFT magn spectrum different for Nyquist-frequency's bin?

Started by November 3, 2010
```On Nov 8, 8:31 am, Rick Lyons <R.Lyons@_BOGUS_ieee.org> wrote:
> On Sun, 7 Nov 2010 12:18:24 -0800 (PST), Dirk Bell
> <bellda2...@cox.net> wrote:
>               [Snipped by Lyons]
> >The real problem here is that if there is a bin at exactly Nyquist
> >(i.e. FFT size is even) the bin magnitude does not determine the
> >magnitude of the signal component at exactly Nyquist. Ex: If I sample
> >a real sinusoid at Nyquist I can get all zeros, alternating max/min
> >values, or anything in between.
>
> >What can you say from the result? You can figure out a lower bound on
> >the magnitude.  Not real useful for spectral estimation no matter how
> >you normalize it.
> >Dirk
>
> Hi Dirk,
>   Good post!
>
> Yes, the spectral magnitude of a sinusoid whose
> freq is Fs/2 depends on the initial time-domain
> phase of the sinusoid.

Since I did not know this,I thought that others might not also.
Therefore, I wrote a little demo in MATLAB:

close all, clear all, clc

Fs = 1
dt = 1/Fs        % 1

f0 = Fs/2        % 0.5 Hz Nyquist
T0 = 1/f0        % 2 sec Nyquist period
T = 4*T0         % 8 sec (4 Nyquist periods)
N = T/dt         % 8
t = dt*(0:N-1);  % 0:7
j=0
for i = 1:10:361
j=j+1;
phaseref(j,1) = (i-1);
x = cos(2*pi*f0*t + pi*phaseref(j)/180);
X = fft(x)/N;
absX(j,:)   = abs(X);
phaseX(j,:) = 180*angle(X)/pi;
end
absX(absX < 1e-15) = 0; % mitigate roundoff error
phase(absX < 1e-15) = 0;

%Complete Tabulation
absresult   = [(1:j)' absX  ]
phaseresult = [(1:j)' phaseX]

% Nyquist Tabulation
disp('Original Phase     FFT Amplitude    FFT Phase')
result = [phaseref absX(1:j,N/2+1) phaseX(1:j,N/2+1)]

% Original Phase     FFT Amplitude    FFT Phase
%
% result =
%
%             0            1            0
%            10      0.98481            0
%            20      0.93969            0
%            30      0.86603            0
%            40      0.76604            0
%            50      0.64279            0
%            60          0.5            0
%            70      0.34202            0
%            80      0.17365            0
%            90            0            0
%           100      0.17365          180
%           110      0.34202          180
%           120          0.5          180
%           130      0.64279          180
%           140      0.76604          180
%           150      0.86603          180
%           160      0.93969          180
%           170      0.98481          180
%           180            1          180
%           190      0.98481          180
%           200      0.93969          180
%           210      0.86603          180
%           220      0.76604          180
%           230      0.64279          180
%           240          0.5          180
%           250      0.34202          180
%           260      0.17365          180
%           270            0          180
%           280      0.17365            0
%           290      0.34202            0
%           300          0.5            0
%           310      0.64279            0
%           320      0.76604            0
%           330      0.86603            0
%           340      0.93969            0
%           350      0.98481            0
%           360            1            0
%

figure
subplot(211)
plot(phaseref(1:j),absX((1:j),N/2+1),'o')
xlabel('Original Nyquist Phase')
ylabel('FFT Nyquist Amplitude')
title('FFT Nyquist Results (Original Nyquist Amplitude = 1))')
subplot(212)
plot(phaseref(1:j),phaseX((1:j),N/2+1),'o')
xlabel('Original Nyquist Phase')
ylabel('FFT Nyquist Phase')

Hope this helps.

Greg

```
```On Mon, 8 Nov 2010 20:27:26 -0800 (PST), Greg Heath
<heath@alumni.brown.edu> wrote:

[Snipped by Lyons]

>Since I did not know this,I thought that others might not also.
>Therefore, I wrote a little demo in MATLAB:
>
>close all, clear all, clc
>
>Fs = 1
>dt = 1/Fs        % 1
>
>f0 = Fs/2        % 0.5 Hz Nyquist
>T0 = 1/f0        % 2 sec Nyquist period
>T = 4*T0         % 8 sec (4 Nyquist periods)
[Snipped by Lyons]

>xlabel('Original Nyquist Phase')
>ylabel('FFT Nyquist Phase')
>
>
>Hope this helps.
>
>Greg

Hi Greg,
That's a nice demo.

[-Rick-]

```
```>On Nov 8, 8:31 am, Rick Lyons <R.Lyons@_BOGUS_ieee.org> wrote:
>> On Sun, 7 Nov 2010 12:18:24 -0800 (PST), Dirk Bell
>> <bellda2...@cox.net> wrote:
>>               [Snipped by Lyons]
>> >The real problem here is that if there is a bin at exactly Nyquist
>> >(i.e. FFT size is even) the bin magnitude does not determine the
>> >magnitude of the signal component at exactly Nyquist. Ex: If I sample
>> >a real sinusoid at Nyquist I can get all zeros, alternating max/min
>> >values, or anything in between.
>>
>> >What can you say from the result? You can figure out a lower bound on
>> >the magnitude.  Not real useful for spectral estimation no matter how
>> >you normalize it.
>> >Dirk
>>
>> Hi Dirk,
>>   Good post!
>>
>> Yes, the spectral magnitude of a sinusoid whose
>> freq is Fs/2 depends on the initial time-domain
>> phase of the sinusoid.
>
>Since I did not know this,I thought that others might not also.
>Therefore, I wrote a little demo in MATLAB:
>
```
```>>On Nov 8, 8:31 am, Rick Lyons <R.Lyons@_BOGUS_ieee.org> wrote:
>>> On Sun, 7 Nov 2010 12:18:24 -0800 (PST), Dirk Bell
>>> <bellda2...@cox.net> wrote:
>>>               [Snipped by Lyons]
>>> >The real problem here is that if there is a bin at exactly Nyquist
>>> >(i.e. FFT size is even) the bin magnitude does not determine the
>>> >magnitude of the signal component at exactly Nyquist. Ex: If I sample
>>> >a real sinusoid at Nyquist I can get all zeros, alternating max/min
>>> >values, or anything in between.
>>>
>>> >What can you say from the result? You can figure out a lower bound on
>>> >the magnitude.  Not real useful for spectral estimation no matter how
>>> >you normalize it.
>>> >Dirk

>>
>>Since I did not know this,I thought that others might not also.
>>Therefore, I wrote a little demo in MATLAB:

Hmm, don't know what happened to my last post above.

Thanks Greg, Dirk, I couldn't find this anywhere on the net, and your input
to this post has been very helpful. Greg's demo is great to visualize the
impact that the Nyquist phase on output FFT magnitude.
```
```For even length FFTs, the Nyquist bin shouldn't represent
any magnitude of the Nyquist frequency, since only
frequency content strictly below the Nyquist frequency
should be present (assuming non-aliased spectrum) and/or
be properly representable in an FFT result.

IMHO. YMMV.
--
rhn A.T nicholson d.0.t C-o-M
```
```Ron N. <rhnlogic@yahoo.com> wrote:

>For even length FFTs, the Nyquist bin shouldn't represent
>any magnitude of the Nyquist frequency, since only
>frequency content strictly below the Nyquist frequency
>should be present (assuming non-aliased spectrum) and/or
>be properly representable in an FFT result.

I love the way "Nyquist bin" rolls up two overused DSP concepts
into one meaningless two-word phrase.

S.
```
```On Nov 14, 10:41&#4294967295;pm, spop...@speedymail.org (Steve Pope) wrote:
> Ron N. <rhnlo...@yahoo.com> wrote:
> >For even length FFTs, the Nyquist bin shouldn't represent
> >any magnitude of the Nyquist frequency, since only
> >frequency content strictly below the Nyquist frequency
> >should be present (assuming non-aliased spectrum) and/or
> >be properly representable in an FFT result.

anything can happen.  it is certainly possible (due to practical anti-
alias filtering) that there is *some* non-zero component at Nyquist,
but if the input is real, the imaginary part of that component is
zero.  the question is "how big of a sinusoid at Nyquist results in
the quantity in X[N/2]?"  and the answer depends on what phase you
assume, because multiple phases (with corresponding amplitudes) will
result in the same value of the "Nyquist bin".

>
> I love the way "Nyquist bin" rolls up two overused DSP concepts
> into one meaningless two-word phrase.

i don't consider it meaningless at all.  if the FFT length is N and N
is even, then the "Nyquist bin" is X[N/2].  if x[n] is real then X
(the "DC bin") and X[N/2] are real (imag part is zero).  if N is odd,
there is no Nyquist bin but there remains a DC bin.

r b-j
```
```robert bristow-johnson  <rbj@audioimagination.com> wrote:

>On Nov 14, 10:41&#4294967295;pm, spop...@speedymail.org (Steve Pope) wrote:

>> I love the way "Nyquist bin" rolls up two overused DSP concepts
>> into one meaningless two-word phrase.

>i don't consider it meaningless at all.  if the FFT length is N and N
>is even, then the "Nyquist bin" is X[N/2].  if x[n] is real then X
>(the "DC bin") and X[N/2] are real (imag part is zero).  if N is odd,
>there is no Nyquist bin but there remains a DC bin.

My reaction to this argument is aligned with some of the things
Dale has been posting recently: there a leap involved from the concept
of an FFT, to the FFT input having been sampled from some continuous input.

The FFT itself has no "Nyquist" concept associated with it.  Only
in some special contexts is this maybe true.  So I feel that, in isolation,
the "Nyquist bin" concept has no particular meaning.  It's not a
property of the FFT.

Just my opinion.

Steve
```
```Ron N. <rhnlogic@yahoo.com> wrote:

> For even length FFTs, the Nyquist bin shouldn't represent
> any magnitude of the Nyquist frequency, since only
> frequency content strictly below the Nyquist frequency
> should be present (assuming non-aliased spectrum) and/or
> be properly representable in an FFT result.

For practical problems, I agree.

Otherwise, the FFT and IFFT each tranform N complex values
into N complex values, such that, not counting floating point
rounding errors, you get back out what went in if you transform
back again.

Also, the 'strictly below' condition really only applies to the
continuous transform, and even there the only case where it
fails is with a delta function at Fs/2.  (A zero width integral
of a finite valued function is zero.)

In addtion, Nyquist frequency question only applies to sampled
continuous functions.  While that is one use for the FFT, the
transform can really only be applied to the data it is given.

-- glen
```
```> Ron N. <rhnlo...@yahoo.com> wrote:
> > For even length FFTs, the Nyquist bin shouldn't represent
> > any magnitude of the Nyquist frequency, since only
> > frequency content strictly below the Nyquist frequency
> > should be present (assuming non-aliased spectrum) and/or
> > be properly representable in an FFT result.

One of my one of my old textbooks described it this way:

From "Principles of Communication Systems" by Taub and Schilling,
McGraw-Hill, 1971, pps. 160-161: "An interesting special case is the
sampling of a sinusoidal signal having the frequency Fm (i.e.: fs/2).
Here, all the signal power is concentrated precisely at the cut-off
frequency ... and there is some ambiguity about whether the signal
frequency is inside or outside the bandwidth.  To remove this
ambiguity, we require fs > 2Fm rather than that fs >= 2Fm.  To see
that this condition is necessary, assume that fs = 2Fm but that an
initial sample is taken at the moment the sinusoid passes through
zero.  Then all successive samples will also be zero.  This situation
is avoided by requiring fs > 2Fm."

Kevin McGee
```