Decomposing a Square Waves

  • yes! this was my understanding as well
  • absolutely; my apologies for such poor wording! my hope here was to clarify that I had a (basic) understanding of Fourier transforms. But this is good advice in any case.
  • hrmm, i think i need to think about this some more, as it creates a circular argument (i think!)… If I put a perfect square wave, generated by some means - the FFT will tell us that there are harmonics; and a filter will reduce the amplitude of them and again we will see that on a FFT. I have the AD2 and there is a great article on it here: Using the Analog Discovery 2 to Measure Harmonics in a Signal - Digilent Reference - but my fundamental (pun intended!) question is why those harmonics exist in a perfect square wave to begin with! In fact there was a similar question asked on Stack Exchange (Where do overtones in a 555 generated square wave come from?) - though I didn’t find any of the answers “satisfying” - for example here is a small selection, which I think captures the general confusion on this topic, and the mental-model I have right now.

  • “Odd harmonics are fundamental to a square wave as your second illustration shows. (It would be better explained as : a square wave can be decomposed into an infinite series of sine waves)”

  • “It’s not that a square wave can be constructed from sine waves, as some optional thing or wacky view of it. A square is composed of sine waves.”

  • " The FFT (actually a dft) is looking for sinusoidal content by definition."

  • “The square wave is . The 555 created it by switching the output. By feeding it into a spectrum analyser, you’re asking the question ‘what sine waves make up this square wave?’. If you’d fed it into a power meter, you’d be asking the question ‘what’s the power in this square wave?’ BTW, the 555 generates an approximation to a mathematical square wave, because the output voltage can’t switch infinitely fast. It’s pretty fast compared to 2.5kHz, but not fast compared to 100MHz”

  • “It does not mean that whatever generated the signal generated separate sinusoids, only that the resulting signal can be represented in this (very useful) way.”

  • “The key issue is that not only CAN a square wave be constructed from sine waves, it fundamentally IS a collection of sine waves.”

  • the Nuts & Volts article also says “Basically, a square wave consists of a fundamental frequency with a lot of higher harmonics. If the harmonics can be removed, then a sine wave of the fundamental frequency remains.”

The answers here essentially say “there are no sine waves, but the FFT by its nature is able to extract them and show them” and thats ok, i can understand that - it can mathematically break down the square wave it sees. But if we think about some practical implications and think about the signal; a rising edge that experiences ringing - for example, this video from Robert Feranec Everyone designing boards needs to know this about power and noise | Florian Hämmerle|, from the transcript:

“Because the edge of course is step but the step contains all the frequencies… it triggers the resonance and the resonance rings”

this video is talking about if you switch an output at a specific frequency, due to the resistance, inductance and capacitance on the Vcc line, there will be a resonant frequency and if your output switching is the same frequency, you get much higher noise on the Vcc line

image
in this image, the blue trace is the output GPIO, the yellow is the noise on the Vcc line - you can see the ringing when zoomed in.

Another video from Robert Feranec (and partially what kick started this journey) - Why the circuit in the thumbnail is wrong? Do you know?, specifically at 12:53

“also keep in mind that the square waves or signals with very sharp edges, for example when your chip is communicating with all the other chips or when it is controlling I/O pins for accessing to memory, these kinds of sharp signals they contain all the kind of frequencies

All About Circuits: Square Wave Signals - “When a square wave AC voltage is applied to a circuit with reactive components (capacitors and inductors), those components react as if they were being exposed to several sine wave voltages of different frequencies, which in fact they are.”

What is driving my desire to understand this is, of course, the issue Robert Feranec is referring to (and others) where by sharp changing signals / square waves has negative consequences and being able to consider that impact in designs (which incidentally may not be hardware designs, but as Robert shows you may want to avoid switching outputs at specific frequencies which can be a software choice!)

I may be reading ahead here in to an answer from @metacollin however it makes sense in context here, is the Fourier transform just a neat mathematical trick we can exploit for analytical or design purposes? the answer is, as has been shown many times practically, no! it is a real thing (again, see the Robert Feranec’s video Everyone designing boards needs to know this about power and noise linked above for practical demonstration) - I am just not linking concepts properly yet!


p.s: with regards to Robert’s videos, I have reached out to him, as I wasn’t sure what was actually causing the ringing in the first place.

  • The videos start with the notion that when a MCU switches an output, the MCU will draw more current (reasonable)
  • due to internal resistance, track resistance etc, when more current is drawn, there will be more voltage drop across the stray resistance, and so Vcc will drop. Thus there will be ripple on the Vcc line that has a frequency equal to the output switching frequency (still ok!)
  • it is not pure resistance, rather it is complex impedance and so there will be a resonant frequency (still ok!)

so, is the ringing at the resonant frequency of the Vcc circuit formed by the stray resistance, impedance and capacitance caused by

  1. the ripple frequency matching the resonant frequency or
  2. the square wave nature of the output switching or
  3. combination!

my initial thought was it was due to the ripple, but the conversation between Robert and Florian leads me to believe they were implying the second option - however it is not very clear, hence I have reached out to Robert for clarification.