'sine wave' from a triangle wave

ANDREW221231
ANDREW221231 Member Posts: 295 Advisor

ok, this isn't quite a sine wave, but rather, as one of the commenters in the youtube video i got this from astutely called it, a potato. there is still a fair bit of THD, but its still pretty neat: you take a triangle, square it, invert, add dc offset, and then square again

compared to the primary 'parabol' oscillator, it has even and odd order harmonics instead of only odd, but has a somewhat steeper roll-off. anyway, i just like neat waveform tricks like these. it reminds me of how you can integrate a saw wave by squaring it. if anyone knows of any other tricks like these, feel free to share!


Comments

  • Laureano Lopez
    Laureano Lopez Member Posts: 102 Advisor
    edited March 2022

    Trig approxes are back! Yays (?)

    (I promise I'll upload that stuff, like... this year.)

    This is similar to how we actually do sines in Reaktor, with polynomials on a triangle. It's a cosine approx on a -1..1 triangle an octave below. I tried to find a closer approx with those limitations (-1..1 an octave below, same order), and I don't think it's possible, there are no degrees of freedom. For about the same amount of ops, you can get a closer sine approx on a -1/2..1/2 triangle at the same octave, like the core sine but lower order. I like this one though, it's neat and simple. Still trying to find out what's the primary parabol πŸ˜…

  • ANDREW221231
    ANDREW221231 Member Posts: 295 Advisor
    edited March 2022

    oh dang, that's interesting, i never realized it worked like that. always kind of assumed the input to the sine oscillator would be a regular phase ramp, something like 0-1 defining a full rotation of a circle in a way that's abstracted or airgapped from the actual signal output, like how the primary sine function works


    but that's not how it works at all, seems they have opted instead to take a triangle wave and amplitude modulate its harmonics away... the absolute madlads!

    of course that's probably a funny way of putting it, but still interesting to think about in those terms


    anyway, yeah, mine obviously doubles the frequency, i guess that squaring of the signal is better served as part of a polynomial that is be applied to the original signal, it seems the curve of the difference between a sine wave and a triangle would have elements that were 'double the frequency', in a manner of speaking? i don't really know anything about polynomials but its fun to probe each stage of multiply add with a scope and at least try to get a sense for what's going on


    this idea came from a guy named dave seig whose life passion preserving the legacy of the old analog scanimate machines that made graphics before computers took over, where presumably sometimes you need a sine wave but all you have handy is a couple op amps and voltage multipliers (and where people say things like 'very pure sine wave generally meaning the opposite 🀣)

  • Laureano Lopez
    Laureano Lopez Member Posts: 102 Advisor

    always kind of assumed the input to the sine oscillator would be a regular phase ramp, something like 0-1 defining a full rotation of a circle in a way that's abstracted or airgapped from the actual signal output

    The idea of using a -1/2..1/2 triangle is that you only need to approximate a half cycle, which is much easier than a whole cycle:

    You get a poly approx for that part, then the triangle "reads" it forward and backward. Seig's potato works on a -1..1 triangle, which is 1 minus squared to get a parabol:

    There you have already doubled the frequency, because you get two identical copies of this for each triangle cycle. When you square it again, it becomes smooth:

    It peaks at zero, so we can say it's a cosine approximation. It's pretty unique in that it crosses zero at the wrong point, so its positive and negative lobes are different (one is "fatter" than the other).

    For sine on -1/2..1/2 in the same octave, you can get a very cheap approx that has a higher buzz, but much lower first harmonics. The next order is much quieter. Here is the precision in bits for Seig's potato (blue, shifted to match a sine), primary parabol (yellow), a 3rd order sine (green) and a 5th order sine (red):

    There you see how the potato is different below and above zero.

  • ANDREW221231
    ANDREW221231 Member Posts: 295 Advisor

    i guess that explains seeing the even order harmonics, and also makes calling it a potato even funnier.


    you figured out the parabol oscillator! think that one's even more elegant in an even hackier way, and i approve of it more. seems if you must have overtone content its better for it to be odd harmonics so at least they're more spread out


    but the things that's really got my interest now is the sine approximations. it certainly makes sense when you describe a linear mapping to a half cycle (i've even heard of quarter?) nothing about that doesn't make sense


    however whenever i think of this process being carried out care of amplitude modulation i get terminally confused. whatever small amount of frequency content there is in the polynomial would still have sum and difference frequency, you know, triangles have harmonics and in my mind any amplitude modulation of a complex waveform should still have sum and difference sidebands as well as at the harmonics... so where did the sum frequencies of harmonics go?? surely not up??


    like this is very off putting, because i can see how of course one could apply some curve to a triangle until it was shaped like a sine wave, but with certainty that frequency content had to go somewhere... did they all go in to the sine wave?? did they the sum/differences move into each other and destructively annihilate? that doesnt make sense either.. maybe sidebands could do that but what about the 'AM baseband'??


    this aggressively does not make sense

  • Laureano Lopez
    Laureano Lopez Member Posts: 102 Advisor

    I had never thought about it in terms of modulation, and I'm not fluent enough to have a clear picture of what happens spectrally at each step. In a very basic, time-domain sense, you can see what happens looking at the scope for each step. Up to the last multiply, the function is making a parabol (of 2nd, 4th, etc order) with some DC bias. Then at the last step it's multiplied by the triangle, and magically (?) all discontinuities are smoothed. It makes some sense if you think you're multiplying a unipolar, even function by a bipolar, linear one -then it becomes and odd function, so instead of having all the arcs going upwards, they alternate, up and down, and the spikes become smooth points. A similar kind of thing happens in the potato when the parabols are squared, which is also similar to what happens when you square an absolute value. It's pretty weird to think in spectral terms that x^2 = abs(x)^2, when x and abs(x) are so different. I guess there could be a frequency-domain explanation, but I'm pretty sure it would look like those parts in Puckette's book where I just roll my eyes in muffled agony

  • ANDREW221231
    ANDREW221231 Member Posts: 295 Advisor
    edited March 2022

    looking at the spectrum gives some ideas... left to right we have the 'modulating polynomial' (with DC bias removed) and the triangle. the spectrum of the modulation signal lies exactly at the triangle's missing even order harmonics!


    this gave me an idea to see what would happen if one applied this same modulation signal to a triangle wave with the fundamental removed... how then would the modulation signal interact with only the part of the triangle wave it is meant to cancel out?. well, as you can see here: the top pic is the spectrum of the triangle, the next is the triangle with the fundamental removed, and the third pic is the output of modulation with the polynomial.

    guess its no great surprise that everything didn't perfectly cancel out leaving only null signal lol. maybe that suggest a frequency domain perspective is not the most useful?


    then again, a triangle wave with its fundamental removed looks like this, so actually with a little DC bias added, one can kinda get a better idea of what's happening spectrally. see this ensemble



  • Laureano Lopez
    Laureano Lopez Member Posts: 102 Advisor

    Sorry, I got distracted with wavetables and paperwork 😁

    I don't think I can shed much light on this confusing matter -it is, indeed, hard to think about in spectral terms. The alternating harmonics are expected, as the triangle has partials 1, 3, 5, 7... and its square gives a parabol at the octave, hence with partials 2, 4, 6, 8... In fact, a triangle itself is the sum of two parabols at the same frequency, one of them inverted and shifted by a half cycle. So if you square two triangles shifted by a quarter cycle, then invert one and add, you get a triangle at the octave! This makes sense because the quadratic terms cancel out, sort of like:

    The inversion may be relevant for any spectral understanding of this -every other harmonic in a triangle is 180ΒΊ out of phase, which may explain the cancellations after modulation.

  • Studiowaves
    Studiowaves Member Posts: 451 Advisor

    I don't know why you guys mess with this stuff, the 27bit 9th order job from Laureano works great. But I guess we have to have fun trying new things. hey hey.

  • ANDREW221231
    ANDREW221231 Member Posts: 295 Advisor

    imostly academic, laureanos perfect sine waves are a fantastic tool but not much fun to ponder. sine waves are understood to death, but the humble potato holds secrets!!!


    anyway colin was messing with tonewheel simulations and it might actually be the most useful for something like that. sometimes you want a dirty sine wave, and this one contains even harmonics unlike the factory parabol which has only odd

  • ANDREW221231
    ANDREW221231 Member Posts: 295 Advisor

    yeah it pretty much makes sense now, a biiiiig improvement from aggressively not making sense, or even the short time window when it was simply 'vexing'



    think the only thing i'm thinking of now is how some waveshapes are integrated by squaring, so filtered and dc shifted, as opposed to doubled in frequency and DC shifted like a sine. guess it'd be a similar phenomenon and probably also dependent on those even harmonics


    cant remember if i came across an exception to those behaviors being exclusive to wave symmetry. i well might have, but i'm putting it in the past, this relative lack of confusion is on weak legs

  • ANDREW221231
    ANDREW221231 Member Posts: 295 Advisor


    also while on the subject of even harmonics, i was playing around again the other week with an 'even harmonics oscillator' since i know core a bit better since the last attempt and finally got a functional oscillator



    ignoring that harmonic 1, the fundamental frequency is odd, i took a sine wave and added even harmonics to it by mixing with a sawtooth shifted up an octave


    what i found out is there is no way to produce this waveform and not have it simply be percieved as a sawtooth an octave higher... even adding in some of the lower missing odd harmonics and transitioning to even only @ higher order harmonics , your brain simply listens to 'how far apart in hz' overtones are


    like...i always knew about missing fundamental but never realized it was that aggressive

  • colB
    colB Member Posts: 762 Guru


    your brain simply listens to 'how far apart in hz' overtones are

    Yeah, brains are ridiculously good at recognising patterns even with some parts missing, or some additional noise. So if it's mostly the pattern from that saw, that's what is percieved.

    The sine an octave down is maybe ignored more strongly because sines are quite an unnatural thing by themselves. Are there any truly pure non man made sines?

  • colB
    colB Member Posts: 762 Guru
    edited March 2022

    anyway colin was messing with tonewheel simulations and it might actually be the most useful for something like that

    I plotted a wave where y is the distance between a point and the edge of a rotating polygon, and x is modulo 2pi. It's quite close to squaring a triangle wave, but slightly chubbier... in the same way that the squared tri is chubbier than a full wave rectified sine. The tri thing is closer than the sine, but still visibly different. Haven't studied the spectrum yet though.

    I think much of the waveshape will come from the integrating effect of the pickup. I wonder if that can be very badly modelled just by using a very leaky integrator on the point based waveform.

    Then there's those pesky flower petal tone wheels for the higher frequencies. The harmonics will depend on exactly what type of curve is machined into that edge... and then working out how that will be smoothed out by the pickups magnetic field being wider than a petal... really better to just model the waveform than try to do analytic math for the mechanicals and the magnetics and the electronics...

    There's a FEM plot on one of the papers, and that's interesting, but I think fem only gives you instantaneous values, so you don't get the effect of the hysteresis of the magnetic field or the pickup coil (probably not technically hysteresis in the coil, but similar lag effects?). Haven't used fem for over a decade though.

    This is where we really need to see scope plots of the hardware being modelled. Without access to some data like that, there's not much point. And recordings of a complete Hammond are so full of other stuff, that it will be difficult to guess what distortions come from the tone wheels and what come from amplification and filtering or even leslie cabinet and microphone


    EDIT: hehe, seems I thought I was posting this in the other thread

  • Studiowaves
    Studiowaves Member Posts: 451 Advisor

    Exactly mang, nothing more fun than a smokin' dirty waves to change things up. I dig... You can even use them in fm synthesis but you need to take it easy on the harmonics of a modulator. Those harmonics create harmonics of their own in the carrier and you can end up with something that will fry your brain. lol

  • Laureano Lopez
    Laureano Lopez Member Posts: 102 Advisor

    like...i always knew about missing fundamental but never realized it was that aggressive

    It is 😊 One of my favorite, simplest harmonic effects is a bare two-voice counterpoint that goes in and out of dissonances with most fundamentals ommited. Your brain perceives their absence as a hole, it gives a pretty rough, abstract impression.

Back To Top