Beginner questions on producing "perfect" square waves

Started by ThinkingMan, September 23, 2019, 07:21:05 PM

Previous topic - Next topic

ElectricDruid

Quote from: Ben N on September 24, 2019, 02:17:02 PM
PWM is pretty close to a perfect square wave.

I don't really know what you mean here, Ben.

I like PWM too, but since a PWM waveform spends so little time actually being square (mostly being some other pulse wave somewhat away from a pure 50/50% square wave) it seems a bit odd to say its a perfect square.

We should mention the easy way to get a perfect 50%/50% square if you've got a fixed frequency pulse from a 555 or whatever is to run it through a flip-flop to divide it down by two. The flip-flop's output is guaranteed to be square as long as the frequency isn't changing.

HTH,
Tom

PRR

Quote from: Phoenix on September 23, 2019, 11:15:06 PMEasy, use the in-built calibration signal on the oscilloscope. This is always a square wave, and is almost always 10kHz. It will always have better rise-and-fall-times than the bandwidth of the scope is capable of displaying. This is used for calibrating your probes. ...

It's not always better than the 'scope. It really only has to be considerably better than the cross-over point of the 10:1 probe, often in the kHz not MHz range.

It will normally be calibrated for Volts and Seconds, as a quick verification of the internal gain and time-base, especially when turned to a VAR position.
  • SUPPORTER

Rob Strand

#22
I wasn't going to mention anything but consider what it means to have perfect square-wave for an audio signal.

The main points are:
- we can only hear upto 20kHz (as an upper limit)
but
-   the harmonics of a "perfect" square-wave extend to infinity.

Clearly there's something pointless about the goal of a perfect square-wave for audio.

So one view is to take a 1kHz square-wave and sum all the odd harmonic upto 19kHz.
The result is a rippled waveform such as the plot about halfway down this page,
https://www.allaboutcircuits.com/textbook/alternating-current/chpt-7/square-wave-signals/

[not 1kHz but the shape is the important thing]


So to the eye it looks bad but to the ear it's a perfect square wave.

So another approach would be to take a squarewave pass it through a first-order low-pass filter.
If the filter cut-off is high enough (say 200kHz) there is little filtering of the square-wave harmonics upto 20kHz so to the ear it sounds like a square wave.   The waveform in this case will have sloped edges.  For a 200kHz first order filter the rise and fall times would be 1.75us which you can see on a CRO if you zoom in.  The waveform would have this shape,

[not 1kHz but the shape is the important thing]


So the next step would be to use a higher order filter with a cut-off of say 200kHz.  Again the harmonic up to 20kHz are left pretty much intact.   In this case we would get a waveform which looks like,

[not 1kHz but the shape is the important thing]


The ringing looks bad to the eye but the ring is at 200kHz, way above human hearing.   It's like bats chirping while listening to something we simply don't hear the extra signals.  In fact we can add a whole heap of rubbish to the square wave.  If the harmonics of the added signal are above 20kHz we would not hear it but the CRO waveforms would not look like a square-wave at all.
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

Rob Strand

#23
QuoteIt's not always better than the 'scope. It really only has to be considerably better than the cross-over point of the 10:1 probe, often in the kHz not MHz range.
It actually doesn't need to be that great since the compensation adjustment affects quite a large fraction of the waveform.     If you try to adjust it with a high frequency square wave often you see tilt when you look at a low frequency square-wave.

For some of very old CROs the edges were quite slow so you could set-up the astigmatism.
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

Phoenix

Quote from: PRR on September 24, 2019, 07:02:44 PM
Quote from: Phoenix on September 23, 2019, 11:15:06 PMEasy, use the in-built calibration signal on the oscilloscope. This is always a square wave, and is almost always 10kHz. It will always have better rise-and-fall-times than the bandwidth of the scope is capable of displaying. This is used for calibrating your probes. ...

It's not always better than the 'scope. It really only has to be considerably better than the cross-over point of the 10:1 probe, often in the kHz not MHz range.

It will normally be calibrated for Volts and Seconds, as a quick verification of the internal gain and time-base, especially when turned to a VAR position.

My mistake, apologies to the OP, but does serve to illustrate my point of:
Quote from: Phoenix on September 23, 2019, 10:41:41 PM
Remember, just because you read something on the internet does not make it true.

ThinkingMan

Ok wait, perfect square waves are not equal to symmetrical square waves with equal sides and equal angles. Such as these pictures below. Right?





These symmetrical square waves are possible to reproduce on the oscilloscope, I believe. Most square wave sounds I heard came from irregular square waves but I never heard anything coming out from these kind of square waves. The closest is the Raise The Dead fuzz from Tatefx, but not all of the square waves are equal in sides especially the smaller rectangular waves next to the squarish waves. It is a silicon based fuzzbox.





ElectricDruid

Quote from: ThinkingMan on September 25, 2019, 03:10:05 AM
Ok wait, perfect square waves are not equal to symmetrical square waves with equal sides and equal angles. Such as these pictures below. Right?





Right. The crucial part of those diagrams that makes those "perfect square waves" is that the relationship between the high and low periods should be exactly 50%/50% (AKA the duty cycle). The amplitude is variable, so the height of the waveform can go up and down. You can have quiet square waves and loud square waves, and they won't look as neatly "square" as the ones in the little diagrams, but they're still perfect square waves.

Quote
These symmetrical square waves are possible to reproduce on the oscilloscope, I believe. Most square wave sounds I heard came from irregular square waves but I never heard anything coming out from these kind of square waves. The closest is the Raise The Dead fuzz from Tatefx, but not all of the square waves are equal in sides especially the smaller rectangular waves next to the squarish waves. It is a silicon based fuzzbox.





Yep, those are getting pretty close. As you've noticed, the duty cycle is not the perfect 50/50, so you don't get exactly the harmonic series of a square wave. Other pulse waves have some even harmonics, whereas the perfect square wave has only odd harmonics (More about that here: https://electricdruid.net/timbral-evolution-harmonic-analysis-of-classic-synth-sounds/).