## Topic: Representing frequency of n Hz needs sampling rate >2n Hz, not =2n (Read 13989 times)previous topic - next topic

0 Members and 1 Guest are viewing this topic.
• DonP
• Members (Donating)
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### 16 February, 2012, 11:13:36 AM
Each of the additional waves only needs a couple of points to represent their frequency. As per usual it appears that CA article really doesn’t get what the Nyquist theorem is saying…
....
The whole point is that a perfect DAC will produce a perfect 8kHz signal when sampled at 16kHz.

This key mistake in citing the Nyquist theorem leads to no end of potential trouble.  The sampling frequency has to be greater than 2x the maximum signal frequency you want to reproduce.

• icstm
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #1 – 17 February, 2012, 05:35:06 AM
Each of the additional waves only needs a couple of points to represent their frequency. As per usual it appears that CA article really doesn’t get what the Nyquist theorem is saying…
....
The whole point is that a perfect DAC will produce a perfect 8kHz signal when sampled at 16kHz.

This key mistake in citing the Nyquist theorem leads to no end of potential trouble.  The sampling frequency has to be greater than 2x the maximum signal frequency you want to reproduce.
agreed, but what people do not understand is that this leads to a perfect storage of the signal (within the quantum of the bits storing the amplitude. It is not an approximation that improves with higher sampling.

• db1989
• Global Moderator
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #2 – 17 February, 2012, 02:47:34 PM
The point was that you stated that a signal of n Hz can be perfectly represented by a sampling rate of 2n Hz, but that in fact this requires >2n Hz.

• pdq
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #3 – 17 February, 2012, 03:08:34 PM
As a further qualification, how close you can come to 2n Hz is a function of the period over which you observe the waveform. As you approach 2n Hz, the required time approaches infinity.

• greynol
• Global Moderator
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #4 – 17 February, 2012, 03:09:33 PM
Put another way it is impossible to know with any certainty the amplitude of a pure tone with only two regularly spaced points per cycle.
Is 24-bit/192kHz good enough for your lo-fi vinyl, or do you need 32/384?

• [JAZ]
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #5 – 18 February, 2012, 04:12:52 AM
While I agree that this is a scientific-based forum and that it is adequate to correct this small imprecision that we're used to say (as in saying only 2x instead of >2x)....

... can we stop arguing about it at last? There's been what, already 5 posts about it?

Back on topic, the number was mentioned in relation to the fact that the frequency can be properly reconstructed from the sampled one, which is something that we all agree on. For this, the images posted by xnor are quite representable of that fact.

We can talk about the needed time in case of frequencies nearing half the sampling rate, like pdq's last post, but let's stop talking about ">" versus ">=".

• Woodinville
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #6 – 18 February, 2012, 06:11:33 AM
Time for the graph at http://i238.photobucket.com/albums/ff228/j...ots/imaging.jpg

This shows in the first plot a sine wave a bit below fs/2.

As you go down, the red is the sum of the first 2, next 2, next 2 and next ?100? I think (the plot was made with a different script may years ago) images, and the resulting waveform with the images, all of them over fs/2, is shown behind the red waveform.

Notice how only images cause it to square off.

I'm not going to figure out the amplitudes for a triangle right here and now today (it should be easy, of course) but you're welcome to take script below, which is an enhanced version of the one that made the plot above, fix it, and pot that here.

But I think this makes the point that drawing striaght lines around plots of incividual samples doesn't show what a lot of people think it does.

Code: [Select]
`clear all;close all;fclose all;clc;len=8192;f0= 2*pi* .4;fs=2*pi;overs=512;w0=f0/overs;ws=fs/overs;ax=[ 1 len -1.5 1.5];iter(1:len)=(0:len-1);t=w0/ws*pi;amp=sin(t)/t;x(1:len)=amp*cos(iter*w0);subplot(5,1,1)plot(x,'k');axis( ax );# first image pairwl=ws-w0;wh=ws+w0;tmp(1:len)=0;t=wl/ws*pi;amp=sin(t)/t;tmp=tmp+amp*cos(iter*wl);t=wh/ws*pi;amp=sin(t)/t;tmp=tmp+amp*cos(iter*wh);subplot(5,1,2)x=x+tmp;plot(x,'k');axis(ax);hold on;plot(tmp,'r');hold off;wl=2*ws-w0;wh=2*ws+w0;tmp(1:len)=0;t=wl/ws*pi;amp=sin(t)/t;tmp=tmp+amp*cos(iter*wl);t=wh/ws*pi;amp=sin(t)/t;tmp=tmp+amp*cos(iter*wh);subplot(5,1,3)x=x+tmp;plot(x,'k');axis(ax);hold on;plot(tmp,'r');hold offwl=3*ws-w0;wh=3*ws+w0;tmp(1:len)=0;t=wl/ws*pi;amp=sin(t)/t;tmp=tmp+amp*cos(iter*wl);t=wh/ws*pi;amp=sin(t)/t;tmp=tmp+amp*cos(iter*wh);subplot(5,1,4)x=x+tmp;plot(x,'k');axis(ax);hold on;plot(tmp,'r');hold off;tmp(1:len)=0;for ii=4:1000wl=ii*ws-w0;wh=ii*ws+w0;t=wl/ws*pi;amp=sin(t)/t;tmp=tmp+amp*cos(iter*wl);t=wh/ws*pi;amp=sin(t)/t;tmp=tmp+amp*cos(iter*wh);endsubplot(5,1,5)x=x+tmp;plot(x,'k');axis(ax);hold on;plot(tmp,'r');hold off;`
-----
J. D. (jj) Johnston

• db1989
• Global Moderator
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #7 – 18 February, 2012, 02:40:37 PM
(as in saying only 2x instead of >2x)....

... can we stop arguing about it at last?

Who’s arguing about anything? Subsequent posts just elaborated upon the original correction—which, as DonP said in the first instance, is a very important one.

Quote

Since it apparently offends you so much, perhaps you would like it to be split to a separate thread. Edit: Which I have just done. Also, somehow I had thought DonP was pawelq!

• pdq
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #8 – 18 February, 2012, 11:16:57 PM
If you know that the waveform consists of a single unvarying sine wave whose frequency is less than half the sampling rate then a fairly small number of data points are required to determine the waveform's frequency and amplitude.

On the other hand, if there are multiple frequencies or the amplitude is not constant then you will need a longer observation period.

• greynol
• Global Moderator
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #9 – 19 February, 2012, 02:29:35 PM
On the other hand, if there are multiple frequencies or the amplitude is not constant then you will need a longer observation period.
A signal consisting of a tone with varying amplitude is not a pure tone.
Is 24-bit/192kHz good enough for your lo-fi vinyl, or do you need 32/384?

• pdq
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #10 – 19 February, 2012, 03:00:03 PM
A signal consisting of a tone with varying amplitude is not a pure tone.

I understand that. On the other hand, a tone that is not infinite in duration is also not a pure tone.

• Speedskater
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #11 – 19 February, 2012, 09:02:46 PM
On the other hand, if there are multiple frequencies or the amplitude is not constant then you will need a longer observation period.

We can't assign a single frequency to this type of waveform.
The amplitude may very depending on how the multiple frequencies sum.
Kevin Graf :: aka Speedskater

• 2Bdecided
• Developer
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #12 – 20 February, 2012, 06:32:17 AM
If you know that the waveform consists of a single unvarying sine wave whose frequency is less than half the sampling rate then a fairly small number of data points are required to determine the waveform's frequency and amplitude.

On the other hand, if there are multiple frequencies or the amplitude is not constant then you will need a longer observation period.
For any arbitrary waveform, correctly sampled, you can reconstruct all frequency components under fs/2 perfectly - but you need an infinite number of sample points.

If we consider quantisation it's far worse.

If however we consider that we don't care about anything beyond ~120dB down, it becomes easily realisable in 1990s-style DSP.

I know everyone here knows this. That computeraudiophile thread is just a parallel universe which I don't want to enter

Cheers,
David.

• icstm
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #13 – 20 February, 2012, 07:06:03 AM
If you know that the waveform consists of a single unvarying sine wave whose frequency is less than half the sampling rate then a fairly small number of data points are required to determine the waveform's frequency and amplitude.

On the other hand, if there are multiple frequencies or the amplitude is not constant then you will need a longer observation period.
For any arbitrary waveform, correctly sampled, you can reconstruct all frequency components under fs/2 perfectly - but you need an infinite number of sample points.
when you say an infinite number of sample points, over what period? An infinite number of sample points with 1sec, IS a higher sampling rate! An infinite number of points over an infinite is surely just handling the tails?

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #14 – 20 February, 2012, 07:59:48 AM
If you know that the waveform consists of a single unvarying sine wave whose frequency is less than half the sampling rate then a fairly small number of data points are required to determine the waveform's frequency and amplitude.

On the other hand, if there are multiple frequencies or the amplitude is not constant then you will need a longer observation period.
For any arbitrary waveform, correctly sampled, you can reconstruct all frequency components under fs/2 perfectly - but you need an infinite number of sample points.

If we consider quantisation it's far worse.

If however we consider that we don't care about anything beyond ~120dB down, it becomes easily realisable in 1990s-style DSP.

I know everyone here knows this. That computeraudiophile thread is just a parallel universe which I don't want to enter

Whenever infinity is mentioned, the temptation to become pedantic can be overpowering. Take this for exactly a pedantic question, because that is what it it is.

Isn't infinity an indefinite number? That's what I was taught in first semester calculus 48 years ago, if memory serves.  I'm under the impression from my work in calculus through grad school that equations involving infinity only make sense if you talk about infinity as the limit. IOW, a sampled wave approaches perfection as the number of sampled points approaches infinity.

In the real world nothing is perfect, and significance and relevance should be our greatest interest. As I think about it, in audio the number of sample points and the numerical precision of those samples are not serious limiting issues in our best or even mediocre currently implemented systems.

• Woodinville
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #15 – 21 February, 2012, 04:36:39 AM
If you know that the waveform consists of a single unvarying sine wave whose frequency is less than half the sampling rate then a fairly small number of data points are required to determine the waveform's frequency and amplitude.

On the other hand, if there are multiple frequencies or the amplitude is not constant then you will need a longer observation period.
For any arbitrary waveform, correctly sampled, you can reconstruct all frequency components under fs/2 perfectly - but you need an infinite number of sample points.

Ok, if you have 'n' samples, you'll get n/2+1 distinct lines out of a DFT.  Given positive and negative frequencies, you get n, exactly, as one would expect (depending on how you wish to count complex, of course).

You do need order of 1/df time for df being how close to fs/2 in Hertz you are, i.e. df = fs/2 - fmax where fs is sampling frequency and fmax is the highest frequency in the material.

It's order 1/df because that's the best you can do.  But you won't do much worse than 10 times that at any reasonable SNR.
-----
J. D. (jj) Johnston

• 2Bdecided
• Developer
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #16 – 21 February, 2012, 06:14:01 AM
In the real world nothing is perfect, and significance and relevance should be our greatest interest. As I think about it, in audio the number of sample points and the numerical precision of those samples are not serious limiting issues in our best or even mediocre currently implemented systems.
I agree entirely.

I think brick wall filters are both vilified and lauded unnecessarily. Wrongly vilified, because you can't hear their action. Wrongly lauded, because any filter that you can't hear when applied twice, but is sufficiently down at fs/2 and above, is good enough for ADC and DAC.

• 2Bdecided
• Developer
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #17 – 21 February, 2012, 06:20:22 AM
Ok, if you have 'n' samples, you'll get n/2+1 distinct lines out of a DFT.  Given positive and negative frequencies, you get n, exactly, as one would expect (depending on how you wish to count complex, of course).

You do need order of 1/df time for df being how close to fs/2 in Hertz you are, i.e. df = fs/2 - fmax where fs is sampling frequency and fmax is the highest frequency in the material.

It's order 1/df because that's the best you can do.  But you won't do much worse than 10 times that at any reasonable SNR.
When I first read this, I was a bit uncomfortable with the straight connection you made between a DFT and what frequencies you can store/reconstruct. I thought "what about windowing / glitches / non-periodic etc issues?". Still a bit concerned that what the DFT tells you is what is present if you loop the samples you have ad infinitum, but other than that I think I agree. As I'm not even worthy to polish your shoes I have no choice to agree anyway , but I had to stop and think for a bit.

Cheers,
David.

• Woodinville
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #18 – 21 February, 2012, 03:12:02 PM
When I first read this, I was a bit uncomfortable with the straight connection you made between a DFT and what frequencies you can store/reconstruct. I thought "what about windowing / glitches / non-periodic etc issues?". Still a bit concerned that what the DFT tells you is what is present if you loop the samples you have ad infinitum, but other than that I think I agree. As I'm not even worthy to polish your shoes I have no choice to agree anyway , but I had to stop and think for a bit.

Cheers,
David.

You're absolutely right that by just taking a DFT you're imposing circularity, and by doing so, you're incorporating any end-discontinuities, i.e. you're using a rectangular window (same thing).

But you still have the stated number of frequencies, it just includes information you probably didn't want.

If you window, you don't have quite the resolution you would otherwise have, but you get more "far frequency" resolution, of course, i.e. you don't have that end discontinuity splashing things all over the place.

It's fun to plot rectangular vs. han vs. blackman vs. some kaiser window, plot two things, first plot the passband to .5dB or so, and then plot the far-frequency response. Unsurprisingly you find lots of differences, but what they are can be surprising.  The narrowest passband is rectangular, if you think about it, that's because it has the widest scope (don't forget df * dt > 1 for the problem we're talking about here).  But, of course, you have that horrid far-frequency response. The blackman is wider than most anything, but yessiree it falls off like a brick... Perhaps unsurprisingly there is a conservation happening. Life is like that
-----
J. D. (jj) Johnston

• Woodinville
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #19 – 21 February, 2012, 03:23:01 PM
I think brick wall filters are both vilified and lauded unnecessarily. Wrongly vilified, because you can't hear their action. Wrongly lauded, because any filter that you can't hear when applied twice, but is sufficiently down at fs/2 and above, is good enough for ADC and DAC.

Well, something fun to try. Build the sharpest 20kHz passband filter you can with whatever FIR design program you have available.

Not one that goes 20kHz passband, 22kHz stop band, but as sharp as your software will design.

Then filter castinetts with it and see what happens. Use ABX, of course. Just give it a try.

Note, I just tried this in octave. remez in octave needs work
-----
J. D. (jj) Johnston

• xnor
• Developer
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #20 – 21 February, 2012, 04:59:36 PM
I tried this and couldn't hear any difference.

edit: used a linear phase fir filter, 200 dB down at ~21.6 kHz
"I hear it when I see it."

• Woodinville
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #21 – 22 February, 2012, 12:07:51 PM
I tried this and couldn't hear any difference.

edit: used a linear phase fir filter, 200 dB down at ~21.6 kHz

How long? Try 90dB down and as sharp as you can make it.
-----
J. D. (jj) Johnston

• xnor
• Developer
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #22 – 22 February, 2012, 01:20:22 PM
Even a 8192 samples long filter doesn't cause anything I could hear. Maybe because the passband has to be a lower to make the filter audible, e.g. 18 kHz instead of 21 kHz? Anyway the filter is quite steep. -6 dB at 21 kHz and -90 dB at 21.0157 kHz.
"I hear it when I see it."

• Porcus
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #23 – 22 February, 2012, 01:41:53 PM
Isn't infinity an indefinite number? That's what I was taught in first semester calculus 48 years ago, if memory serves.  I'm under the impression from my work in calculus through grad school that equations involving infinity only make sense if you talk about infinity as the limit. IOW, a sampled wave approaches perfection as the number of sampled points approaches infinity.

Well, in first-semester calculus, infinity is not a number at all. In higher courses, it might even be treated just as a number. Now you are talking about 'the' limit, and that 'the' is not necessarily a unique concept (first-semester calculus may or may not involve the distinction between pointwise and uniform limits).

For each given frequency < half the sampling frequency, a sine wave on time interval [-T, T] will be sampled better as T grows, and -- in the appropriate sense -- tend to perfection.
But:
Fix the time interval [-T,T] and let the frequency increase to half the sampling frequency. Then the sample quality tends to pretty bad. (And no, you don't have do do a sweep.)

So transients near the Nyquist may be badly sampled, in principle. But even if you can hear 22.05, it does not mean that you will hear that this is bad -- this physiology issue beats me, but: do you really hear a tone before the hair cells in the  inner ear have reached a steady resonance with the sound? That takes some oscillations, sampler takes some oscillations to pick up the frequency, wouldn't it?

• greynol
• Global Moderator
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n
##### Reply #24 – 22 February, 2012, 01:49:22 PM
That takes some oscillations, sampler takes some oscillations to pick up the frequency, wouldn't it?

No, it wouldn't.  A simple impulse will set them in motion, just like any other mechanical device.
Is 24-bit/192kHz good enough for your lo-fi vinyl, or do you need 32/384?