Author Topic: Generating a clean 10kHz sine wave from PWM  (Read 6655 times)

0 Members and 1 Guest are viewing this topic.

Online Marco

  • Super Contributor
  • ***
  • Posts: 6694
  • Country: nl
Re: Generating a clean 10kHz sine wave from PWM
« Reply #25 on: June 30, 2022, 09:22:32 pm »
Do you have 1 more output available? Then you can do 3 level PWM modulation, which has a much reduced third harmonic.
 
The following users thanked this post: robca

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3032
  • Country: us
Re: Generating a clean 10kHz sine wave from PWM
« Reply #26 on: June 30, 2022, 10:30:27 pm »

It is similar to what this circuit does:
https://electronics-diy.com/lc_meter.php




This circuit is simple enough that it is worth building and testing. It has been around for a long time and was even sold as a product. You can find reviews, comments, etc. by searching the web for "AADE LC meter".

One criticism is that it doesn't test inductors at a specific frequency and you don't get to choose the test frequency. Real inductors have frequency dependent characteristics.

Here is a similar approach of using frequency to measure inductance/capacitance:

https://circuitcellar.com/research-design-hub/projects/building-an-lc-meter/

It references a Silicon Chip article which you can view at:

https://siliconchip.com.au/Issue/2020/June

The author goes into a lot of detail on the steps he took to make the meter as accurate as possible.

 
The following users thanked this post: robca

Offline moffy

  • Super Contributor
  • ***
  • Posts: 1682
  • Country: au
Re: Generating a clean 10kHz sine wave from PWM
« Reply #27 on: June 30, 2022, 10:42:07 pm »
I built and played with the LC measuring circuit you have shown and found it is very dependent upon the Q of the measured components. Low Q coils would have difficulty or not resonate at all, too much damping. The lower Q would also pull the resonant frequency off what is expected.
 

Offline Le_Bassiste

  • Frequent Contributor
  • **
  • Posts: 282
  • Country: de
Re: Generating a clean 10kHz sine wave from PWM
« Reply #28 on: July 01, 2022, 12:47:27 pm »
In any case, a clean 10kHz sine wave is a requirement. Can you please help me figure out a good active filter and help pick the passive values for my frequency? A single PWM pulse is 16MHz, and I use 40 pulses to represent values 0 to 40. So the PWM frequency is 400kHz. I have a 40 items LUT, to build the sine

an LTC1564 might do the trick, and it probably won't get much simpler than that in terms of usage.
https://www.analog.com/en/products/ltc1564.html
An assertion ending with a question mark is a brain fart.
 

Offline robcaTopic starter

  • Frequent Contributor
  • **
  • Posts: 257
Re: Generating a clean 10kHz sine wave from PWM
« Reply #29 on: July 01, 2022, 04:06:09 pm »
Do you have 1 more output available? Then you can do 3 level PWM modulation, which has a much reduced third harmonic.
I have plenty of outputs, and plenty of extra PWM channels I can use. But I'm not sure how 3 level PWM would work to create a single analog signal. I did some searches, but mostly seemed related to motor drives and used H bridges. I could not find a simple proof of concept (and sample connection guide) on how to sum the PWM signals to create a single 0-1.8V signal

Do you have a pointer or an example I can use as a starting point?
 

Offline robcaTopic starter

  • Frequent Contributor
  • **
  • Posts: 257
Re: Generating a clean 10kHz sine wave from PWM
« Reply #30 on: July 01, 2022, 04:08:42 pm »
I built and played with the LC measuring circuit you have shown and found it is very dependent upon the Q of the measured components. Low Q coils would have difficulty or not resonate at all, too much damping. The lower Q would also pull the resonant frequency off what is expected.
I spoke some more with the creator of the sensor, and they tried an LC circuit but was too problematic and in the end they abandoned the effort. The sensor is, in reality, much more complex than a single inductor

So I'm back to the original plan: generate a sine wave, measure phase differences. I'm exploring both the PWM option and the square wave to sine one...
 

Offline robcaTopic starter

  • Frequent Contributor
  • **
  • Posts: 257
Re: Generating a clean 10kHz sine wave from PWM
« Reply #31 on: July 01, 2022, 04:15:30 pm »
In any case, a clean 10kHz sine wave is a requirement. Can you please help me figure out a good active filter and help pick the passive values for my frequency? A single PWM pulse is 16MHz, and I use 40 pulses to represent values 0 to 40. So the PWM frequency is 400kHz. I have a 40 items LUT, to build the sine

an LTC1564 might do the trick, and it probably won't get much simpler than that in terms of usage.
https://www.analog.com/en/products/ltc1564.html
Simple, sure... but at more than $20 in single quantity, not cheap  >:D It would be the 3 times the cost of the nRF52840 (BLE-enabled processor), and by far the most expensive component on the PCB... not to mention adding yet another semiconductor that can be impossible to find when needed, with no easy replacements.
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 14073
  • Country: de
Re: Generating a clean 10kHz sine wave from PWM
« Reply #32 on: July 01, 2022, 04:19:52 pm »
One can use 2 equal resistors to combine 2  phase shifted rectangular signals to get a 3 level signal with less (ideally no) 30 kHz contend. With a 60 degree phase shift for the 10 kHz the 30 kHz harmonics see a 180 degree phase shift and thus cancel.  This would simplify filtering, as less amplitude (about half) and a larger frequency ratio (1:5 instead 1:3).
Chances are a first or second order passive followed by a 2nd order active filter (1 OP-amp) could be enough to get a sufficiently good signal (e.g. ~ 1% THD).
 

Offline gf

  • Super Contributor
  • ***
  • Posts: 1132
  • Country: de
Re: Generating a clean 10kHz sine wave from PWM
« Reply #33 on: July 01, 2022, 07:49:35 pm »
If the sine wave is supposed to be generated with a 1-bit DAC, then I'd prefer PDM / delta-sigma modulation instead of PWM. With the same clock frequency (16 MHz), and just with a first order delta-sigma modulator and 1st order lowpass filter with 10kHz cut-off I get the attached spectrum. SFDR is better than 60dBc. SINAD (over 8MHz bandwidth) is about 49dBc. A higher order modulator and/or higher filter order would certainly lead to further improvements. The modulator does not even need to run in real-time. Since the waveform is fixed, it is sufficient to store a pre-calculated stream of 1600 bits in memory and send it repeatedly.

EDIT: Added spectrum with 2nd order chebycheff filter with 3dB ripple (one Sallen Key stage - one opamp). SINAD is now about -67dBc. Still first order modulator.
« Last Edit: July 01, 2022, 09:13:37 pm by gf »
 
The following users thanked this post: Someone

Offline robcaTopic starter

  • Frequent Contributor
  • **
  • Posts: 257
Re: Generating a clean 10kHz sine wave from PWM
« Reply #34 on: July 01, 2022, 10:16:29 pm »
If the sine wave is supposed to be generated with a 1-bit DAC, then I'd prefer PDM / delta-sigma modulation instead of PWM. With the same clock frequency (16 MHz), and just with a first order delta-sigma modulator and 1st order lowpass filter with 10kHz cut-off I get the attached spectrum. SFDR is better than 60dBc. SINAD (over 8MHz bandwidth) is about 49dBc. A higher order modulator and/or higher filter order would certainly lead to further improvements. The modulator does not even need to run in real-time. Since the waveform is fixed, it is sufficient to store a pre-calculated stream of 1600 bits in memory and send it repeatedly.

EDIT: Added spectrum with 2nd order chebycheff filter with 3dB ripple (one Sallen Key stage - one opamp). SINAD is now about -67dBc. Still first order modulator.
Unfortunately the nRF52840 doesn't have PDM out, so that's a non-starter for me. I guess I could try and find some way to bit-bang the stream, but I couldn't do it in hardware (or, better, I don't know how I could do it 100% in hardware). The Nordic chip is not really hard real time, because it's using a single core to also manage the BLE radio, so if the code is being executed in what they call the Softdevice, there's no guarantee that your code will run when needed, especially not as fast as 16MHz

Thinking about this some more, I guess that if I were to use a 2 pulse PWM value (only possible values 0, 1, 2), I could then find a way to use 20 of those packets to precalculate PDM-like bitstreams using PWM. The downside is that I would need a big amount of RAM to hold the array for the values, since the way the code works is to identify each value sent as a 16 bit value. That would be a 800 items 16 bit array, not impossible. Maybe this can work, actually, and would be pretty clever, good suggestion

Do you know of an easy way to generate the 1600 bits for the PDM sine? I can then easily break that down to simulated PWM values
 

Offline gf

  • Super Contributor
  • ***
  • Posts: 1132
  • Country: de
Re: Generating a clean 10kHz sine wave from PWM
« Reply #35 on: July 01, 2022, 10:45:50 pm »
This was mine:

Code: [Select]
% create 10 periods, to have room for settling of the modulator
s = sin([0:15999]/1600*2*pi);
bit = s * 0;
a=0; e=0; for i=1:16000; bit(i)=a; e+=s(i)-a; a=sign(e); end
% print last 1600 bit, where the modulator hopefully has settled to a stable state
printf("%d,", bit(end-1600+1:end)>0)

Code: [Select]
0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,0,1,1,1,1,0,1,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0

EDIT: The MCU has no serial output pins which can be fed via DMA?
« Last Edit: July 01, 2022, 10:53:33 pm by gf »
 
The following users thanked this post: Someone

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4391
  • Country: dk
 
The following users thanked this post: gf

Online Marco

  • Super Contributor
  • ***
  • Posts: 6694
  • Country: nl
Re: Generating a clean 10kHz sine wave from PWM
« Reply #37 on: July 01, 2022, 11:02:31 pm »
Should be able to abuse one of the other peripherals with easydma to send the bits. SPI/UART/whatever.
 

Online dmendesf

  • Frequent Contributor
  • **
  • Posts: 318
  • Country: br
Re: Generating a clean 10kHz sine wave from PWM
« Reply #38 on: July 01, 2022, 11:41:20 pm »
"Magic sines" is a voodoo name for "selective harmonic elimination". Look it up.
 

Offline robcaTopic starter

  • Frequent Contributor
  • **
  • Posts: 257
Re: Generating a clean 10kHz sine wave from PWM
« Reply #39 on: July 03, 2022, 06:49:19 pm »
Update: I have been looking at ways to use the nRF52840 to generate a PDM signal.

There is no programmable I/O with DMA, nor a way to use other peripherals (like SPI) at 16MHz with DMA. The nRF52 family is stellar for BLE and interfacing to standard peripherals, not as strong in the analog front.

I'm trying to abuse the PWM peripheral, by using only two pulses per period, to create a bitstream. Alas, at 16MHz, it doesn't seem to work as well as hoped. I opened a ticket with Nordic https://devzone.nordicsemi.com/f/nordic-q-a/89607/unexpected-pwm-behavior to see if I'm doing something wrong or I'm actually running into a HW limitation. I think the latter, given that it works as expected at 8MHz.

The other alternative would be to use 4 pulse PWM and what I saw called "dithering". Using a 4 pulse PWM seems to work for the nRF52. Basically a PDM stream is broken in clusters of 4 bits, and the closest possible PWM value is used. The timing won't be perfect (i.e. a 0010 PDM will become 1000 PWM), but for a smooth signal like a sine should be ok. Much better than using a 40 pulse PWM for sure

Is there any other easy way to use a 8MHz bitstream to get a clean 10KHz sine, without complex filtering?
 

Online Marco

  • Super Contributor
  • ***
  • Posts: 6694
  • Country: nl
Re: Generating a clean 10kHz sine wave from PWM
« Reply #40 on: July 03, 2022, 07:21:44 pm »
nor a way to use other peripherals (like SPI) at 16MHz with DMA.
Why not exactly? It can work at 32 MHz, it's double buffered so you should be able to keep the bitstream going, what's missing?
 
The following users thanked this post: robca

Offline robcaTopic starter

  • Frequent Contributor
  • **
  • Posts: 257
Re: Generating a clean 10kHz sine wave from PWM
« Reply #41 on: July 03, 2022, 07:30:10 pm »
nor a way to use other peripherals (like SPI) at 16MHz with DMA.
Why not exactly? It can work at 32 MHz, it's double buffered so you should be able to keep the bitstream going, what's missing?
You are right, it looks as if I missed that SPIM3 is 32MHz. All the other SPI instances are limited to 8MHz, but not SPIM3

What's missing is my ability to properly read specs :) Thanks! Need to experiment some more, then
 

Offline gf

  • Super Contributor
  • ***
  • Posts: 1132
  • Country: de
Re: Generating a clean 10kHz sine wave from PWM
« Reply #42 on: July 03, 2022, 11:28:40 pm »
I'm trying to abuse the PWM peripheral, by using only two pulses per period, to create a bitstream. Alas, at 16MHz, it doesn't seem to work as well as hoped. I opened a ticket with Nordic
The other alternative would be to use 4 pulse PWM and what I saw called "dithering". Using a 4 pulse PWM seems to work for the nRF52. Basically a PDM stream is broken in clusters of 4 bits, and the closest possible PWM value is used. The timing won't be perfect (i.e. a 0010 PDM will become 1000 PWM), but for a smooth signal like a sine should be ok. Much better than using a 40 pulse PWM for sure

Delta-sigma modulation is not limited to binary output, but the output can be N-level quantized (say N=5), and these 5 levels (0...4) could be encoded with PWM then. Result is of course not as good as with delta-sigma modulation alone. SINAD with 1st order filter dropped to 42dBc, the PWM introduces a 2nd harmonic (-51dBc), and there arise spurs in the neighborhood of 4MHz.

5-level sine wave @4MSa/s (400 samples per period):

Code: [Select]
2,2,2,2,2,2,2,3,2,2,2,3,2,2,3,2,3,2,3,2,3,3,2,3,3,2,3,3,3,3,2,3,3,3,3,3,3,3,3,4,3,3,3,3,4,3,3,3,4,3,4,3,3,4,3,4,3,4,3,4,4,3,4,4,3,4,4,3,4,4,4,3,4,4,4,4,4,3,4,4,4,4,4,4,4,4,4,4,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,3,4,4,4,4,4,3,4,4,4,4,3,4,4,3,4,4,3,4,4,3,4,3,4,3,4,3,4,3,3,4,3,3,4,3,3,4,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,3,3,2,3,3,2,3,2,3,2,3,2,3,2,2,3,2,2,2,2,2,3,2,2,2,2,2,1,2,2,2,2,2,1,2,2,1,2,1,2,1,2,1,2,1,1,2,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,0,1,0,1,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,1,0,1,1,0,1,0,1,1,1,0,1,1,1,1,0,1,1,1,1,1,1,1,1,2,1,1,1,1,2,1,1,2,1,1,2,1,2,1,2,1,2,2,1,2,2,2,1,2,2,2,2
0 => 0 0 0 0
1 => 1 0 0 0
2 => 1 1 0 0
3 => 1 1 1 0
4 => 1 1 1 1
« Last Edit: July 03, 2022, 11:32:39 pm by gf »
 

Offline gf

  • Super Contributor
  • ***
  • Posts: 1132
  • Country: de
Re: Generating a clean 10kHz sine wave from PWM
« Reply #43 on: July 04, 2022, 01:09:22 pm »
You are right, it looks as if I missed that SPIM3 is 32MHz. All the other SPI instances are limited to 8MHz, but not SPIM3

Here is a 32MHz 1st order delta-sigma bit stream (3200 bits), if you are able to send it:

Code: [Select]
1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,1,0,1,0,1,0,1,1,0,1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,0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from PWM
« Reply #44 on: July 07, 2022, 05:09:15 am »
You are right, it looks as if I missed that SPIM3 is 32MHz. All the other SPI instances are limited to 8MHz, but not SPIM3

Here is a 32MHz 1st order delta-sigma bit stream (3200 bits), if you are able to send it:

Code: [Select]
1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,1,0,1,0,1,0,1,1,0,1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,0,1,1,1,0,1,1,1,1,0,1,1,1,0,1,1,1,1,0,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1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,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0

SFDR ~74dBc, SINAD ~52dBc.
Thanks a lot for all your input, I learned a lot from you. At this time, i decided that using an active filter to get a sine out of a square wave is the better option (one of the suggestions here), and I have a working circuit https://www.eevblog.com/forum/beginners/generating-a-good-enough-10khz-sine-wave-from-a-square-one/msg4282492/#msg4282492

PWM on the nRF52 seems to be more work than it's worth, for my specific problem (might be worth for more complex waveforms)

Out of curiosity (for the future), what are you using to generate the various PDM streams and pseudo streams? I have some code that works for normal PDM, below, but was curious about the 4 bit one (your post before the quoted one)

Code: [Select]
#define PDM_PERIOD 40
void pdm_gen(int value)
{
    int v =0;
    for (int i=0; i<PDM_PERIOD; i++)
    {
        v += value;
        if (v >= PDM_PERIOD)
        {
            printf("1");
            v -= PDM_PERIOD;
        }
        else printf("0");
    }
    printf("\r\n");
}

int main()
{
    for (int i=0; i<40; i++)
    {
        sine_table[i] = sin(i * 2.0 * M_PI / 40) * 20.0 + 20.5;  // storing values in case I need the sine table later on
        pdm_gen(sine_table[i]);
    } 
    return 0;
}
 

Offline gf

  • Super Contributor
  • ***
  • Posts: 1132
  • Country: de
Re: Generating a clean 10kHz sine wave from PWM
« Reply #45 on: July 07, 2022, 10:25:30 am »
Just replace the binary quantizer (whose output is only 0 or 1) with a multi-level quantizer.
The code below (sorry, untested!) assumes a normalized 0...1 value range for the original signal and for the quantized levels, but this can be adapted, of course.

Code: [Select]
float quantize(float v, int nlevels)
{
    // number of steps between levels
    int nsteps = nlevels - 1;
    // round v to nearest level
    return floor(v * nsteps + 0.5f) / nsteps;
}

// signal[i] is assumed to be in the range 0...1
// nlevels=2 means binary quantization, i.e. {0, 1}
// nlevels=5 means {0, 0.25, 0.5 ,0.75, 1}

void pdm_gen(const float signal[], int nsampes, int nlevels)
{
    float v = 0;
    for (int i=0; i<nsampes; i++)
    {
        v += signal[i];
        float qv = quantize(v, nlevels);
        v -= qv;
        printf("%f ", qv);
    }
    printf("\n");
}
« Last Edit: July 07, 2022, 12:43:09 pm by gf »
 
The following users thanked this post: robca


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf