IPB

Welcome Guest ( Log In | Register )

2 Pages V   1 2 >  
Reply to this topicStart new topic
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n, From: Badly drawn waveforms vs. the audio that’s actually output/93496
DonP
post Feb 16 2012, 17:13
Post #1





Group: Members (Donating)
Posts: 1477
Joined: 11-February 03
From: Vermont
Member No.: 4955



QUOTE (icstm @ Feb 16 2012, 06:56) *
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.
Go to the top of the page
+Quote Post
icstm
post Feb 17 2012, 11:35
Post #2





Group: Members
Posts: 121
Joined: 25-January 12
Member No.: 96698



QUOTE (DonP @ Feb 16 2012, 16:13) *
QUOTE (icstm @ Feb 16 2012, 06:56) *
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.

This post has been edited by icstm: Feb 17 2012, 11:35
Go to the top of the page
+Quote Post
db1989
post Feb 17 2012, 20:47
Post #3





Group: Super Moderator
Posts: 5275
Joined: 23-June 06
Member No.: 32180



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.
Go to the top of the page
+Quote Post
pdq
post Feb 17 2012, 21:08
Post #4





Group: Members
Posts: 3450
Joined: 1-September 05
From: SE Pennsylvania
Member No.: 24233



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.
Go to the top of the page
+Quote Post
greynol
post Feb 17 2012, 21:09
Post #5





Group: Super Moderator
Posts: 10348
Joined: 1-April 04
From: San Francisco
Member No.: 13167



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.


--------------------
Breath is found in plots and DR figures.
Go to the top of the page
+Quote Post
[JAZ]
post Feb 18 2012, 10:12
Post #6





Group: Members
Posts: 1798
Joined: 24-June 02
From: Catalunya(Spain)
Member No.: 2383



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 ">=".
Go to the top of the page
+Quote Post
Woodinville
post Feb 18 2012, 12:11
Post #7





Group: Members
Posts: 1415
Joined: 9-January 05
From: In the kitchen
Member No.: 18957



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. smile.gif

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
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
Go to the top of the page
+Quote Post
db1989
post Feb 18 2012, 20:40
Post #8





Group: Super Moderator
Posts: 5275
Joined: 23-June 06
Member No.: 32180



QUOTE ([JAZ] @ Feb 18 2012, 09:12) *
(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!

This post has been edited by db1989: Feb 21 2012, 10:55
Go to the top of the page
+Quote Post
pdq
post Feb 19 2012, 05:16
Post #9





Group: Members
Posts: 3450
Joined: 1-September 05
From: SE Pennsylvania
Member No.: 24233



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.
Go to the top of the page
+Quote Post
greynol
post Feb 19 2012, 20:29
Post #10





Group: Super Moderator
Posts: 10348
Joined: 1-April 04
From: San Francisco
Member No.: 13167



QUOTE (pdq @ Feb 18 2012, 20:16) *
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.


--------------------
Breath is found in plots and DR figures.
Go to the top of the page
+Quote Post
pdq
post Feb 19 2012, 21:00
Post #11





Group: Members
Posts: 3450
Joined: 1-September 05
From: SE Pennsylvania
Member No.: 24233



QUOTE (greynol @ Feb 19 2012, 14:29) *
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.
Go to the top of the page
+Quote Post
Speedskater
post Feb 20 2012, 03:02
Post #12





Group: Members
Posts: 139
Joined: 12-December 07
From: Cleveland, OH
Member No.: 49500



QUOTE (pdq @ Feb 18 2012, 23:16) *
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
Go to the top of the page
+Quote Post
2Bdecided
post Feb 20 2012, 12:32
Post #13


ReplayGain developer


Group: Developer
Posts: 5364
Joined: 5-November 01
From: Yorkshire, UK
Member No.: 409



QUOTE (pdq @ Feb 19 2012, 04:16) *
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 wink.gif

Cheers,
David.
Go to the top of the page
+Quote Post
icstm
post Feb 20 2012, 13:06
Post #14





Group: Members
Posts: 121
Joined: 25-January 12
Member No.: 96698



QUOTE (2Bdecided @ Feb 20 2012, 11:32) *
QUOTE (pdq @ Feb 19 2012, 04:16) *
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?
Go to the top of the page
+Quote Post
Arnold B. Kruege...
post Feb 20 2012, 13:59
Post #15





Group: Members
Posts: 4492
Joined: 29-October 08
From: USA, 48236
Member No.: 61311



QUOTE (2Bdecided @ Feb 20 2012, 06:32) *
QUOTE (pdq @ Feb 19 2012, 04:16) *
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 wink.gif


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.
Go to the top of the page
+Quote Post
Woodinville
post Feb 21 2012, 10:36
Post #16





Group: Members
Posts: 1415
Joined: 9-January 05
From: In the kitchen
Member No.: 18957



QUOTE (2Bdecided @ Feb 20 2012, 03:32) *
QUOTE (pdq @ Feb 19 2012, 04:16) *
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
Go to the top of the page
+Quote Post
2Bdecided
post Feb 21 2012, 12:14
Post #17


ReplayGain developer


Group: Developer
Posts: 5364
Joined: 5-November 01
From: Yorkshire, UK
Member No.: 409



QUOTE (Arnold B. Krueger @ Feb 20 2012, 12:59) *
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.

Go to the top of the page
+Quote Post
2Bdecided
post Feb 21 2012, 12:20
Post #18


ReplayGain developer


Group: Developer
Posts: 5364
Joined: 5-November 01
From: Yorkshire, UK
Member No.: 409



QUOTE (Woodinville @ Feb 21 2012, 09:36) *
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 wink.gif, but I had to stop and think for a bit.

Cheers,
David.
Go to the top of the page
+Quote Post
Woodinville
post Feb 21 2012, 21:12
Post #19





Group: Members
Posts: 1415
Joined: 9-January 05
From: In the kitchen
Member No.: 18957



QUOTE (2Bdecided @ Feb 21 2012, 03:20) *
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 wink.gif, 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 smile.gif


--------------------
-----
J. D. (jj) Johnston
Go to the top of the page
+Quote Post
Woodinville
post Feb 21 2012, 21:23
Post #20





Group: Members
Posts: 1415
Joined: 9-January 05
From: In the kitchen
Member No.: 18957



QUOTE (2Bdecided @ Feb 21 2012, 03:14) *
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 sad.gif


--------------------
-----
J. D. (jj) Johnston
Go to the top of the page
+Quote Post
xnor
post Feb 21 2012, 22:59
Post #21





Group: Developer
Posts: 1025
Joined: 29-April 11
From: Austria
Member No.: 90198



I tried this and couldn't hear any difference.

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

This post has been edited by xnor: Feb 21 2012, 23:12


--------------------
"we are having an educated and deep technical discussion"-amirm
Go to the top of the page
+Quote Post
Woodinville
post Feb 22 2012, 18:07
Post #22





Group: Members
Posts: 1415
Joined: 9-January 05
From: In the kitchen
Member No.: 18957



QUOTE (xnor @ Feb 21 2012, 13:59) *
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
Go to the top of the page
+Quote Post
xnor
post Feb 22 2012, 19:20
Post #23





Group: Developer
Posts: 1025
Joined: 29-April 11
From: Austria
Member No.: 90198



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.


--------------------
"we are having an educated and deep technical discussion"-amirm
Go to the top of the page
+Quote Post
Porcus
post Feb 22 2012, 19:41
Post #24





Group: Members
Posts: 1995
Joined: 30-November 06
Member No.: 38207



QUOTE (Arnold B. Krueger @ Feb 20 2012, 13:59) *
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?


--------------------
One day in the Year of the Fox came a time remembered well
Go to the top of the page
+Quote Post
greynol
post Feb 22 2012, 19:49
Post #25





Group: Super Moderator
Posts: 10348
Joined: 1-April 04
From: San Francisco
Member No.: 13167



QUOTE (Porcus @ Feb 22 2012, 10:41) *
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.


--------------------
Breath is found in plots and DR figures.
Go to the top of the page
+Quote Post

2 Pages V   1 2 >
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 29th December 2014 - 12:28