Distortion of an analytic signal - has this been tried?

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

A thought occurred to me, what if you applied a typical distortion algorithm to the magnitude of a sound's analytic signal?

Instead of just
sound → apply distortion → distorted sound
we'd do
sound → make analytic signal → apply distortion to the magnitude → keep real part

If we applied that to a pure tone multiplied by an envelope it would be the same as modifying the envelope so it wouldn't sound like distortion and more like compression, but if harmonics are present or more I have no idea what it would sound like. Has this been tried and if so what does it sound like?
Developer of Photosounder (a spectral editor/synth), SplineEQ and Spiral

Post

Real signal distortion is also just infinitely fast compression. Same goes for the envelope of an analytic signal. So the result probably won't be much different. Try it out!

Post

If the original signal is x(t), and the complex signal you make up is x(t)+j*y(t), and "applying distortion to the magnitude" is multiplication by a time varying gain a(t), the final result is a(t)*x(t) (after discarding j*a(t)*y(t)) and y makes no difference: a(t) only depends on x(t). A complex signal can still be a useful implicit tool to compute the gain in a principled way.

Post

G-Spot wrote: Thu Mar 21, 2024 9:56 am If the original signal is x(t), and the complex signal you make up is x(t)+j*y(t), and "applying distortion to the magnitude" is multiplication by a time varying gain a(t), the final result is a(t)*x(t) (after discarding j*a(t)*y(t)) and y makes no difference: a(t) only depends on x(t). A complex signal can still be a useful implicit tool to compute the gain in a principled way.
But that's wrong, a(t) would be a function of sqrt(x(t)^2+y(t)^2).
Developer of Photosounder (a spectral editor/synth), SplineEQ and Spiral

Post

I just tried it on a sawtooth by Fourier series with a erf() magnitude distortion and it looks like it softens the waveform. Green is the original, orange is the result.

Image
Developer of Photosounder (a spectral editor/synth), SplineEQ and Spiral

Post

Whaddabout a sine??
We are the KVR collective. Resistance is futile. You will be assimilated. Image
My MusicCalc is served over https!!

Post

BertKoor wrote: Thu Mar 21, 2024 10:41 pm Whaddabout a sine??
I mentioned this in the OP, a sine would stay a sine, a sine modulated by an envelope would seem like only its envelope was changed (flattened) but it would still oscillate like a sine so there would be no added harmonics. It fact I'm starting to think that if anything this process should tend to suppress harmonics.
Developer of Photosounder (a spectral editor/synth), SplineEQ and Spiral

Post

A_SN wrote: Thu Mar 21, 2024 10:37 pm I just tried it on a sawtooth by Fourier series with a erf() magnitude distortion and it looks like it softens the waveform. Green is the original, orange is the result.

Image
Plot the Hilbert transform and it'll be obvious why this happens. In fact the Hilbert transform at the discontinuity of a perfect saw (or square) is infinite (if we take saw as the limit to the series sin(2*pi*x*n)/n, then Hilbert transform would be cos(2*pi*x*n)/n, at x=0 we have cos(0)=1 and the sum 1/n diverges). Ofcourse with a band-limited signal the "discontinuity" isn't a true discontinuity, so the Hilbert transform is finite, but it can still spike pretty bad.

Post

A_SN wrote: Thu Mar 21, 2024 10:46 pm It fact I'm starting to think that if anything this process should tend to suppress harmonics.
It does not. I've run some quick experiments with input consisting of first 5 harmonics of saw wave, and it will produce a lot of additional harmonics, but at lower levels compared to distorting in classical manner.
In essence, when you distort magnitude, output asymptotically approaches x(t)/magnitude(t). Even when magnitude is fully squashed, x(t)/magnitude(t) resembles x(t) much more closely than just squashing x(t).
I have tried another thing and it also looks promising, low pass filtering instead of distorting magnitude wave. It still produces additional harmonics, but with low/no impact on dynamics, and of course it will result in same amount of additional harmonics regardless of input level.
I hope I'll have time on weekend to check how it sounds, but based on analysis it should be interesting.

Post

Sounds interesting and fun to play with. How do you guys compute the Hilbert transform in first place? Do you use a FIR filter? Or do you do it in the frequency domain? I guess, the frequency domain approach (DFT -> do stuff* -> IDFT) is the best approach for periodic waveforms? And for arbitrary signals, the FIR filter? I currently have no proper Hilbert filter in my DSP library but I may kinda feel inclined to write one just to try out this idea and also have a new toy to play with.

* where "do stuff" might be: zero out the negative frequencies, double the positives?
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

Music Engineer wrote: Fri Mar 22, 2024 5:52 am Sounds interesting and fun to play with. How do you guys compute the Hilbert transform in first place? Do you use a FIR filter? Or do you do it in the frequency domain? I guess, the frequency domain approach (DFT -> do stuff* -> IDFT) is the best approach for periodic waveforms? And for arbitrary signals, the FIR filter? I currently have no proper Hilbert filter in my DSP library but I may kinda feel inclined to write one just to try out this idea and also have a new toy to play with.

* where "do stuff" might be: zero out the negative frequencies, double the positives?
All these approaches work, in practice to do a Hilbert transform on an entire sound at once I do an FFT (after some zero-padding), simply swap the real and imaginary values (I usually do this to get envelopes so I don't care about the signs) and the inverse FFT gives me the imaginary part.

To do it in real time I'd generate a kernel in the time domain using (1 - cos(t*pi))/(t*pi) with a window function applied to it (specifically my own approach for a short Gaussian window), and if delay matters I might do something which I've been thinking about lately which would be a fade in with something like 0.5+0.5*erf(k*t-offset) (but shortened at the start kind of like my short Gaussian window).
Developer of Photosounder (a spectral editor/synth), SplineEQ and Spiral

Post

OK - thanks. I think, I'll try the FIR approach because I'm also interested in realtime operation. A nice library you have there! Thanks for making it available!
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

A_SN wrote: Fri Mar 22, 2024 6:36 am simply swap the real and imaginary values (I usually do this to get envelopes so I don't care about the signs) and the inverse FFT gives me the imaginary part.
I guess the proper way (with correct signs) to do it would be to negate the real part after swapping? The idea seems to be to do a 90° rotation in the complex plane and a vector (x,y) rotated by 90° gives (-y,x).
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

A_SN wrote: Thu Mar 21, 2024 9:59 am
G-Spot wrote: Thu Mar 21, 2024 9:56 am If the original signal is x(t), and the complex signal you make up is x(t)+j*y(t), and "applying distortion to the magnitude" is multiplication by a time varying gain a(t), the final result is a(t)*x(t) (after discarding j*a(t)*y(t)) and y makes no difference: a(t) only depends on x(t). A complex signal can still be a useful implicit tool to compute the gain in a principled way.
But that's wrong, a(t) would be a function of sqrt(x(t)^2+y(t)^2).
Since the imaginary component y has been made up with a Hilbert transform, it depends on x and doesn't contain any additional information, so your gain a actually depends on x only.
You should probably try actual complex signals (for example, upgrading a synth to nontrivial quadrature oscillators), using Hilbert transforms of real signals as a fallback for mono inputs and/or as a test case.

Post

G-Spot wrote: Fri Mar 22, 2024 10:10 am
A_SN wrote: Thu Mar 21, 2024 9:59 am But that's wrong, a(t) would be a function of sqrt(x(t)^2+y(t)^2).
Since the imaginary component y has been made up with a Hilbert transform, it depends on x and doesn't contain any additional information, so your gain a actually depends on x only.
You should probably try actual complex signals (for example, upgrading a synth to nontrivial quadrature oscillators), using Hilbert transforms of real signals as a fallback for mono inputs and/or as a test case.
I see what you mean, but I can't help but feel that this is missing the point of pondering the topic of magnitude distortion of an analytic signal, which is that even if the output derives entirely from the input real-valued signal it's quite different from normal distortion and has different properties which presumably result in a different audio effect and this is probably worth investigating if this hasn't already been done. Applying distortion to the radius of a spinning signal is very much the idea, in fact I'd wager that applying that to complex signals that aren't analytic signals but that wiggle every which way in the complex plane instead of just spinning in one direction would be more similar to regular distortion and give a less novel effect.

The aspect about applying this specifically to analytic signals and that made me think it could be interesting is specifically that the real output would be just as affected around zero as it would be around the extrema which would make sinusoids remain sinusoids, whereas with regular distortion values around zero remain unchanged and sinusoids stop being sinusoids, they get flat tops and sharp corners. It's an effect that instead of flattening all the peaks would tend to make signals more wavy. I think that a non-analytic complex signal might fall between the two (kind of flat-topped with sharp corners, kind of wavy), so doing this on analytic signals is the more novel and pure effect.
Last edited by A_SN on Fri Mar 22, 2024 12:46 pm, edited 2 times in total.
Developer of Photosounder (a spectral editor/synth), SplineEQ and Spiral

Post Reply

Return to “DSP and Plugin Development”