• WANTED: Happy members who like to discuss audio and other topics related to our interest. Desire to learn and share knowledge of science required. There are many reviews of audio hardware and expert members to help answer your questions. Click here to have your audio equipment measured for free!

Composition of a Square Wave (important!)

René - Acculution.com

Senior Member
Technical Expert
Joined
May 1, 2021
Messages
427
Likes
1,303
If we use a steep filter than rolls off everything over the seventh harmonic, then we'll generate a signal that looks like the "F1-7" curve in the first plot above. Notice the waveform now looks like it has overshoot and ringing, but in fact the shape is because we filtered out the higher frequencies. This is not due to some component failure or phase margin issue, but simply because we filtered our "ideal" square wave so it no longer has all the frequencies needed to create that perfect flat top and sharp edges.
I saw this be a huge problem in a project in a company that I used to work for: A clipped microphone signal had a known maximum amplitude, and knowing the amplitude, the engineers could design an input state accordingly, even is the signal should clip. But in practice the amplitude of the measured signal was quite a bit higher, and several engineers ran around for weeks testing the measurement equipment and scratching their heads. It was not until me and anther co-worker got involved, it was found that there was a filter before the input state that removed a lot of the harmonics leading to the higher amplitude. This is why I push my students into really getting the fundamentals right, and not rely on intuition and working by analogy.
 
Last edited:

DonH56

Master Contributor
Technical Expert
Forum Donor
Joined
Mar 15, 2016
Messages
7,880
Likes
16,667
Location
Monument, CO
I saw this be a huge problem in a project in a company that I used to work for: A clipped microphone signal had a known maximum amplitude, and knowing the amplitude, the engineers could design an input state accordingly, even is the signal should clip. But in practice the amplitude of the measured signal was quite a bit higher, and several engineers ran around for weeks testing the measurement equipment and scratching their heads. It was not until me and anther co-worker got involved, it was found that there was a filter before the input state that removed a lot of the harmonics leading to the higher amplitude. This is why I push my students into really getting the fundamentals right, and not rely on intuition and working by analogy.
Yup! In my day job it is also a big problem since we are dealing with risetimes in the 5~30 ps range and DSOs with bandwidth in the 33~100 GHz range but the cables filter the edges, plus the internal DSO processing to enhance bandwidth can do squirrely things to the waveforms. I can see the problems but not hear them... :)

A friend of mine would derive almost everything from first principles. It was sometimes pedantic to annoying but he was invariably right. Years ago in a class on device physics, one of my professors handed out a quiz on day 1 with a bunch of common units like ampere, volt, ohm, watt, farad, henry, etc. and said to express them in MKS units. I got a few, sort of; what an embarrassment for a bunch of cocky know-it-all college kids...
 

xaviescacs

Major Contributor
Forum Donor
Joined
Mar 23, 2021
Messages
1,499
Likes
1,977
Location
La Garriga, Barcelona
Years ago in a class on device physics, one of my professors handed out a quiz on day 1 with a bunch of common units like ampere, volt, ohm, watt, farad, henry, etc. and said to express them in MKS units. I got a few, sort of; what an embarrassment for a bunch of cocky know-it-all college kids...
I remember answering some questions in non-elementary physics test using fundamental and "second layer" units as C, J or eV, just because I was unsure about those "deeper" EE units. No teacher ever marked that as incorrect :p
 

600_OHM

Active Member
Joined
May 19, 2022
Messages
162
Likes
119
Ah, this is making me want to break out a moog synth! :)

First time I ever saw a square wave demonstrated was by Wendy Carlos in this clip. Filters and envelope generators ! Too young to really understand but was mesmerized!

 

mirlo

Member
Joined
Sep 6, 2018
Messages
17
Likes
15
....

This is something we who do testing and measurements need to keep in mind lest we chase "ringing" in our designs that is not really there (don't ask how I know this). In my case, running the output of a 70 GHz clock signal into a 33 GHz oscilloscope resulted in Gibbs ringing, and sure enough I chased my tail for a bit looking for mismatches and such before slapping my head and remembering the basics.
.....
33 GHz oscilloscope :cool:
 

DonH56

Master Contributor
Technical Expert
Forum Donor
Joined
Mar 15, 2016
Messages
7,880
Likes
16,667
Location
Monument, CO
33 GHz oscilloscope :cool:
NASA calls Don when they need to confirm alien communications, especially since Arecibo is totally fugged and out of action.
33GHz? That's quite the scopeski!
The new ones in the lab are 67 GHz (256 GS/s); 33 GHz is too low in bandwidth to meet the latest serial standards. But, after any reasonable length of PCB trace and/or cable, 33 GHz is still enough IME/IMO... But one reason I don't borrow stuff from work is that I am leery of taking a 'scope worth more than my house to my house. :) Highest system I have ever worked with was ~300 GHz, but at that point it is all plumbing waveguides and math above my little pea brain.

Back when I was doing R&D contracts I worked with NASA a fair amount. The cool part was getting to visit the sites where it all happened. One time we were on the floor with the astronauts getting ready for a mission, albeit at about 30' distance (to get closer had to have bunny suits and be cleared by a doctor). It was neat the way everything was in synch, what the astronauts and control room were doing, etc.

As for Arecibo, had to look that one up. Reminded me of some James Bond movie. :)

But I have said audio is not my day job, though the principles don't change. This is just for "fun".
 

Geert

Major Contributor
Joined
Mar 20, 2020
Messages
1,944
Likes
3,548
Today I stumbled upon this nice article which discusses a common pitfall when creating (and listening to) digital bandwith limited squarewaves. The page also provides an online generator that allows you to test what a (correctly) bandwidth limited square wave sounds like (source code provided to create your own test signals). I add it to this thread as a reference: https://www.nayuki.io/page/band-limited-square-waves.

A fun test for who's new to this square wave theory and which demonstrates what's explained in the OP. Scroll down to the generator demo, enter 1000 in the Frequency field and press play. Now on top switch the Wave type between Sine and Square (band-limited) and see what difference you hear between a sine and square wave. Now do the same for the frequency set to 10000 (a frequency for which all uneven harmonics of the base signal which form the square wave are outside the audible band).
 

fpitas

Master Contributor
Forum Donor
Joined
Jul 7, 2022
Messages
9,885
Likes
14,201
Location
Northern Virginia, USA
Sheesh, this far into the thread and no troll has arrived to question Fourier's Theorem. Must be because raw math doesn't allow subjective blather.
 

tomtoo

Major Contributor
Joined
Nov 20, 2019
Messages
3,713
Likes
4,777
Location
Germany
Bah, 33GHz. Pillepalle

Terahertz radiation – also known as submillimeter radiation, terahertz waves, tremendously high frequency, T-rays, T-waves, T-light...


Until dacs dont operate there the audiophiles can hear the steps in the signal. And maybe even then? ;)
 

pma

Major Contributor
Joined
Feb 23, 2019
Messages
4,602
Likes
10,769
Location
Prague
Just to explain, this is the 1kHz "square wave" that I use and need for testing of stability margin of preamplifiers and power amplifiers.

1kHz square from my generator
GEN038_1ksq.png


Short rise time of the edge is extremely important
GEN038_rise.png


And this is the spectrum up to 10MHz
GEN038_1ksq_spectrum.png


Anyone would create it with an audio DAC and summation of the sine waves? I really do not think so.
 

restorer-john

Grand Contributor
Joined
Mar 1, 2018
Messages
12,679
Likes
38,782
Location
Gold Coast, Queensland, Australia
Just to explain, this is the 1kHz "square wave" that I use and need for testing of stability margin of preamplifiers and power amplifiers.

1kHz square from my generator
View attachment 229648

Short rise time of the edge is extremely important
View attachment 229649

And this is the spectrum up to 10MHz
View attachment 229650

Anyone would create it with an audio DAC and summation of the sine waves? I really do not think so.

Is the overshoot the square wave generator or the sinc interpolation on the Pico? Clean square- is that the unit you designed and showed in the 'what's on my bench thread' a while back? :)
 

pma

Major Contributor
Joined
Feb 23, 2019
Messages
4,602
Likes
10,769
Location
Prague
Is the overshoot the square wave generator or the sinc interpolation on the Pico? Clean square- is that the unit you designed and showed in the 'what's on my bench thread' a while back? :)
It is the Picoscope response, completely. The generator has about 5ns rise time, at the moment I have no scope fast enough to show it properly. Yes I built the generator. And with this short times, even the coax makes a difference, an yes it must be terminated by 50 ohm and the generator has 50 ohm output impedance.
 

egellings

Major Contributor
Joined
Feb 6, 2020
Messages
4,059
Likes
3,301
The extremely sharp edge on the square wave is simply not needed for analog audio signals. High speed D1G1T0L [sic] signals would need that, however. The sharpness of the edge shown in the image above is much sharper, or closer to vertical than a 20kHZ upper limit audio signal would need. All an edge that steep will do is make life difficult for linear or switch-mode amplifiers trying to reproduce it, and no speaker would even think of trying to do so.
 

pma

Major Contributor
Joined
Feb 23, 2019
Messages
4,602
Likes
10,769
Location
Prague
Is the overshoot the square wave generator or the sinc interpolation on the Pico?
Hi John, I have digged out my good old and retired analog scope. Unfortunately, even that one is not fast enough.
GEN038_analogosc.JPG


And what does this have to do with audio?
for 4K video with speeds up to 12 Gigahertz sure, but audio?
The extremely sharp edge on the square wave is simply not needed for analog audio signals. High speed D1G1T0L [sic] signals would need that, however. The sharpness of the edge shown in the image above is much sharper, or closer to vertical than a 20kHZ upper limit audio signal would need. All an edge that steep will do is make life difficult for linear or switch-mode amplifiers trying to reproduce it, and no speaker would even think of trying to do so.

From a limited view of an usual audio user and consumer, you seem to be right. However, in a design and test phase, the fast generator and fast measurements are absolutely necessary. Below just 2 examples.

1) Preamp oscillations, at about 4MHz (still low frequency). The occurrence of oscillations was irregular and appeared occasionally during connection of input or output cables when the preamp was on, as a result of fast ESD discharge. Fast step was a way to test it.

preamp_oscillations.jpg


2) Irregular oscillations in output diamond buffer of the preamp, at 253MHz. This was extremely difficult to find and the only effect in the audio band was THD rising from 0.001% to some 0.02% and rising modulation of noise floor at frequencies below 1kHz, together with a slightly audible LF hum.

preamp_oscillations_253MHz.png


I understand that a common user can hardly imagine such scenarios, but the laughter based on limited knowledge is not appreciated. You guys might have had some respect to those who do a real job, this is not addressed to only the posters I am reacting at. It is much better to try to learn than to argue based on limited understanding.
 

egellings

Major Contributor
Joined
Feb 6, 2020
Messages
4,059
Likes
3,301
I have seen a signal much like that on my 'scope, around 80MHz or so while examining a power amplifier output (resistively terminated in 8 ohs) with no input signal to the amplifier. Then I powered the amp down, and that signal was still there. I unplugged the powered-down amplifier from the wall and the signal amplitude dropped noticeably but not completely. Looks like RFI to me, rather than amplifier shenanigans.
 

restorer-john

Grand Contributor
Joined
Mar 1, 2018
Messages
12,679
Likes
38,782
Location
Gold Coast, Queensland, Australia
Hi John, I have digged out my good old and retired analog scope.

Keep out your old 'scope. :)

I use both DSOs and my old CROs. The one I always reach for to do something quickly is my oldest 20MHz CRO as it was the first one. The scope I saved up for a long time to buy and it has lived on my bench for over 4 decades. It had a major overhaul a few years back which took me two days.

Never let me down, although the trace is getting a little dimmer these days.
 
  • Like
Reactions: pma

pma

Major Contributor
Joined
Feb 23, 2019
Messages
4,602
Likes
10,769
Location
Prague
Keep out your old 'scope. :)

I use both DSOs and my old CROs. The one I always reach for to do something quickly is my oldest 20MHz CRO as it was the first one. The scope I saved up for a long time to buy and it has lived on my bench for over 4 decades. It had a major overhaul a few years back which took me two days.

Never let me down, although the trace is getting a little dimmer these days.

I agree. After I have wiped off the dust, I have re-realized all the advantages of analog scopes. No aliasing. Even with slow time base you see that "something is happening" because the bandwidth remains uncompromised, not affected by slower sampling at long time base setting as in case of digital scopes. No switching supply - no EMC induced spikes through measuring cable shield.

Analog scopes have their advantages, regardless more complicated capture of records and their archiving.
 
Top Bottom