2
\$\begingroup\$

I'm not so deeply into the theory about all this, I may use strange terminology...

If I put a square wave through a simple lowpass RC filter, the output will be a sort of "rounded sawtooth", well not so much a ramp but a capacitor charge curve followed by a discharge curve. Like this: enter image description here

So I tried to replicate this in a computer program, in a band-limited form. First, I made a function to add harmonics, as weighted sum according to the typical falloff for a square wave. That alone looks indeed like a slightly lowpass filtered square on an oscilloscope.

Next I wrote a second function, which was supposed to impose the LPF frequency response curve over the harmonics envelope of the square wave, i.e. such that the weights of the summands would take into account the lowpass response.

Now, of course, the result is not the same, I get a rectangle with both corners rounded off, instead of a saw-toothy asymmetrical wave. Intuitively I'd say that what's not taken into account here is the "lag" of such a low-pass filter.

How could I mathematically incorporate this information to produce the harmonics sum the correct way? (I.e. not using a sample-based 1-pole LPF implementation)

The actual goal of this is to obtain one precisely-cut, glitch-free, loopable period of the waveform. I.e. if a harmonic falloff function is known for this type of waveform ("capacitor nonconst charge sawtooth"), like there are for other known waveforms, that would be sufficient as an answer.


P.S. feel free to add pointers to further waveforms and the way to generate them via harmonic sums - other than square, tri, saw, which are in wiki ;)

\$\endgroup\$
  • \$\begingroup\$ Electronic or software implementation? (Description looks sampled rather than continuous to my eyes, though.) Is this some kind of duty cycle corrector? Can you do this long after the fact in post processing? Or? (Sorry about my confusion.) \$\endgroup\$ – jonk Aug 22 '16 at 2:52
  • \$\begingroup\$ Yes you have to take into account not only the amplitude attenuation but also the phase delay for each harmonic \$\endgroup\$ – Claudio Avi Chami Aug 22 '16 at 8:10
  • \$\begingroup\$ @Claudio ah, this sounds like something I understand, if I'm up to the math is another question, but I'll look into that in the evening. @ jonk: yes, software implementation, I'm generating a lookup table \$\endgroup\$ – user1847129 Aug 22 '16 at 8:23
  • \$\begingroup\$ By the way - would the human ear notice a difference if the phase response is accounted for vs. if not and it's only haromics? \$\endgroup\$ – user1847129 Aug 23 '16 at 12:00
  • \$\begingroup\$ One thing that is bothering me is that the input max voltage is 10v, but the output max voltage is 12v? With respect to the "rounding" of both corners, it seems you are applying the same "charging" values, but in reverse for the trailing corner. This is wrong. You need to calculate the "discharging" values, for the trailing corner. \$\endgroup\$ – Guill Aug 26 '16 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.