Ring modulation: no difference with and without oversampling ?

Roald Baudoux's icon

I have built this patcher in order to check the possible influence of oversampling to prevent aliasing in ring modulation. One can test the difference between a ring modulation between two sawtooth oscillators occurring at either regular sampling rate, with 4x oversampling, or with 32x oversampling. Besides a tiny difference of amplitude I can't hear any spectral difference between the three sounds, even when both oscillators are set to high frequencies. Any idea why?

Max Patch
Copy patch and select New From Clipboard in Max.

Save this as the main patcher:

Max Patch
Copy patch and select New From Clipboard in Max.

Save the code below as "poly_ringMod.maxpat" and put it in the same folder as the main patcher.

Christopher Dobrian's icon

I'm going to hazard a guess that you're listening through a DAC that operates at a standard rate such as 44,100 or 48,000, thus downsampling your upsampling.

Roald Baudoux's icon

Of course there is downsampling, but this is precisely because this downsampling is not performed the same way in each case (after an antialiasing filter in the case of the poly~ and without antialiasing filter in the case of the regular version) that one should hear a difference. So I don't pretend one should hear higher frequencies when listening to either poly~'s output but one should hear more aliased frequencies when listening to the regular (non oversampled) modulation.

Anyway the base sampling rate doesn't change anything to the principle of the comparison: even at 192 kHz, the sampling rate would be higher inside the poly~ than outside but still their output would go through an anti-aliasing filter before before the reduction of their sampling rate. So the benefits of the oversampling lies in the reduction of aliasing and if I am correct a difference should be audible whatever the patcher's basic (not oversampled) sampling rate.

Peter McCulloch's icon

In ring modulation, you're creating sum and difference tones between the two sources; when both sources are complex, the number of tones produced grows factorially. The spectral density may be making it hard to hear any differences. I'd recommend using a sine wave for one of the oscillators to test the oversampling.

Roald Baudoux's icon

I really can't believe there's no audible difference with two sawtooth oscillators.

Ernest's icon

Coincidentally I was thinking about this issue a few hours ago, and here is what I have been told about it before. When you're doing frequency modulation, the modulator is changing the pitch of the carrier, so if the modulator contains BLEPs or the such for antialiasing, the anti-aliasing creates additional frequency components in the carrier which are different from those which the modulator output was meant to make, so there can be noticeable harmonic distortion. For this reason in my Godel design, I did not originally use anti-aliased oscillators, because I intend to be expanding it for 4=6 FM oscillators in the next year.

Ring modulation, also known as amplitude modulation, multiplies the output of two audio signals together, but does not change the frequency of the original oscillators. As Peter states, this creates additional harmonics from the two source waves (from the sum and difference of their frequencies). So it is natural to think the additional frequencies add aliasing.

On the other hand, ring modulation is actually just adjusting the amplitude of the source signals. If the source signals are anti-aliased, there's no reason to think amplitude adjustment actually should create aliasing. To follow this contrary thought, one can consider whether EQ filters add aliasing to an anti-aliased oscillator. EQ filters also adjust the amplitude of different frequency components of the source signal.

About a decade ago, I thought maybe I could remove aliasing by oversampling both the oscillators and subsequent filters, then downsampling the output after filtering. But someone with more experience told me, no that doesn't work because the aliased components are already in the oscillator signals before they enter the filter, and the filter could emphasize them, or de=emphasize them, but the aliasing is already in there, and even if you could design a downsampler to remove the frequency components from the original oscillators, there could be additional distortion made by the aliasing inside the filter. So the oscillator signals have to be anti-aliased before they enter the filter. Now maybe the same is true for ring modulation, and if the source waves are antialiased, the harmonic changes from ring modulation don't actually add aliased frequencies. But whatever the case, only one of the signals which you're testing with could be a sine wave, because sine waves shouldn't have any harmonics, hence, if you are safely below Nyquist, there won't be any significant aliasing to produce audible distortion; and if the sine frequency is close enough to Nyquist to produce audible distortion then you ring-modulate it, obviously the sidebands from the ring modulator will be well above Nyquist, and it won't matter how much aliasing you start with or not, it will sound awful anyway.

Peter McCulloch's icon

There's some audible difference, but it's pretty subtle and it often occurs high in the spectrum. (See the plots in the attached patch) These types of effects will also by affected by the frequencies of the oscillators as well as the sampling rate. (much in the way that a phasor~ at 441 or 100 Hz will appear not to alias at a sampling rate of 44100)

There shouldn't be much (if any?) of a difference between 4x and 32x because the highest possible frequencies that ring mod could produce would be Nyquist*2.

Max Patch
Copy patch and select New From Clipboard in Max.

You might try a similar thing with frequency modulation, since it produces considerably more overtones.

stkr's icon

yeah ring mod with non-sines is a bummer. good luck!

as peter says it is the discontinuities etc. i have not solved it.

with sines though it is super easy with some attenuation and filtering, and then upsampling makes a huge difference, always a must for fm type oscs.

maybe the attached can help.

stkrSinOscRingMod.zip
zip
Peter McCulloch's icon

@Ernest: Ring modulation and amplitude modulation are actually different processes, though they look similar in implementation.

Ring modulation is (in the simplest digital implementation) the multiplication of two bipolar audio rate signals. In the resulting signal, the sum and difference tones are present, but neither of the two input signals appear unaltered. (so for every frequency present in A and B, you will get A+B and A-B, but not A or B)

Amplitude modulation is the multiplication of a bipolar by a unipolar wave. The signal from the bipolar wave will be present in the output in addition to the sum and difference tones. (e.g., A+B, A-B, A) You can crossfade between ring mod and amplitude mod simply by changing the offset in the attached example.

In both cases, the output will not be harmonic unless there is an underlying harmonic relationship between the two oscillators. For example, sine wave oscillators at 100 and 400 Hz will produce 300 and 500 Hz as sum and difference tones which are harmonically related to 100 Hz. This type of modulation effect can be used to create formant type effects as occurs in the PAF and FOF oscillators. Same thing goes for voice, etc.--if you know the fundamental frequency, you can create formant shifts provided that the carrier frequency is above the modulator and in a harmonic relationship with it.

Regarding anti-aliasing, if you upsample the entire signal chain before downsampling (e.g. aliased oscillator into filter inside of poly~) there will be a reduction in aliasing because the aliasing is produced based on the sampling rate of the signal chain (so higher rate = higher ceiling for aliased frequencies). Depending on the oscillator, it may or may not be a significant reduction, however. Sawtooth wave harmonics continue for a long ways, so you have to do an absurd amount of upsampling to see improvement, and by that point, there are more efficient algorithms that could be used instead.

Concerning FM and distortion: my guess is that this is true for saw~,tri~, and rect~ because I think they are BLIT-based, though I notice that this distortion is only present when changing the frequency (when using them as a modulator); when the frequency is stable (i.e. used as a modulation source), its performance is much better than that of the aliased version of the oscillator, and this can be seen in an upsampled patch.

Max Patch
Copy patch and select New From Clipboard in Max.

Why this may be: when you look at the waveform for one of these oscillators being modulated, you'll see that the overall baseline of the wave wiggles quite a bit (compare tri~ to phasor~ -> triangle~ 0.5). Because these designs use an integrator, there is some inherent latency that could occur with fast frequency shifts. It's generating a band-limited impulse, then integrating that over the course of the entire cycle of the waveform, IIRC, so that means that the frequency won't be updated on a sample by sample basis throughout the entire cycle, and that will have a definite impact both as a modulator or as a carrier. I'd encourage you to try it out with some of the other anti-aliased designs you've been experimenting with (if you haven't already) as they may be more amenable to FM.

Ernest's icon

Peter, thanks again, although call me old school I guess, but when I think of AM, I think of radio broadcasting, and radio does use bipolar modulation. These days when people think of radio they probably think it should be called XM or or something, but to me that's just branding by Sirius because it doesnt really stand for anything at all, and maybe Americans object to me thinking that--better to be a cowboy than a layman--but to me, modulation of amplitude and 'AM' may refer to different things technically in the audio world, but I'm just a layman. So please excuse me, and I'd like to follow up on your shares some more, but after at least several hundred Max crashes in the last few weeks (many from changing gen~ inlets, which still doesnt work in Max 7), I feel more jaded than I should and need to take a little break for a while.

Roald Baudoux's icon

Thanks for your answers everyone.

@Peter: I realize you're right about the upper limit in the frequency range which can be produced by ring modulation (Nyquist x 2 = the sampling rate precisely). Also, the plot~ from your patcher indeed shows clearly that there is more aliasing in the non-upsampled version. However I think that the sonic difference is not meaningful.

@Ernest: I don't think that because two signals are alias-free the outcome of their multiplication is also alias-free (as shown by Peter's plotting if I understand it the right way...)

Peter McCulloch's icon

@Roald: That's correct. The sum tone of two 19kHz waves, for example, will be 38 kHz.

Christopher Dobrian's icon
Max Patch
Copy patch and select New From Clipboard in Max.

This example shows how upsampling can avoid some aliasing, and it demonstrates that poly~ does indeed implement antialiasing filtering when it sends its output back into the un-upsampled MSP world. In the example, the ring modulation produces sidebands at 1000 Hz and 41,100 Hz. In the non-poly~ version the 41,100 Hz tone is folded over to appear as a 3,000 Hz tone. In the upsampled poly~ version, it's not aliased inside the poly~, and it gets filtered out before the signal is sent back out into the un-upsampled portion of the patch. [Save the attached file for use in poly~.]

unaliased.maxpat
Max Patch
oli larkin's icon

not exactly on-topic, but here is a ring modulator based on a paper by julian parker:

jpringmod.zip
zip
brendan mccloskey's icon

Hey
Oli's back, with a new avatar too.

Should I be opening this in the shiny new Max7; I'm really keen to see its innards, but opening this in 6 has caused several repeated crashes, despite advising Max where the .js stuff lives.

Brendan

its_all_olis_fault.png
png
oli larkin's icon

sorry should have said max7 only because i used the nice new feature of JS to write direct to a buffer!

brendan mccloskey's icon

yeah, sorted thanks mate:

EX-TER-MIN-ATE.png
png
brendan mccloskey's icon

ps:

booHoo.png
png
Roald Baudoux's icon

Thanks for this adaptation to Max, Oli!

I suppose one could adapt the patcher to Max 6 by outputting the table values one by one from the .js and writing them to the buffer~ using good' ol' peek~.

Ernest's icon

well, I thought some more about this while recovering from gen~ crashes and rude people at KVR, and maybe the downsampling from poly~ is part of the reason the results are not as expected. Here is a screenshot showing the results simply changing the clock from 44.1 to 88.2khz for aliased (red) and antialiased (blue saws with a cycle, based on Peter.s design, and there is definitely a significant improvement with the higher clock rate.

ringmod.png
png