some thoughts on pulse and pulse width

Sound synthesis techniques, DSP and related mathematics

Moderators: electrogear, exonerate

some thoughts on pulse and pulse width

Postby tester on Thu Jan 19, 2012 9:48 pm

While looning for osm's for signal reshaping, I found some discussions regarding pulse/square waves and their quality. According to my understanding - wouldn't be easier to use normal pulse generator to turn a digital switch between 0 and 1? Such digital swich would follow signal changes (pulse width), and it should produce ideal pulse waves, which then can be re-amplified and DC readjusted. Am I missing something?
Need to take a break? Looking for relaxing sounds? I have something right for you.
(by purchasing, you are also supporting further development of related projects).
Thank you for your contribution.
tester
smanatic
 
Posts: 688
Joined: Wed Jan 18, 2012 9:52 pm
Location: Poland, internet

Re: some thoughts on pulse and pulse width

Postby rl on Fri Jan 20, 2012 11:54 am

yes, you're missing aliasing.
User avatar
rl
dsp wiz
 
Posts: 1494
Joined: Mon Feb 07, 2005 10:24 pm
Location: de.earth.universe.known

Re: some thoughts on pulse and pulse width

Postby trogluddite on Fri Jan 20, 2012 12:05 pm

tester wrote:should produce ideal pulse waves

The problem here is that when using a digital system there is not really any such thing as a perfect square wave.

A perfect square wave is made up of a series of harmonics that stretch all the way to infinity. But when using a sampled digital system, there is a maximum frequency (half the sample rate) that is the maximum you can generate.
Using a 0-1 'switching' system, all of the higher harmonics are still there - what happens to them is that they have their frequencies transformed into ones that your soundcard can play back.
But those are not the right frequencies to make a good sounding square wave - they become nasty 'aliasing'. Aliasing is a horrible form of distortion because it has many frequencies that are not related to the pitch of your 'note', which sound out of tune (they go down when your note pitch goes up, for example).

The SM form of PWM does look rather complicated, I agree. But it is done that way because the saw oscillators used have had all of the 'too high' harmonics removed ('band-limited oscillators'). So the square wave produced also has no 'too high' harmonics.
Although the resulting square wave is not 'perfect' (if you look with the scope tool, you can see this) - it will sound much better, because it is not asking your soundcard to do the impossible thing of making frequencies more than half the sample rate.

It's a complex subject, and I doubt I have explained it very well - a quick google for 'aliasing' will find you many much better explanations.
Feel free to use any schematics and algorithms I post on the forum in your own designs - a credit is appreciated (but not a requirement).
Don't stagnate, mutate to create. Without randomness and serendipity the earth would be just another barren rock.
User avatar
trogluddite
smychopath
 
Posts: 3024
Joined: Mon Oct 20, 2008 3:52 pm
Location: Yorkshire, UK

Re: some thoughts on pulse and pulse width

Postby tester on Sat Jan 21, 2012 12:36 am

Okay, thanks for explanation on that, it clarified everything. My thinking is just still between seeing digital logic (idealistic signals) and non-audio related electronics, where idealism is desiderable and sometimes difficult to achieve. ;-)

I also thought about this topic in terms of using the pulse as a slow AM modulator (on/off switcher), where these glitches are rather not good for smooth and quick switching the sound. One of ways to make it roght in cooledit for exampple - was to use exp function to sinus wave, I guess another one would be to use some trapezoid with 10-20 ms smoothing edge (made from sinus by cutting the tops).
Need to take a break? Looking for relaxing sounds? I have something right for you.
(by purchasing, you are also supporting further development of related projects).
Thank you for your contribution.
tester
smanatic
 
Posts: 688
Joined: Wed Jan 18, 2012 9:52 pm
Location: Poland, internet

Re: some thoughts on pulse and pulse width

Postby Acrobat on Sat Jan 21, 2012 12:01 pm

User avatar
Acrobat
smaniac
 
Posts: 1660
Joined: Mon Jun 04, 2007 10:50 pm
Location: Roma, Italia

Re: some thoughts on pulse and pulse width

Postby Leslie147 on Tue Jan 24, 2012 11:33 pm

Acrobat wrote:...you can either way produce a clean square using additive synthesis, summing up sine waves:
http://en.wikipedia.org/wiki/Gibbs_phenomenon


That Wikipedia article appears to suggest that the half-magnitude of the resulting square wave (in the flat parts) is the same as the amplitide of the fundamental sine wave, but it isn't - it's smaller.

A 4/Pi scaling factor comes out of the full Fourier integral, see http://mathworld.wolfram.com/SquareWave.html, so adding:

(4/Pi)sinx + (4/3Pi)(sin3x) + (4/5Pi)(sin5x) + (4/7Pi)(sin7x) + etc.

... would result in a square wave with unit half magnitude. Conversely, adding:

sinx + (sin3x)/3 + (sin5x)/5 + (sin7x)/7 + etc.

... as in that Wikipedia article, would result in a square wave with a half-magnitude of Pi/4 (i.e. less than the unit amplitude of sinx).

Occasionally, I have found it intriguing (and counter-intuitive) that removing the harmonics from a square wave by low-pass filtering should make its voltage excursion increase, although I haven't found a use for this yet.

The Wikipedia entry on 'Square wave' http://en.wikipedia.org/wiki/Square_wave gets the sum right but uses the same, misleading, graphic.

Chris
User avatar
Leslie147
essemer
 
Posts: 38
Joined: Sun Jun 24, 2007 4:34 pm
Location: West Wales


Return to Sound

Who is online

Users browsing this forum: No registered users and 1 guest