Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Representing frequency of n Hz needs sampling rate >2n Hz, not =2n (Read 30369 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

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.

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #1
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.

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #2
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.

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #3
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.

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #4
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.

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #5
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 ">=".

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #6
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 pair

wl=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 off


wl=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:1000
wl=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);
end

subplot(5,1,5)
x=x+tmp;
plot(x,'k');
axis(ax);
hold on;
plot(tmp,'r');
hold off;
-----
J. D. (jj) Johnston

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #7
(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
There's been what, already 5 posts about it? […] let's stop talking about ">" versus ">=".

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!

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #8
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.

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #9
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.

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #10
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.

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #11
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

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #12
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.

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #13
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
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.

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #15
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

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #16
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.


Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #17
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.

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #18
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

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #19
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

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #20
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."

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #21
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

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #22
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."

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #23
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?

Representing frequency of n Hz needs sampling rate >2n Hz, not =2n

Reply #24
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.