[sdiy] Square to Sine
rsdio at audiobanshee.com
rsdio at audiobanshee.com
Wed Apr 5 07:01:32 CEST 2017
On Apr 4, 2017, at 6:56 AM, rburnett at richieburnett.co.uk wrote:
> Tom Wiltshire wrote:
>> From the document:
>> "Present implementations limit magic sinewaves to power line
>> frequencies, possibly up to 400 Hertz."
>> and
>> "Unusual programming techniques are required as each and every
>> microprocessor clock cycle is critical."
>> Sounds like exactly the sort of thing the SDIY list would get into!
>> and
>> "As many as 44,000 or more microprocessor instructions may be needed
>> per power line cycle."
>> So it looks like full audio might be pretty demanding. Not impossible,
>> perhaps, but at least demanding. For generating sines for a Hammond
>> organ (just to take totally random example…) we'd only need up to
>> 6KHz. Assuming the 44K-instructions-per-cycle guideline from above,
>> that's a 264MHz processor!
>
> Thanks for your comments and analysis. I have to confess that I didn't read all of the particular document that I linked to, I just tried to quickly find something that described the technology I was thinking of. From what is written in that document and your analysis it doesn't sound so tempting for audio rate sinewave generation.
Power electronics have completely different considerations compared to small-signal audio. As a result, what works extremely well for power system can very easily be a ridiculously poor idea for audio.
In power systems, it's basically necessary to run the final output transistors at all or nothing, so that there's either no voltage drop or no current. Anywhere between full-on and full-off results in significant wattage, leading to heat failure. Looking at the diagrams in the magic sine document, you'll see that they're only performing 7 transitions per quadrant, which is somewhat like having only 28 samples per waveform cycle. The quality there would be too low for a synthesizer. But the advantage is that they can turn on the positive voltage, or turn on the negative voltage, or turn both off. They're probably using an H bridge to drive a motor, and these binary switching states are crucial to managing the wattage. This is sort of like a D-Class power amplifier, but for a fixed frequency.
In audio systems, the signals are small, and the minor wattage levels created in an op-amp that's handling all of the in-between voltages of a true analog sine do not pose any problem at all. In addition, we can afford way more than 28 samples per period. The typical PPG Wave has 256 samples per oscillator period. The harmonic distortion would already be quite low, because there is no requirement to operate in binary full-on/full-off mode.
>> Still, like you, I can't help thinking there must be a (simpler) way…
>
> Sending a digital sinewave from a lookup table straight to a DAC :-)
Yes. Given a microprocessor, using a DAC makes way more sense than generating a PWM signal based on about 56 calls (by my count) to the sin() or cos() function, which are each quite expensive. The easiest sine wave in the digital realm would require only two multiply instructions, an add, and a subtract. Considering that a lookup table requires linear interpolation - which introduces harmonic distortion - generating the sine directly might make more sense. Then again, in the context of producing fixed sine wave frequencies, it would be possible to create the lookup tables at the exact sample rate, so that interpolation is not needed.
Brian
More information about the Synth-diy
mailing list