Teensy 4.1 MQS has harmonics which alias down to audible frequencies

ericfont

Well-known member
This is just an observation, not a complaint, because "MQS" does stand for "Medium Quality Sound", but thought I would share. I was trying the tone sweep example from the wiki (https://github.com/TeensyUser/doc/wiki/Audio-Example-using-MQS-on-Teensy-4.0-or-4.1 only code line I changed was lowered the top frequency from 22000 to 20000) and used the following schematic:

MQS-simple-blocking-cap-into-lowpass-filter.PNG

which is basically a large DC-blocking capacitor on each MQS pin output followed by a RC-lowpass filter with R=130Ω and C=68nF for a -3dB cutoff frequency of 18 kHz. I first listened to the output of the sweep, but after the sine output got into the high >10 kHz frequencies, I could start to hear a sine wave falling down, even though the frequency sweep test was still in the rising part of the test. To make sure my ears weren't fooling me or that someone was wrong with my headphones, I sent each MQS output into my audio interface and recorded at 192kHz sampling rate and looked at the spectrogram in Audacity:

Teensy41-MQS-freq-sweep-test-20-to-20kHz-LR.jpg

And sure enough I can see multiple harmonics of the sine wave output in the spectrogram, which appear as less-bright diagonal lines with steeper slope. Zooming in closely at when the sweep test goes from 20Hz to 5kHz, I am able to see 5 distinct harmonics above the fundamental, with the 1st harmonic most prominent, then the 2nd harmonic, then the 4th harmonic, and then only very faint 3rd and 5th harmonic:

zommed-in-first-five-kHz.jpg

Zooming in on the part of the sweep when the sine wave goes from 20Hz to 20 kHz, I can notice that those higher harmonics are aliased back down into audible frequency range:

zoomed-in-raising-full-rasing-rnage-from-20Hz-to-20kHz_shows-aliasing_annotated.jpg

I believe what I was that one the fundamental rose past 14 kHz, my ears could no longer hear the high-pitched fundamental very well, but the 3rd-harmonic was falling and aliased down into the audible frequency range, and so I was hearing that alias instead of the fundamental.

Maybe tweaking some of the MQS options like clock rate or oversampling ratio helps. Or another thing I'm thinking is to maybe just run any audio into a digital lowpass filter before going to the MQS output, maybe with a cutoff around 10 KHz that slowly rolls off, that way any higher frequencies are attenuated somewhat and so they won't produce as strong aliased versions in the lower audible frequencies. Of course it is "medium quality sound". Maybe someone else has some ideas about addressing this.
 
MQS is essentially noise-shaped PWM/PDM output so you should not expect much. NXP docs specifically say that over 10kHz you are going to get bad THD+N.
 
Good point.

I've found that putting a digital lowpass filter (for instance using biquad filter consisting of 4-stages of lowpass corner freq of 10 kHz) before the MQS output will softly roll-off the highs while drastically reducing the aliasing to the point that I can't hear the aliased signals (of course I loose some of the high end but I don't necessarily need a lot of high end):

filtered-sine-sweep-little-aliasing.jpg

Alternatively one could just avoid outputting signals with significant high frequencies about 10 kHz.
 
Back
Top