You are here

Question relating to Nyquist frequency

Customising, building or repairing your own gear? Need help with acoustic treatment or soundproofing? Ask away…

Question relating to Nyquist frequency

Postby dwebb » Sat Feb 02, 2019 12:46 pm

I'm currently having a go at making a microcontroller-based VCO and consequently pondering issues around sample rates and wave reconstruction.

As far as I understand the Nyquist sampling theorem, to reproduce a sine wave at a given frequency you need to sample the wave at least double the wave's frequency.

So if I have a sample rate of 44kHz and a sine wav of 22kHz I would sample it twice and that should be sufficient to reproduce. However it seems to me that this would only allow me to deduce the frequency - not the amplitude of the wave. So if I have this wave:

Image

and sample it at positions A and B then that describes everything I need to reproduce the wave. However if I sample it at positions C and D then I know the frequency but have no idea of the wave's amplitude.

So two questions:

1. Does the Nyquist theorem only work for frequency?
2. If so, what sample rate would I actually need to reasonably accurately reproduce both the frequency and the amplitude of a sine wave at a given frequency?
dwebb
Regular
Posts: 55
Joined: Wed Aug 26, 2009 12:00 am
 

Re: Question relating to Nyquist frequency

Postby Wonks » Sat Feb 02, 2019 1:13 pm

The sampling rate has to be greater than twice the frequency you want to sample. In your example, you've used exactly twice the frequency, which is inappropriate. You yourself said 'at least double', and then used an example that ignored that! :D

Use a greater sampling frequency, and the points on the graph will have different amplitudes, and a waveform can be reconstructed.

The theory also only works for a bandwidth limited range of sounds/waves. Which is why you also need to apply a filter to prevent aliasing, as a 44kHz wave or an 88kHz wave would otherwise also appear to be a 22kHz wave if no filtering was applied but the sampling rate kept at just above 44kHz.

The Nyquist frequency tells you how fast you have to sample, but you obviously need a means of determining the amplitude of the wave as well to give it its proper structure, which is what an A/D converter does. It's the clock rate of the A/D converter that determines the upper frequency it can detect. On receiving a new clock pulse, the A/D converter converts the voltage level at that point in time into a bit value that gives you the amplitude.
User avatar
Wonks
Jedi Poster
Posts: 10120
Joined: Thu May 29, 2003 12:00 am
Location: Reading, UK
Correcting mistakes on the internet since 1853

Re: Question relating to Nyquist frequency

Postby wireman » Sat Feb 02, 2019 1:23 pm

Have a look at the Nyquist and Signal Content section of this webpage.

I suppose it depends how you interpret the theorem here, it is one thing to say that you can completely determine a pure sine wave by a series of points spaced apart at this frequency but another thing to say yout could do this with any sequence of points (ignoring the phase). To avoid this you need to sample at a higher rate.
wireman
Regular
Posts: 306
Joined: Fri Dec 17, 2004 1:00 am

Re: Question relating to Nyquist frequency

Postby Folderol » Sat Feb 02, 2019 1:24 pm

I would just add that the design of those filters is something of a black art. They have to be steep enough to do the job, but at the same time not be susceptible to ringing or instability.

For example, I have a KA6 here that performs very well, however hit it with a really clean square wave from a signal generator and the ringing is quite obvious..
User avatar
Folderol
Jedi Poster
Posts: 9160
Joined: Sat Nov 15, 2008 1:00 am
Location: The Mudway Towns, UK
Yes. I am that Linux nut.
Onwards and... err... sideways!

Re: Question relating to Nyquist frequency

Postby Hugh Robjohns » Sat Feb 02, 2019 1:34 pm

dwebb wrote:However if I sample it at positions C and D then I know the frequency but have no idea of the wave's amplitude.

As others have pointed out, you correctly state the essence of the theorem, and then completely ignore it! :wave: you need to sample at more than twice the highest frequency you want to sample, taking into account the response of your reconstruction filtering -- the latter being a critical part of the whole sampling process (and one which is often completely overlooked in simple explanations of sampling theory).

H
User avatar
Hugh Robjohns
Moderator
Posts: 24997
Joined: Fri Jul 25, 2003 12:00 am
Location: Worcestershire, UK
Technical Editor, Sound On Sound

Re: Question relating to Nyquist frequency

Postby Hugh Robjohns » Sat Feb 02, 2019 1:37 pm

Folderol wrote:...however hit it with a really clean square wave from a signal generator and the ringing is quite obvious..

Any band-limited square wave will exhibit obvious ringing. It's a fundamental of physics, innit?

H
User avatar
Hugh Robjohns
Moderator
Posts: 24997
Joined: Fri Jul 25, 2003 12:00 am
Location: Worcestershire, UK
Technical Editor, Sound On Sound

Re: Question relating to Nyquist frequency

Postby Wonks » Sat Feb 02, 2019 1:43 pm

There is no such thing as a "clean square wave". For a wave to be perfectly square, the leading and falling edges would have to occupy two values at the same point in time - which can't happen. So there is only a true square wave in theory, not in practice. And as you can only have a finite band-width on any real-world device, you'll never be able to recreate the infinite sequence of sine waves necessary to create the perfect square wave.

This popped into my head kept me awake for half the night just over a week ago!
User avatar
Wonks
Jedi Poster
Posts: 10120
Joined: Thu May 29, 2003 12:00 am
Location: Reading, UK
Correcting mistakes on the internet since 1853

Re: Question relating to Nyquist frequency

Postby blinddrew » Sat Feb 02, 2019 2:38 pm

Wonks wrote:There is no such thing as a "clean square wave". For a wave to be perfectly square, the leading and falling edges would have to occupy two values at the same point in time - which can't happen.
That had never occured to me before! :headbang:
User avatar
blinddrew
Jedi Poster
Posts: 8470
Joined: Sun Jul 05, 2015 12:00 am
Location: York
Ignore the post count, I have no idea what I'm doing...

Re: Question relating to Nyquist frequency

Postby Wonks » Sat Feb 02, 2019 2:44 pm

This probably proves that the universe is bandwidth limited, but I have no idea of what that means or implies.

Or I've got it wrong.
User avatar
Wonks
Jedi Poster
Posts: 10120
Joined: Thu May 29, 2003 12:00 am
Location: Reading, UK
Correcting mistakes on the internet since 1853

Re: Question relating to Nyquist frequency

Postby nathanscribe » Sat Feb 02, 2019 2:48 pm

Wonks wrote:This probably proves that the universe is bandwidth limited, but I have no idea of what that means or implies.

Does this mean deep space is a low pass filter? Can we voltage control it?
User avatar
nathanscribe
Frequent Poster
Posts: 1078
Joined: Fri Jan 19, 2007 1:00 am
Location: Wakefield, for my sins.
I have no idea what I'm doing.

Re: Question relating to Nyquist frequency

Postby Wonks » Sat Feb 02, 2019 3:27 pm

Well, those new age folks always say it has a resonant frequency...
User avatar
Wonks
Jedi Poster
Posts: 10120
Joined: Thu May 29, 2003 12:00 am
Location: Reading, UK
Correcting mistakes on the internet since 1853

Re: Question relating to Nyquist frequency

Postby Folderol » Sat Feb 02, 2019 5:00 pm

OKOKOK I was being simplistic to make a point... innit!
Said sig gen output looks pretty damn square on a scope with a 10M bandwidth i.e. the trace has no 'sides'.
User avatar
Folderol
Jedi Poster
Posts: 9160
Joined: Sat Nov 15, 2008 1:00 am
Location: The Mudway Towns, UK
Yes. I am that Linux nut.
Onwards and... err... sideways!

Re: Question relating to Nyquist frequency

Postby Hugh Robjohns » Sat Feb 02, 2019 6:07 pm

Folderol wrote:OKOKOK I was being simplistic to make a point... innit!

:D
User avatar
Hugh Robjohns
Moderator
Posts: 24997
Joined: Fri Jul 25, 2003 12:00 am
Location: Worcestershire, UK
Technical Editor, Sound On Sound

Re: Question relating to Nyquist frequency

Postby Mike Stranks » Sat Feb 02, 2019 6:07 pm

Folderol wrote:OKOKOK I was being simplistic to make a point... innit!

That was your mistake! :lol:

You can never do that here without someone saying, "Ah! Yes, but..."

(Unless you say that you're trying to keep it simple for the sake of the original questioner. Even then it doesn't always work...)
Mike Stranks
Jedi Poster
Posts: 6925
Joined: Fri Jan 03, 2003 1:00 am

Re: Question relating to Nyquist frequency

Postby Hugh Robjohns » Sat Feb 02, 2019 8:34 pm

Mike Stranks wrote:You can never do that here without someone saying, "Ah! Yes, but...

True! But in my defence there was an important point to be made. When Mr F said:

Folderol wrote:I would just add that the design of those filters is something of a black art. They have to be steep enough to do the job, but at the same time not be susceptible to ringing or instability.

While no one would want an 'unstable' filter, some might think from that comment that the goal would be for the filter to exhibit no ringing at all when exercised by a square wave (or, indeed, an impulse).

However, that would be impossible and contrary to the laws of physics.

The low-pass reconstruction filter inherently removes the higher partials (harmonics) contained within a square wave signal, which results in the square wave becoming decidedly 'wobbly' with apparent 'ringing' before and after the transient edges.
User avatar
Hugh Robjohns
Moderator
Posts: 24997
Joined: Fri Jul 25, 2003 12:00 am
Location: Worcestershire, UK
Technical Editor, Sound On Sound

Re: Question relating to Nyquist frequency

Postby dwebb » Sat Feb 02, 2019 10:20 pm

I think I understand - the idea is that if the sampling rate is more than twice the frequency you can reconstruct the wave - at least from a mathematical perspective.

On the practical level, a DAC can only output output fixed voltages at the chosen sample frequency. In this situation I would (I think) need need to have an output sample rate at significantly more than double the frequency of the wave to I was trying to output. I would guesstimate around 6+ samples per cycle would give something that would look close to the sine wave I was trying to reproduce.

If so, is there a rule of thumb (or something more scientific) that states the required output sample rate to recreate a close enough approximation of a desired sine wave frequency?
dwebb
Regular
Posts: 55
Joined: Wed Aug 26, 2009 12:00 am
 

Re: Question relating to Nyquist frequency

Postby Hugh Robjohns » Sat Feb 02, 2019 10:23 pm

Again, you are overlooking the critical role of the reconstruction filtering....

And somewhere around 2.2x the highest wanted frequency is usually enough.

H
User avatar
Hugh Robjohns
Moderator
Posts: 24997
Joined: Fri Jul 25, 2003 12:00 am
Location: Worcestershire, UK
Technical Editor, Sound On Sound

Re: Question relating to Nyquist frequency

Postby Sam Spoons » Sat Feb 02, 2019 10:35 pm

This might help https://www.soundonsound.com/techniques/digital-problems-practical-solutions but, in a nutshell, 44.1kHz sampling frequency is sufficient to render a perfect reproduction of a 20Hz - 20kHz audio signal.

edit :- and this https://www.soundonsound.com/sound-advice/q-should-i-use-high-sample-rates
User avatar
Sam Spoons
Jedi Poster
Posts: 10504
Joined: Thu Jan 23, 2003 1:00 am
Location: Manchester UK
Finally taking this recording lark seriously (and recording my Gypsy Jazz CD)........

Re: Question relating to Nyquist frequency

Postby Eddy Deegan » Sat Feb 02, 2019 10:37 pm

This might be relevant (and was also written by Hugh) - https://www.soundonsound.com/techniques ... -solutions

I understand some of the words in that article ;)

Edit: Sam beat me to it!
User avatar
Eddy Deegan
Frequent Poster (Level2)
Posts: 2836
Joined: Wed Sep 01, 2004 12:00 am
Location: Brighton & Hove, UK
Please consider supporting the SOS Forum Album project, helping charities via music created by forum members.
 

Re: Question relating to Nyquist frequency

Postby Sam Spoons » Sat Feb 02, 2019 10:40 pm

Great minds Mr D :thumbup:
User avatar
Sam Spoons
Jedi Poster
Posts: 10504
Joined: Thu Jan 23, 2003 1:00 am
Location: Manchester UK
Finally taking this recording lark seriously (and recording my Gypsy Jazz CD)........

Next

Who is online

Users browsing this forum: No registered users