Representing frequency of n Hz needs sampling rate >2n Hz, not =2n, From: Badly drawn waveforms vs. the audio that’s actually output/93496 |
![]() ![]() |
Representing frequency of n Hz needs sampling rate >2n Hz, not =2n, From: Badly drawn waveforms vs. the audio that’s actually output/93496 |
Feb 16 2012, 17:13
Post
#1
|
|
![]() Group: Members (Donating) Posts: 1442 Joined: 11-February 03 From: Vermont Member No.: 4955 |
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. |
|
|
|
Feb 17 2012, 11:35
Post
#2
|
|
|
Group: Members Posts: 121 Joined: 25-January 12 Member No.: 96698 |
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. This post has been edited by icstm: Feb 17 2012, 11:35 |
|
|
|
Feb 17 2012, 20:47
Post
#3
|
|
|
Group: Super Moderator Posts: 4356 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.
|
|
|
|
Feb 17 2012, 21:08
Post
#4
|
|
|
Group: Members Posts: 3083 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.
|
|
|
|
Feb 17 2012, 21:09
Post
#5
|
|
![]() Group: Super Moderator Posts: 9268 Joined: 1-April 04 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.
-------------------- Everything sounds the same until it is proven otherwise.
|
|
|
|
Feb 18 2012, 10:12
Post
#6
|
|
|
Group: Members Posts: 1559 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 ">=". |
|
|
|
Feb 18 2012, 12:11
Post
#7
|
|
![]() Group: Members Posts: 1355 Joined: 9-January 05 From: JJ's office. 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. 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 |
|
|
|
Feb 18 2012, 20:40
Post
#8
|
|
|
Group: Super Moderator Posts: 4356 Joined: 23-June 06 Member No.: 32180 |
(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 |
|
|
|
Feb 19 2012, 05:16
Post
#9
|
|
|
Group: Members Posts: 3083 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. |
|
|
|
Feb 19 2012, 20:29
Post
#10
|
|
![]() Group: Super Moderator Posts: 9268 Joined: 1-April 04 Member No.: 13167 |
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.-------------------- Everything sounds the same until it is proven otherwise.
|
|
|
|
Feb 19 2012, 21:00
Post
#11
|
|
|
Group: Members Posts: 3083 Joined: 1-September 05 From: SE Pennsylvania Member No.: 24233 |
|
|
|
|
Feb 20 2012, 03:02
Post
#12
|
|
|
Group: Members Posts: 128 Joined: 12-December 07 From: Cleveland, OH Member No.: 49500 |
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
|
|
|
|
Feb 20 2012, 12:32
Post
#13
|
|
![]() ReplayGain developer Group: Developer Posts: 4589 Joined: 5-November 01 From: Yorkshire, UK Member No.: 409 |
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. 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.On the other hand, if there are multiple frequencies or the amplitude is not constant then you will need a longer observation period. 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. |
|
|
|
Feb 20 2012, 13:06
Post
#14
|
|
|
Group: Members Posts: 121 Joined: 25-January 12 Member No.: 96698 |
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. 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.On the other hand, if there are multiple frequencies or the amplitude is not constant then you will need a longer observation period. |
|
|
|
Feb 20 2012, 13:59
Post
#15
|
|
![]() Group: Members Posts: 3212 Joined: 29-October 08 From: USA, 48236 Member No.: 61311 |
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. 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.On the other hand, if there are multiple frequencies or the amplitude is not constant then you will need a longer observation period. 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. |
|
|
|
Feb 21 2012, 10:36
Post
#16
|
|
![]() Group: Members Posts: 1355 Joined: 9-January 05 From: JJ's office. Member No.: 18957 |
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. 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.On the other hand, if there are multiple frequencies or the amplitude is not constant then you will need a longer observation period. 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 |
|
|
|
Feb 21 2012, 12:14
Post
#17
|
|
![]() ReplayGain developer Group: Developer Posts: 4589 Joined: 5-November 01 From: Yorkshire, UK Member No.: 409 |
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. |
|
|
|
Feb 21 2012, 12:20
Post
#18
|
|
![]() ReplayGain developer Group: Developer Posts: 4589 Joined: 5-November 01 From: Yorkshire, UK Member No.: 409 |
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). 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 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. Cheers, David. |
|
|
|
Feb 21 2012, 21:12
Post
#19
|
|
![]() Group: Members Posts: 1355 Joined: 9-January 05 From: JJ's office. Member No.: 18957 |
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 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 |
|
|
|
Feb 21 2012, 21:23
Post
#20
|
|
![]() Group: Members Posts: 1355 Joined: 9-January 05 From: JJ's office. Member No.: 18957 |
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 |
|
|
|
Feb 21 2012, 22:59
Post
#21
|
|
![]() Group: Developer Posts: 304 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 |
|
|
|
Feb 22 2012, 18:07
Post
#22
|
|
![]() Group: Members Posts: 1355 Joined: 9-January 05 From: JJ's office. Member No.: 18957 |
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 |
|
|
|
Feb 22 2012, 19:20
Post
#23
|
|
![]() Group: Developer Posts: 304 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.
|
|
|
|
Feb 22 2012, 19:41
Post
#24
|
|
![]() Group: Members Posts: 1475 Joined: 30-November 06 Member No.: 38207 |
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? -------------------- geocities.com/hydrogenaudio: http://goo.gl/tqYZj
|
|
|
|
Feb 22 2012, 19:49
Post
#25
|
|
![]() Group: Super Moderator Posts: 9268 Joined: 1-April 04 Member No.: 13167 |
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. -------------------- Everything sounds the same until it is proven otherwise.
|
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 25th May 2013 - 19:42 |