# Frequency Domain Undersampling?

Started by July 15, 2013
```I was using matlab and switched from using the function fft to freqz.

The data I was using turned out to be longer than the default freqz length
of 512 but I didn't pay any attention to it at first, but now I finally
caught it.

So for example had x[n] of length 1024 and used matlabs function X = freqz
(x).

Would that be equivalent of taking an fft of length 1024 and picking off
ever other frequency sample?  I assume some kind of aliasing would talk
place if one were to return that X to the sample domain.

(I understand freqz doesnt default to showing the negative side of the
spectrum).

_____________________________
Posted through www.DSPRelated.com
```
```On Mon, 15 Jul 2013 06:12:25 -0500, westocl wrote:

> I was using matlab and switched from using the function fft to freqz.
>
> The data I was using turned out to be longer than the default freqz
> length of 512 but I didn't pay any attention to it at first, but now I
> finally caught it.
>
> So for example had x[n] of length 1024 and used matlabs function X =
> freqz (x).
>
> Would that be equivalent of taking an fft of length 1024 and picking off
> ever other frequency sample?  I assume some kind of aliasing would talk
> place if one were to return that X to the sample domain.
>
> (I understand freqz doesnt default to showing the negative side of the
> spectrum).

If doing X in the time domain affects Y in the frequency domain when you
do a Fourier transform, then when you do X in the frequency domain it
will affect Y in the time domain.

So sampling in frequency will cause aliasing in time.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

```
```On Mon, 15 Jul 2013 06:12:25 -0500, "westocl" <31050@dsprelated>
wrote:

Hi westocl,
you asked a very good question.

>I was using matlab and switched from using the function fft to freqz.

OK.

>The data I was using turned out to be longer than the default freqz length
>of 512 but I didn't pay any attention to it at first, but now I finally
>caught it.

OK.

>So for example had x[n] of length 1024 and used matlabs function X = freqz
>(x).

It's perfectly OK to do that.
I don't like using both lower and upper cases variables
using the same letter, so let's write the following:

Spec_FFT = fft(x);  and

Spec_Freqz = freqz(x);

>Would that be equivalent of taking an fft of length 1024 and picking off
>ever other frequency sample?

In this special case where the only argument passed
to the freqz() command is 'x', *AND* the length of
'x' is 1024, then 'Spec_Freqz' is identical to
the first half of 'abs(Spec_FFT)'.

That's because Matlab's freqz(x) command *ALWAYS*
performs a 1024-pt FFT, ...but only plots the first
512 spectral magnitudes of that 1024-pt FFT.

>I assume some kind of aliasing would talk
>place if one were to return that X to the sample domain.

Correctamundo!  Give that young man a kewpie doll!

Here's the story:
Matlab's 'freqz(x)' command is a *VERY* clever routine.
It NEVER gives you incorrect results, regardless of
the length of 'x'.  The 'freqz(x)' command will always
produce 512 spectral magnitudes samples, covering the
freq range of 0 Hz -to- half the sample rate, regardless
of the length of 'x'.

If you asked a Matlab guy to plot 512 positive-freq
spec magnitude samples of an 80,000 sample input
sequence, he might do the following:

1) Perform an 80,000-pt DFT.
2) Compute spec magnitudes.
3) Discard the upper 40,000 magnitude samples.
4) Resample (interpolate) the pos-freq 40,000-sample
magnitude sequence down to 512 magnitude samples.

Ah, but those Matlab geeks are clever.  They don't
perform any messy "resampling".  If the original 'x'
is 80,000 samples, they wrap those 80,000 samples back
onto themselves modulo 1024.  (There's your time aliasing
westocl!).  And then they perform a 1024 FFT on the
"wrapped" time sequence.  That wrapping in the
time domain implements the desired spectral interpolation
in the freq domain!  Pretty neat, huh?
This is the kind of stuff that makes DSP so interesting!

>(I understand freqz doesnt default to showing the negative side of the
>spectrum).

Well yes, the command 'Spec_Freqz = freqz(x);' only plots
512 positive-frequency spectral magnitude samples.
But it is possible to plot a full positive- and negative-freq
spectrum if you pass the text argument 'whole' to the
'freqz(x)' command.  See Matlab's "help" info to see how
that's done.

Good Luck,
[-Rick-]
```
```On Tue, 16 Jul 2013 14:37:44 -0700, Rick Lyons
<R.Lyons@_BOGUS_ieee.org> wrote:

Oops!  In my last post I wrote:

"...the command 'Spec_Freqz = freqz(x);'
only plots 512 positive-frequency spectral
magnitude samples."

I should have written:

"...the command 'freqz(x);' only plots
512 positive-frequency spectral
magnitude samples."

The command 'Spec_Freqz = freqz(x);' would NOT
produce a plot.

Sorry for the confusion.

[-Rick-]
```
```>On Mon, 15 Jul 2013 06:12:25 -0500, "westocl" <31050@dsprelated>
>wrote:
>
>
>Hi westocl,
>   you asked a very good question.
>
>>I was using matlab and switched from using the function fft to freqz.
>
>OK.
>
>>The data I was using turned out to be longer than the default freqz
length
>>of 512 but I didn't pay any attention to it at first, but now I finally
>>caught it.
>
>OK.
>
>>So for example had x[n] of length 1024 and used matlabs function X =
freqz
>>(x).
>
>It's perfectly OK to do that.
>I don't like using both lower and upper cases variables
>using the same letter, so let's write the following:
>
>   Spec_FFT = fft(x);  and
>
>   Spec_Freqz = freqz(x);
>
>>Would that be equivalent of taking an fft of length 1024 and picking off
>>ever other frequency sample?
>
>In this special case where the only argument passed
>to the freqz() command is 'x', *AND* the length of
>'x' is 1024, then 'Spec_Freqz' is identical to
>the first half of 'abs(Spec_FFT)'.
>
>That's because Matlab's freqz(x) command *ALWAYS*
>performs a 1024-pt FFT, ...but only plots the first
>512 spectral magnitudes of that 1024-pt FFT.
>
>>I assume some kind of aliasing would talk
>>place if one were to return that X to the sample domain.
>
>Correctamundo!  Give that young man a kewpie doll!
>
>Here's the story:
>Matlab's 'freqz(x)' command is a *VERY* clever routine.
>It NEVER gives you incorrect results, regardless of
>the length of 'x'.  The 'freqz(x)' command will always
>produce 512 spectral magnitudes samples, covering the
>freq range of 0 Hz -to- half the sample rate, regardless
>of the length of 'x'.
>
>If you asked a Matlab guy to plot 512 positive-freq
>spec magnitude samples of an 80,000 sample input
>sequence, he might do the following:
>
>  1) Perform an 80,000-pt DFT.
>  2) Compute spec magnitudes.
>  3) Discard the upper 40,000 magnitude samples.
>  4) Resample (interpolate) the pos-freq 40,000-sample
>     magnitude sequence down to 512 magnitude samples.
>
>Ah, but those Matlab geeks are clever.  They don't
>perform any messy "resampling".  If the original 'x'
>is 80,000 samples, they wrap those 80,000 samples back
>onto themselves modulo 1024.  (There's your time aliasing
>westocl!).  And then they perform a 1024 FFT on the
>"wrapped" time sequence.  That wrapping in the
>time domain implements the desired spectral interpolation
>in the freq domain!  Pretty neat, huh?
>This is the kind of stuff that makes DSP so interesting!
>
>>(I understand freqz doesnt default to showing the negative side of the
>>spectrum).
>
>Well yes, the command 'Spec_Freqz = freqz(x);' only plots
>512 positive-frequency spectral magnitude samples.
>But it is possible to plot a full positive- and negative-freq
>spectrum if you pass the text argument 'whole' to the
>'freqz(x)' command.  See Matlab's "help" info to see how
>that's done.
>
>Good Luck,
>[-Rick-]

>Ah, but those Matlab geeks are clever.  They don't
>perform any messy "resampling".  If the original 'x'
>is 80,000 samples, they wrap those 80,000 samples back
>onto themselves modulo 1024.  (There's your time aliasing
>westocl!).  And then they perform a 1024 FFT on the
>"wrapped" time sequence.

Rick,
Sorry for the late reply. I was away from the computer.

This is great information but im still a little confused.  If one were to
wrap 80,000 samples onto themselves, woulnt i be loosing some information?

undergraduate DSP books, but its really the first time I took notice.

Could someone elabourate on this process?

_____________________________
Posted through www.DSPRelated.com
```
```On Wed, 17 Jul 2013 13:26:19 -0500, "westocl" <31050@dsprelated>
wrote:

[Snipped by Lyons]
>
>Rick,

Hi,

>Sorry for the late reply. I was away from the computer.

No problem.  Before I continue, let explain exactly what I mean by
"wrapping" data samples on them selves.

If we have a sequence  'x' = [1 2 3 4 5 100 200 300 400 500],
wrapping that sequence back on itself *modulo five* produces
the sequence 'y' = [101 202 303 404 505].
Wrapping that oritinal x sequence back on itself *modulo
three* produces the sequence 'z' = [705 307 503].
Westocl, make sure you understand how sequences 'y'
and 'z' are produced before continuing here.

>This is great information but im still a little confused.  If one were to
>wrap 80,000 samples onto themselves, woulnt i be loosing some information?

Yes, yes.  Your thinking is correct.

>undergraduate DSP books, but its really the first time I took notice.
>
>Could someone elabourate on this process?

I'll try.
Let's say you have 1024-sample time sequence
called 'x'.
The 1024-pt FFT of sequence 'x' ('Spec_x') will
produce 1024 (complex valued) freq-domain samples,
of the spectrum of 'x', covering
the freq range of 0 Hz to just under Fs Hz.

If you wrap 'x' back on itself *modulo 2* you'll
have 512 "aliased" 'x2' time samples.
The 512-pt FFT of sequence 'x2' (Spec_x2') will
produce 512 freq-domain samples, of the spectrum of
'x2', covering the freq range of 0 Hz to just
under Fs Hz.   So now you have reduced freq "granularity"
"lost information."

But here's the deal: 'Spec_x2' is
equal to every other sample of 'Spec_x'!
So 'Spec_x2' is a reduced-granularity
original 'Spec-x' spectrum.

If you wrap 'x' back on itself *modulo 4* you'll
have 256 "aliased" 'x4' time samples.
The 256-pt FFT of sequence 'x4' (Spec_x4') will
produce 256 freq-domain samples, of the spectrum of
'x4', covering the freq range of 0 Hz to just
under Fs Hz.   So now you have further-reduced
freq "granularity" in your spectral information.
And experience even more "lost information."

Likewise: 'Spec_x4' is equal to every fourth
sample of the original 'Spec_x'!

I hope that made some sense, and also makes
my last post a little more sensible.

[-Rick-]
```
```>On Wed, 17 Jul 2013 13:26:19 -0500, "westocl" <31050@dsprelated>
>wrote:
>
>  [Snipped by Lyons]
>>
>>Rick,
>
>Hi,
>
>>Sorry for the late reply. I was away from the computer.
>
>No problem.  Before I continue, let explain exactly what I mean by
>"wrapping" data samples on them selves.
>
>If we have a sequence  'x' = [1 2 3 4 5 100 200 300 400 500],
>wrapping that sequence back on itself *modulo five* produces
>the sequence 'y' = [101 202 303 404 505].
>Wrapping that oritinal x sequence back on itself *modulo
>three* produces the sequence 'z' = [705 307 503].
>Westocl, make sure you understand how sequences 'y'
>and 'z' are produced before continuing here.
>
>>This is great information but im still a little confused.  If one were
to
>>wrap 80,000 samples onto themselves, woulnt i be loosing some
information?
>
>Yes, yes.  Your thinking is correct.
>
some
>>undergraduate DSP books, but its really the first time I took notice.
>>
>>Could someone elabourate on this process?
>
>I'll try.
>Let's say you have 1024-sample time sequence
>called 'x'.
>The 1024-pt FFT of sequence 'x' ('Spec_x') will
>produce 1024 (complex valued) freq-domain samples,
>of the spectrum of 'x', covering
>the freq range of 0 Hz to just under Fs Hz.
>
>If you wrap 'x' back on itself *modulo 2* you'll
>have 512 "aliased" 'x2' time samples.
>The 512-pt FFT of sequence 'x2' (Spec_x2') will
>produce 512 freq-domain samples, of the spectrum of
>'x2', covering the freq range of 0 Hz to just
>under Fs Hz.   So now you have reduced freq "granularity"
>"lost information."
>
>But here's the deal: 'Spec_x2' is
>equal to every other sample of 'Spec_x'!
>So 'Spec_x2' is a reduced-granularity
>original 'Spec-x' spectrum.
>
>If you wrap 'x' back on itself *modulo 4* you'll
>have 256 "aliased" 'x4' time samples.
>The 256-pt FFT of sequence 'x4' (Spec_x4') will
>produce 256 freq-domain samples, of the spectrum of
>'x4', covering the freq range of 0 Hz to just
>under Fs Hz.   So now you have further-reduced
>freq "granularity" in your spectral information.
>And experience even more "lost information."
>
>Likewise: 'Spec_x4' is equal to every fourth
>sample of the original 'Spec_x'!
>
>
>I hope that made some sense, and also makes
>my last post a little more sensible.
>
>[-Rick-]

Thanks Rick,

This clears things up alot for me.

DSP is very intersting.

_____________________________
Posted through www.DSPRelated.com
```