• ### How much is a signal aliasing?

Is there any way to measure or estimate how much an arbitrary signal is aliasing in PD? I'm thinking it might go something like [1] generate the signal at 16X oversampling, [2] perform an FFT, [3] figure out which bins are above the original 44.1khz Nyquist limit and add up all their...um...powers? amplitudes?...then [4] express that as a percentage of the total power/amplitude?

I'd also be interested to know if this question is complete nonsense!

• Posts 10 | Views 2724
• seems like you could estimate by generating using 16x upsampling and then using a sharpish highpass filter at nyquist?

• @seb-harmonik.ar, thanks, I'll take that as evidence that my oversampling idea isn't completely bonkers . Then how would you measure the strength of the remaining signal, and how does that strength relate to the strength of the frequencies that would be reflected back into the audio spectrum?

• I guess you could use whatever time-domain rms or peak amplitude measurement you would use normally and compare both signals. then just divide the higher-than-nyquist volume by the total volume to see what ratio is going to be aliased.

for example if the volume of the would-be aliased part is 1 and the volume of the total signal is 2 then you know that 1/2 of the signal will be aliased

one thing to consider when using a highpass vs. using an fft is that the sine-wave components will have their phases changed by the filter, so the amplitude might not be reflective of the actual amplitude of the aliased signal (so maybe rms is better since it uses averages, so the phases won't matter as much I think).

if you want to measure using amplitude I guess it might be best to sum the FFT magnitudes of each bin and/or use some kind of spectral/FIR brickwall to separate the 2.. but rms might be a better measurement anyways

honestly idk that much about it & am just guessing maybe someone better at dsp will chime in..

• Did you come up with something?

qalias~.pd
quantify_aliasing_3c.pd
ups~.pd
(EDIT: all three UPDATED again and again now!)

Uses Bessel-filters from IEMlib.

As quick test bed:
Copy/paste or write your own object-chain in qalias~' arguments,
Thx to @svanya !

What do you think?
How to implement the FFT-filter?
How to improve?

To my surprise [osc~] starts to alias above 3400 Hz and [cyclone/wave~] is even worse!
I convinced myself that I can even hear it.

Do you know how to make a less distorted sine @ 44100 ?

• @lacuna Thanks, that's really interesting. I don't think I solved this using FFTs because I didn't understand how to add the bins to get a meaningful measure of signal strength (among many other things). Looking over the code I wrote I can see it's gonna take a while before I understand what I was trying to do, but in the meantime maybe we can discuss your test and possibly poke holes in my original assumptions.

In my limited experience the filters in Pd do strange things when set to frequencies outside of the musical pitch range, so I would wonder if lp10_bess~ works properly at Nyquist. But I really don't know either way. And what does it mean to low pass filter a signal at Nyquist, since the filter itself is subject to the Nyquist limit? Or maybe you have other reasons to do so?

I'm still not convinced that comparing a signal with its upsampled version is meaningful. How do we know that the upper harmonics in the upsampled version are present and aliasing at the normal sample rate? My understanding is that upsampling just gives us more frequency headroom in which to filter out frequencies above Nyquist. But for measurement I wonder whether we should be instead passing the normal signal to an upsampled subpatch and then measuring how much energy is above 22050. Then again, that signal would look like a stepped signal in the upsampled environment, and that seems like it would have a lot of additional high frequency energy, so maybe that's a terrible idea.

I'm obviously more confused now than when I originally asked the question.

That said, I can't believe that there is an audible aliasing problem with plain sine waves. If you want I'd be happy to write you a double-blind listening test based on the Lady Tasting Tea experiment. Let me know and we'll work out what it should contain.

But assuming your method is valid, maybe you should try fft-split~ from Audiolab instead of the IEM filters. If I can understand my old code then maybe I'll have something more constructive to contribute later.

• @lacuna Ha ha, it turns out I did "solve" it using FFTs, but I had to study my year-old code for a while to see it. You can see in this snapshot that I'm measuring a lot less upper harmonic energy in oversampled sinewaves than you are, and I'm wording it that way (and putting "solve" in quotes) because I'm not convinced that this is a useful measure of aliasing at the normal sample rate. I also can't say that I understand my results for noise and for the impulse function--I thought the latter would have even more energy above Nyquist. I have another idea to try, but I have a plumbing issue to address first I'm still interested in your thoughts though.
measure aliasing (static vector).pd

• thank you, will study this, could you please add the missing

clone oddHarmonic~ 25
... couldn't create

@jameslo said:

what does it mean to low pass filter a signal at Nyquist, since the filter itself is subject to the Nyquist limit? Or maybe you have other reasons to do so?

Yes, that was wrong, I made many mistakes in that patch.

I'm still not convinced that comparing a signal with its upsampled version is meaningful. How do we know that the upper harmonics in the upsampled version are present and aliasing at the normal sample rate?

I see your point and I am not sure.
If this is the case, that whole concept would plop.

for measurement I wonder whether we should be instead passing the normal signal to an upsampled subpatch and then measuring how much energy is above 22050. Then again, that signal would look like a stepped signal in the upsampled environment, and that seems like it would have a lot of additional high frequency energy

No, I don't think so, as niquist reflects before upsampling. Even when using some upsampling filter, as in [inlet~]'s help, you can't un-alias an aliasing signal by upsampling !?

maybe you should try fft-split~

Yes, I was thinking about some steep FFT-filter,
https://forum.pdpatchrepo.info/topic/12245/perfect-filter-square-shape-filter
but don't know how to tweak it for different sample rates and with fairly precise cuttoff frequency, yet.

Bessel was not a good idea, high order Butterwoth is stronger, and everything needs to get calibrated, because the filter-slopes are messing with the result.

• @lacuna Oh yeah, sorry, here it is: oddHarmonic~.pd . It's not so important I think--I was just verifying that an additive synth approximation of a square wave was "alias-free" by this measure.

No, I don't think so, as niquist reflects before upsampling. Even when using some upsampling filter, as in [inlet~]'s help, you can't un-alias an aliasing signal by upsampling !?

Agreed. I would probably appear to be smarter if I didn't speculate in public

but don't know how to tweak it for different sample rates and with fairly precise cuttoff frequency, yet.

I'll look at Audiolab's fft-split~ tomorrow and try to incorporate it into your patch. The thing is you're filtering at a bucket boundary in the upsampled domain, so that seems perfect for its brand of FFT bucket moses.

• @lacuna I replaced those IEM filters in [ups~] with [pp.fft-split~] and I'm getting more stable results for sine waves. ups~.pd That said, I don't really understand the arithmetic you are performing in the lower left corner of the main patch. Can you please explain?

Here's another approach that doesn't depend on knowing how the upper harmonic strengths in the upsampled version relate to the aliasing in the normal version. Using both fft-split~ as well as the 3 pole 3 zero Butterworth filter shown in J07.oversampling, measure how much signal has been removed. That should be close to the amount of aliasing that has been removed provided the frequency and rolloff of the filters are appropriate. I'm more confident in this measurement because it uses an established anti-aliasing technique and performs the measurement in the non-upsampled environment. What do you think?
measure alias filtering.pd

Posts 10 | Views 2724
Internal error.

Oops! Looks like something went wrong!