Hi Scott, I never heard of "magic sinewaves" before, so I can be wrong. Anyway, if I understand correctly, there are two goals in generating the pulse sequence: 1) Minimize switching 2) Attenuate higher harmonics I can't understand why you choose PWM to achieve this! Okay, PWM has small number of transitions - two per PWM period. Now harmonics. They appear as a result of PWM conversion and can be thought of as quantization error. To reduce the quantization effect the PWM resolution (and therefore frequency) must be increased. The problem is: If you want to reduce errors(or harmonics), you have to increase PWM frequency. On the other hand, increased PWM frequency increases the number of transitions per unit of time. So these two goals conflict with each other, don't they? I can see another approach. A scheme to minimize quantization errors, also known as "Scenix PWM". -------------- 0..1 ----- | 1 +--- | -----|+ |---o--| | |--o------------- --|+ | | | 0 ----+ | | | ----- | | 1 | | | | -------------- | | | Quantizer | | | | | ------- ----------- | | | | -------- | | + - | | | | | ------- -------- | | -1 | | -----| Z |------- ------- Switching is determined by sampling frequency. Choose what you need or can afford. In any case, the system is trying to eliminate quantization error at every sample (unlike PWM), which leads to a higher attenuation of harmonics at the same clock frequency. The benefit is that you don't have to worry about pulse position, it's done automatically. The noise is minimal at fundamental harmonic frequency and increases with frequency. Probably there is a better feedback variant (noise shaping filter) but this is the simplest and the only one I know . Nikolai On Monday, March 06, 2000 Scott Dattalo wrote: > On Mon, 6 Mar 2000, "Grif" w. keith griffith wrote: >> At 10:44 AM 3/5/00 -0600, you wrote.. >> >It finally dawned on me yesterday how magic sine waves can be sythesized. >> >> Major math snip::: >> >> Scott: doesn't your code produce an analog output? I was of the opinion >> the whole reason for the Magic part of the synthesis was using saturated >> switching at a much higher freq than the final output and stuffing it thru >> a low pass filter, getting a somewhat usable, higher power sine wave >> output? Or did I just learn something this early in the week??? ( that >> would be good,,, then I wouldn't have to work as hard the rest of the week!) > True, the ultimate objective is to produce an analog output. However, the > goal with the so called 'magic sinewaves' is to find the MINIMUM number of > switch transitions. The resulting bit stream is filtered such that a sine > wave is produced. The reason for minimizing the transitions is because > some switches, particularly those associated with high power applications > like in AC inverters, require a significant amount of energy to switch or > cannot be efficiently switched at high frequencies. As an example, you may > have a sine wave synthesis circuit where you want to drive the gate of a > MOSFET directly from a pic I/O pin. Pic's have fairly beefy outputs, > however they're very weak when compared to real MOSFET drivers. But given > enough time, the PIC I/O can switch a MOSFET (assuming of course that Voh > is above Vgs threshold - i.e. logic level Vgs MOSFETs may be required). If > you attempted to drive the MOSFET at too high of frequency with this pic > I/O pin, then chances are that it will never switch! > In addition, if you can use harmonic cancellation, then the constraints on > the analog filter may be relaxed. PWM generated waveforms relax the filter > constraints by maximizing the switching frequency. If the PWM carrier is > 100 times the sinewave you're trying to generate, then you're analog > filter is much easier to design. There aren't any harmonics (to an > approximation) between the sine wave frequency you're generating and the > carrier frequency of the PWM. > Magic sine waves explicitly remove these harmonics by strategically > placing the pulses (or edges). The pulses, when viewed individually, > contain harmonics at the fundamental (of the sine wave being generated) > and at all integer multiples above. But when the pulses are taken > together, the 2nd, 3rd and so on harmonics are cancelled. The number of > harmonics cancelled depends on the quantization of time for the edges. For > example, in the previous post, I had a graph of a 12-bit pulse stream > 010110100000. The second and third harmonics were exactly cancelled, but > there is a 4th and 5th harmonic present. Doubling the number of pulses to > 24 allows a pulse stream to be created that will cancel the 4th harmonic. > In general, if you have a pulse stream containing n! pulses, then it's > possible to exactly cancel the first n harmonics. However, n! grows rather > quickly. It's simply not practical to attempt to cancel the first 10 > harmonics (after the fundamental) by creating a pulse stream containing > 10! or 3,628,800 pulses. > Consequently, if you wish to cancel the first 10 harmonics but with a > pulse stream containing only a 1000 pulses, you're not going to achieve > your goal. However, you may discover a particular stream that exactly > cancels the 2nd, 3rd, and 4th, and attenuates the 5th through 10th > harmonics by 20dB. From that you may design an appropriate analog filter. > AFAIK, there is no way to apriori determine the appropriate length of the > pulse stream to achieve some required harmonic profile. I think > Lancaster's contribution to this technology is to discover certain lengths > that perform well - or at least better than pulses streams that are > slightly shorter or longer. What I'm playing around with is a way you can > study the characteristics of one stream versus another. > Scott