absdiff inside gen~

Stuart Anderson's icon

Hi folks,

If I create a patch using absdiff and don't connect anything to one side of the object I get pitch doubling, is this the expected behaviour, my lack of understanding of the object or a bug?

Thanks
S.

Holland Hopson's icon

Yes. You've created a full-wave rectifier which doubles the frequency. https://electronics.stackexchange.com/questions/86447/frequency-of-output-of-full-wave-rectifier

Graham Wakefield's icon

Exactly. The 2nd inlet of absdiff is not connected, so it uses its default value (for absdiff this default is 0). So you are measuring the difference of your input from zero, and then taking the absolute value (throwing away the sign). This is the same as just doing [abs].

With a bipolar cosine input (cycle~), this will turn the negative sides of the sine into positive, producing a waveform that looks like the arches under a bridge. By mirroring the negative wave into the positive, this has effectively made the waveform periodic at half the duration (twice the frequency) of the original cosine wave. Have a look at it in a scope~ (toggle @automatic 1/0 for different views).

Change the 2nd input of absdiff to something between 0 and 1 and you'll get an interesting mix between the full-wave rectified and the original wave, a bit like wavefolding; but you might need a dcblock or something better on the output to keep it in reasonable ranges.