cancel
Showing results for
Did you mean:

# NUCLEO-U575ZI DAC optimal sampling rate for 40hz sine generation?

Associate III

Hello everybody! Sorry, I am a pianist and know very little about engineering, so I most probably will use a naïve terminology, please bear with me.

The thing is I use built-in 12-bit DAC in order to generate a simple sine wave. The frequency is a bout 40hz. Now, from what little I know, it seems that both the bit depth and sampling rate determine how large "gaps" between two adjacent values of the resulting sine will be. The larger the bit depth, the smaller the gap (smoother wave), the greater sampling rate - also the smoother wave. So both, the bit depth and sampling rate determine the smoothness of the resulting wave. My question is, while I cannot adjust the bit depth (let's not mention dithering at this point), I definitely can vary sampling rate. What would be the optimal oversampling ratio for generating a smooth 40hz sine? Could someone please explain the concept in a nut-shell, if possible?

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Chief

hi,

the general question for "generating a smooth 40hz sine" is : what is "smooth" ? see wave on a scope, or hear it on a good ...speaker ? to have a nice pic on a scope, maybe 100 dots -> lines giving a good image , you need 40hz * 100 = 4000 sampels/sec .

but if listen to it and want best quality, you need a sampling rate, that not generates side effect you can hear; so without a extra low pass filter, sampling rate > 16kHz is needed.

so lets say, for audio with good quality you should use a sampling rate of 20 kHz , if only low frequency should be produced.

to play this just by reading from a table (int16 array) you can pre-calculate the sine table (20k / 40) with 500 values and give at 20khz rate to the dac.

If you feel a post has answered your question, please click "Accept as Solution".
12 REPLIES 12
Chief

hi,

the general question for "generating a smooth 40hz sine" is : what is "smooth" ? see wave on a scope, or hear it on a good ...speaker ? to have a nice pic on a scope, maybe 100 dots -> lines giving a good image , you need 40hz * 100 = 4000 sampels/sec .

but if listen to it and want best quality, you need a sampling rate, that not generates side effect you can hear; so without a extra low pass filter, sampling rate > 16kHz is needed.

so lets say, for audio with good quality you should use a sampling rate of 20 kHz , if only low frequency should be produced.

to play this just by reading from a table (int16 array) you can pre-calculate the sine table (20k / 40) with 500 values and give at 20khz rate to the dac.

If you feel a post has answered your question, please click "Accept as Solution".
Associate III

Great! Thank you so much! So it is 500 samples per a period.​ Could you pls let me know, if there is a formula, which helped you to calculate such a value? So that i could use it also next time.

Chief

formula ? 20kHz sampling / 40 waves/sec = 500 values/sec 🙂

and if you want high frequency, best is to go just for "standard" audio rate, like 48kHz .

and you should have some low pass filter after the dac, to filter out some ultrasonic , what could disturb following amplifiers and make intermodulation.

so for your only low frequ. player, a low pass filter at 1 or 2 khz would be fine.

If you feel a post has answered your question, please click "Accept as Solution".
Associate III

Hahaha 🙂 perhaps i wasn't clear, sorry. I mean - if there is a way to make certain generalisation about a desired frequency vs optimal number of samples per second? So roughly 500 samples per period, right?

Principal

It doesn't really work like that... you don't want to switch the sampling rate all the time with audio, unless you are only using single tones (like the 40 Hz).

Usually you want to have a fixed sampling rate, and on the analog side a fitting anti-aliasing filter (low pass).

If you want to use the complete audible range up to 20 kHz you need at least an fs of > 40 kHz, typical audio rates are 44.1kHz, 48kHz, ...

These days the audio converters use oversampling, which means they are actually using much higher sampling rates internally, which simplifies the analog filters.

So maybe you tell us what your goal is.

I cannot imagine that it's really only an output of 40 Hz. 🙂

Associate III

Sure. Actually i need just 40hz. Well... and 3hz also perhaps. I have been building a lucid dreaming ​inducing device and this frequency is needed for very low current bio feedback. Apart from 40hz, the 3hz may bee needed for the same purpose. Just two fixed frequencies, that is why i asked about samples per period. Yet, i wanted the sines to be quite pure.

Chief

btw >building a lucid dreaming ​inducing device < -- i would like to hear/know more about it !

+

40Hz + 3Hz -> now its getting more complex or difficult :

now you have about 3 options to do this :

• make 2 of these "500 samples->play one sine generators" and add the output
• go to standard audio frequ. and write all the waves in a big array (at 48k need about 16000 samples array for 3 Hz )
• use a 1024 samples sine lookup table and generate tones with a DDS generator (/per tone one)
• if only low frequ. at relative low saple rate : use DDS and calculate sine "live"

If you feel a post has answered your question, please click "Accept as Solution".
Principal

> a lucid dreaming ​inducing device

Be careful when playing with electronics going into the medical area, not only dangerous, and because of that many regulations and legal stuff.

Associate III

Sure thing, if i needed 40hz plus 3hz i would resort to SigmaDSP (was my favourite back in the day)​, but luckily i only need either of the frequencies at a time, so I will resort to the option one.

It is still a concept, but according to the data i read, passing about 600uA through the brain at 40hz induces lucid dreaming, if done during REM sleep phase. Since before i was developing a micro EEG device, i guess combing it with the tiny generator won't be a huge problem.​