Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Teensy 4.1 MQS has harmonics which alias down to audible frequencies

  1. #1

    Teensy 4.1 MQS has harmonics which alias down to audible frequencies

    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 ( only code line I changed was lowered the top frequency from 22000 to 20000) and used the following schematic:

    Click image for larger version. 

Name:	MQS-simple-blocking-cap-into-lowpass-filter.PNG 
Views:	18 
Size:	15.9 KB 
ID:	29683

    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:

    Click image for larger version. 

Name:	Teensy41-MQS-freq-sweep-test-20-to-20kHz-LR.jpg 
Views:	19 
Size:	79.5 KB 
ID:	29684

    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:

    Click image for larger version. 

Name:	zommed-in-first-five-kHz.jpg 
Views:	16 
Size:	97.3 KB 
ID:	29685

    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:

    Click image for larger version. 

Name:	zoomed-in-raising-full-rasing-rnage-from-20Hz-to-20kHz_shows-aliasing_annotated.jpg 
Views:	16 
Size:	119.1 KB 
ID:	29686

    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.

  2. #2
    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.

  3. #3
    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):

    Click image for larger version. 

Name:	filtered-sine-sweep-little-aliasing.jpg 
Views:	16 
Size:	56.3 KB 
ID:	29693

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts