1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

It is impossible to shift an audio waveform 90 degrees so that it retains the same shape.

Discussion in 'REAKTOR' started by Unobody, Mar 5, 2019.

  1. Unobody

    Unobody New Member

    Messages:
    9
    I have tried math equations,Time Delay, all sorts of waveshaping. Voxengo wave shifter. Reaktor ensembles. The reason I am so obsessed with this issue is because the implications of it are huge. If you were able to shift the phase of an audio signal 90 degrees, and have it retain the same shape, you could theoretically create any waveform you wanted.

    Here's an example.

    I have a sine wave. A basic sub bass tone. If I run the absolute value math function on it using socalabs MATHS plugin, I get a new waveform. (this is called rectifying fyi) But if I were able to take that new waveform, shift it 90 degrees, invert it, and sum it to the old waveform, I get a triangle wave. This procedure CAN be done by using simple time delay, the problem is, that the wave is delayed by a fixed amount of time, and if I change the pitch of my sub bass waveform, the integrity is compromised, and I no longer have a triangle wave, I have a mess. That's because as frequency goes up, the amount of time delay needed to keep one waveform aligned to another changes.

    Hopefully you guys are familiar with cutting waveforms in half. If not let me clue you in. In NI's absynth, you can put the simple sine wave bass in a sine wave waveshaper, and remove the bottom half of the sine wave, making the waveform sort of look like a question mark ?. You can take either the top half off, or the bottom half.

    Theoretically, if you could shift this half waveform 180 degrees forward, and invert it then sum it to the original, you would have a perfect sinewave, however, it would be composed of two of the exact same halves. This would lead to some crazy sounds. Who knows the possibilities are endless.

    Hopefully I'm being understood. I'm posting this in the hopes that someday some enterprising engineer comes up with a math equation that shifts waveforms forward in time however one where the time changes as frequency changes. This however is impossible to do. I've read something about dolby having done it, but I'm not so sure. I'm no audio pro. Just an enthusiast. Feel free to tell me your thoughts on the matter.
     
    Last edited: Mar 5, 2019
  2. Unobody

    Unobody New Member

    Messages:
    9
    [​IMG]
    here's an image of the cut waveform. If I could shift this 180 degrees, invert it and add it to the original, that would be neat. Simple time delay allows me to do this, but it wont stay as a coherent sine wave afterwards if I change the pitch.
     
  3. Unobody

    Unobody New Member

    Messages:
    9
    [​IMG]
    here's the thing I was talking about in the beginning. Purple is waveform 1, Black is waveform 2 (which is just waveform 1 shifted 90 degrees and inverted), Red is the sum, which is a triangle wave. All easily made out of basic sine waves. If you could easily turn a sine wave into a triangle wave, you could basically turn anything into anything else.
     
    Last edited: Mar 5, 2019
  4. Unobody

    Unobody New Member

    Messages:
    9
    Another bit of useless information. If you take a sawtooth and shift it 90 degrees, invert it and add it back to the original, you get a perfect square wave. Hopefully there's at least one other person out there who's been experimenting with this.


    I thought it was just as simple as taking sin(x) and turning it into cos(x).

    I also realized the reason why you can't use simple math to shift the waveform is because it is already a pre-existing wave.

    What I mean is, you can get sin(x), cos(x), and there's your shift. But this is a whole different story. Because with a preexisting wave, you're taking sin(sin(x)), or cos(cos(x)), or sin(cos(x)). Hopefully I'm making sense. The latter doesn't shift your wave, just shapes it.

    This is also key in fixing phasing issues in a track. Not only that but, Imagine what kind of stereo effect you could have if you can shift the waveform 90 degrees. First of all, when summed to mono, it would never cancel, secondly you could pan the original signal left and your shifted signal right, invert it, and create some beautiful effects.

    Anyway, try it out. Take a sine wave, delay it by a set amount of time, play it along with the original, and you'll see that it increases in volume, and decreases in volume. This is because they're out of sync. The whole point of my rant, is I which to keep them in sync. Hopefully I find someone out there, who has the key.
     
    Last edited: Mar 5, 2019
  5. Thala

    Thala NI Product Owner

    Messages:
    577
    pitch -> p2f -> 1/x = time in seconds.
    thats what you are looking for?

    please download goldcap from the user lib. have a look at the lfos.
    are them doing what you want?
     
    Last edited: Mar 5, 2019
  6. Philippe

    Philippe Well-Known Member

    Messages:
    1,553
    Did you have a look at VPS OSC (Vector Phase Shaping) in the Ul ? Might be close ?
     
    • Like Like x 1
  7. Unobody

    Unobody New Member

    Messages:
    9
    checked it out, but im looking for an ensemble that you can route audio through, and if one even exists that can do what I'm talking about
     
  8. fromwithin

    fromwithin New Member

    Messages:
    13
    I don't really see why you're trying to do it this way, nor why you'd want to use multiple oscillators to create a waveform for which a simpler oscillator already exists. In terms of waveform generation, sine waves are much more complex to generate digitally than sawtooth, square, and triangle waves. You're also going to have a problem with band-limiting. Unless your sawtooth wave is band-limited, the square wave that you create from combining sawtooths and the triangle from sines are not band-limited, so you'll get aliasing up towards the higher frequencies. Also, your triangle from sines is not quite a pure triangle waveform. You'd need to add higher frequency partials to get it closer to a pure triangle.

    But anyway, it sounds to me like you just need to use the Sine Sync oscillator, which has a Phase parameter. Just set that to -1 or +1 to get a 180 degree out-of-phase sine, or -0.5 or +0.5 for a cosine. The other oscillator Sync oscillators all have a phase parameter.

    If you do want to do it by delaying the signal instead, there's no reason why you can't just calculate the delay with the equation in the post above. It won't work very well though because if you delay by whatever you think is 90 degrees out of phase, you're only correctly changing the phase of the root frequency. The harmonics will have their phases affected to varying degrees depending on their frequency.

    The nature of the thing that you're asking for sounds exactly like me playing around a number of years ago when I thought of all audio as time-based waveforms and didn't understand the fundamental nature of the frequency content of waves.
     
    Last edited: Mar 5, 2019
    • Like Like x 2
  9. Thala

    Thala NI Product Owner

    Messages:
    577
    ´you are looking more for a waveshaper than an oscillator?
     
    • Like Like x 1
  10. colB

    colB NI Product Owner

    Messages:
    3,969
    Hmm.

    For specific example there are always better alternatives...
    So for your sinwave processing example, you could do what Thala suggests and use the frequency to calculate the delay...
    Or you could use a quadrature osc to get sine and cosine...
    Or you could hack the osc and at 0.25 to the phase accumulator...

    But none of these work with just an audio input.

    One thing you could look up is a bode shifter. It won't do exactly what you are asking, but you might find it interesting. It's a bit like a frequency shifter.
    What it will give you at the outputs are two waveforms with a consistent phase difference over some particular frequency range.
    Neither of them will look exactly like the input though ;)

    Also useful to note that if you mix together rectified sine waves, you'll get lots of aliasing - unless you do some much fancier processing and/or heaps of oversampling. So for something like a triangle, its much better to just build a triangle oscillator...
     
  11. Thala

    Thala NI Product Owner

    Messages:
    577
    can you create these formulas from that graphs by yourself?
    if yes, best will maybe take an Phase synced ramp osc and create your own oscillator.
    or pick a core saw wave osc incl AA and nest your formula inside there.

    this is how the phase is calculated in seconds and sample amount
    edit : new pic. it had a bug :p
    upload_2019-3-5_19-20-22.png
     

    Attached Files:

    Last edited: Mar 5, 2019
  12. colB

    colB NI Product Owner

    Messages:
    3,969
    Actually not bode shifter (that's a frequency shifter), it's related though (I think) but it's actually a Hilbert transform... or at least a phase shifter based on Hilbert transform...

    I built one ages ago - just guessed and tweaked the frequency values. Could be done much better with proper analysis.
    You'll find that it works not bad with sinusoids, but when you chuck a saw or some other wave through it with a wide frequency spectrum, it gets messy because there aren't enough all pass filters to cover that spectrum accurately enough...
    EDIT: actually I think it maybe gets messy because of the phase being shifted differently at different frequencies - the outputs will be quadrature and the frequency content the same (or at least similar), but the wave shape is changed. Which obviously doesn't affect sinusoids as they are only one frequency.
    Still works well for some applications though.

    EDIT: if you add a little code to this module and feed it with a sine you can get a reasonable approximation of a triangle:
    tri from sine.PNG
     

    Attached Files:

    Last edited: Mar 5, 2019
  13. sellotape

    sellotape NI Product Owner

    Messages:
    345
    Reminds me of the subtractor oscillator. Have a look in the ul it's included in a oscillator bundle the community made some time ago.
     
  14. salamanderanagram

    salamanderanagram NI Product Owner

    Messages:
    3,454
    this is called half-wave rectification, btw. you can achieve it easily enough using the BLAMP method.

    but this triangle wave will have pretty bad characteristics, namely a lot of extra aliasing.

    mmm, no offense, but this is an unsupported assertion. the processing required to turn one signal into another would vary greatly depending on the input and desired output. and why? it would almost certainly be easier just to create the desired output from scratch.

    and as an audio effect, i can't really see the benefit either. what is the intended effect here? to add more harmonics? use a waveshaper, they can also turn a naive sawtooth into any signal you want.

    hate to be a downer, but these relationships are well documented and explored already.
     
    Last edited: Mar 6, 2019
    • Informative Informative x 1
  15. salamanderanagram

    salamanderanagram NI Product Owner

    Messages:
    3,454
    to explain further why everybody is talking about aliasing - aliasing can be caused by discontinuities in a waveform, but it can also be caused by discontinuities within the derivative of that same waveform.

    with that in mind, i graphed out the triangle proposal, with an extra function, i(x), which denotes the derivative of the triangle wave:

    upload_2019-3-6_10-43-9.png

    now, every time there is a discontinuity within the derivative, you'll get aliasing.

    there is a well understood and commonly used method to avoid this problem, known as BLAMP, which is defined and explained in detail in this paper:

    http://dafx16.vutbr.cz/dafxpapers/18-DAFx-16_paper_33-PN.pdf

    but it is hardly practical to use in this instance.

    incidentally, you can also have problems with discontinuities within the second derivative, third derivative, and so on.

    so it's not just a matter of generating an equation that looks like the desired shape you want!
     
    • Like Like x 1
  16. hlmm

    hlmm NI Product Owner

    Messages:
    40
    I think the beauty here is that (apart of trigonometric functions) audio waveforms (technically speaking) does not have a "phase" other than 0 or 180 (which simply means inverted signal). So unless we decide what is 90 degrees by our own definition, we can not shift it by 90 degrees.

    We can however decide what is 360 – means to decide what is our sample length (I don't mean sample as smallest time unit in DSP processing but sample as in "samplers world" – MPC, Akai, Battery, etc) and than we go the "delay path" mentioned above or "phase modulation" path as in Rossum's Assimil8or for example.

    Another option would be to decompose our incoming waveform on sine partials (as every complex waveform is a mix of sine waves having different amplitudes and frequencies) and shift those individually by 90 degrees, though I suspect that would not make much perceptive change in the final sound and would cost lot of processing power. (Is it so that in analogue world transformers can do frequency related phase-shifting for us?)

    Third option and the most interesting is we just think about it for a while (for a while = sample length) and at some point it will connect with something else/unrelated. Human brain...
     
  17. colB

    colB NI Product Owner

    Messages:
    3,969
    You can also produce reduced aliasing rectification using Efflam Le Bivic's 'Infinite linear Oversampling' idea.
     
    • Informative Informative x 1
  18. colB

    colB NI Product Owner

    Messages:
    3,969
    That's what the Hilbert phase shifter I posted earlier does. It shifts each partial. The problem is that each partial has a different wavelength/period, so it is shifted by a different amount, the result is that after shifting, complex waveforms such as saw don't look like a saw any more, and while they have the same (?) frequency content, you can't sum them and get a square, coz they 'aint saws any more.
     
    Last edited: Mar 6, 2019
    • Informative Informative x 1
  19. Unobody

    Unobody New Member

    Messages:
    9
    The simple way about going about this is to take a simple sine wave form, turn it into a square wave that alternates between 0 and 1. Run that waveform reaktor's timer function, so that it calculates the time between the 1s, and use the value you get from the timer to introduce a time based delay to the original sine wave signal. The problem is that reaktor's timer doesn't accept audio input. Only data. So I'm at a loss.

    here's a reactor ensemble that does this with the clock osc.
    http://s000.tinyupload.com/index.php?file_id=23242753766774516692

    Basically, it takes a pulse wave, shifts it 90 degrees (or just about), inverts it and sums it back to the original.
     
    Last edited: Mar 7, 2019
  20. Thala

    Thala NI Product Owner

    Messages:
    577
    bummer...
    what is a timer and what should it help?

    pick a ramp and run it through your formula. done? beside that alias problem.