0
$\begingroup$

I am simulating mic input with a sine of 100 values that would, in q4_28 look like this (full period):

[0] 0.0627079,  0.1251678,  0.1871347,  0.2483625,  0.3086099
[5] 0.3676395,  0.4252185,  0.4811191,  0.5351209,  0.5870113
[10]    0.6365852,  0.6836462,  0.7280092,  0.7694988,  0.8079519
[15]    0.8432168,  0.8751535,  0.9036359,  0.9285526,  0.9498052
[20]    0.9673080,  0.9809942,  0.9908094,  0.9967136,  0.9986839
[25]    0.9967136,  0.9908094,  0.9809942,  0.9673080,  0.9498052
[30]    0.9285526,  0.9036359,  0.8751535,  0.8432168,  0.8079519
[35]    0.7694988,  0.7280092,  0.6836462,  0.6365852,  0.5870113
[40]    0.5351209,  0.4811191,  0.4252185,  0.3676395,  0.3086099
[45]    0.2483625,  0.1871347,  0.1251678,  0.0627079,  0.0000000 
[50]    -0.0627079, -0.1251678, -0.1871347, -0.2483625, -0.3086099
[55]    -0.3676395, -0.4252185, -0.4811191, -0.5351209, -0.5870113
[60]    -0.6365852, -0.6836462, -0.7280092, -0.7694988, -0.8079519
[65]    -0.8432168, -0.8751535, -0.9036359, -0.9285526, -0.9498052
[70]    -0.9673080, -0.9809942, -0.9908094, -0.9967136, -0.9986839
[75]    -0.9967136, -0.9908094, -0.9809942, -0.9673080, -0.9498052
[80]    -0.9285526, -0.9036359, -0.8751535, -0.8432168, -0.8079519
[85]    -0.7694988, -0.7280092, -0.6836462, -0.6365852, -0.5870113
[90]    -0.5351209, -0.4811191, -0.4252185, -0.3676395, -0.3086099
[95]    -0.2483625, -0.1871347, -0.1251678, -0.0627079, 0.0000000

On the scope (url below) you will see about 26 ms covering 4000 Hz from the FFT. It's done over I2C to a DAC, and it has to be finished by the next which is 32 ms. All this should basically work.

I play 320 Hz meaning that I use every other value of the sine. My problem seems to be independent of whether I take every at 160 Hz, every second at 320 Hz or every fourth at 640 Hz. Basic sampling rate is 16000 Hz and I do two double 32 ms spectra in 1024 samples over 64 ms, yielding 15.625 Hz / bin in the spectrum. 15.625 Hz/bin * 256 bin values = 4000 Hz.

I do have AGC on the FFT scope's output, so that there is no overflow in the DAC. I don't think the AGC changes gain between the two 3-secs intervals with different amplitude (1 and 1/16), since the 320 Hz pulse(s) seem(s) to be almost equal.

No clipping of the sine as used for input on the top, but the low volume will of course remove 4 LSB.

On the scope: (26 ms / 4000 Hz) * 320 = about 2 ms, which is where we see that peak. For low volume it looks ok, but (PROBLEM DEF:) for high volume I see so many extra peaks.

Any idea why this could be so?

Equal movie clips. This is a private hobby project, please bare over with the so-and-so quality of this movie:

26 ms spectrum is 4000 Hz (mp4)

26 ms spectrum is 4000 Hz (mov)

$\endgroup$
11
  • 1
    $\begingroup$ so what is the reconstruction filter you attached to your DAC? And, since you have a sufficiently fast scope: how much does your sine actually look like a sine? $\endgroup$ Jan 9 at 20:40
  • $\begingroup$ @MariusMuller. The sine is ok. link. However, it may have to do with my internal AGC, of the analog samples before the FFT. A 320 Hz takes 3.125 ms and I do new AGC values potentially every 32 ms, getting me 10.24 periods - enough for one FFT spectrum. I may come back with this in another thread. If so I will link it up here. $\endgroup$ Jan 11 at 12:35
  • $\begingroup$ interesting! Can you do a single-shot measurement and zoom in on one of the maxima of the curve. There's both good reason to assume there's high-frequency content, and to assume that the frequency plot of your oscilloscope is kind of not very good, mathematically (even the most expensive scope manufacturers are really bad at describing what math they actually do, and try to treat what they calculate as FFT as if it was the same you get with a scanning spectrum analyzer, which very often goes wrong in hilarious ways, and all it would take to sort out would be printing on screen… $\endgroup$ Jan 11 at 13:15
  • $\begingroup$ … what that magic "FFT" mode actually calculates and shows. As you say, you get 10.42 periods, and that should be enough for an FFT-based estimate. Agreed! But for that you would need to parameterize your FFT to actually not be the average of more than these, or less than 1, period. Does the scope allow you to set the FFT length, in samples?) $\endgroup$ Jan 11 at 13:16
  • 1
    $\begingroup$ Just a short response for now. I do not use the built-in FFT function in the scope. It's my own DSP handling with FFT from lib_dsp from XMOS. The spectrum you see on the scope is my own output, over I2C to a DAC4 click from MikroE. The headset output of the sine is to a Pimoroni Pico Audio Pack (Line-Out and Headphone Amp) PIM544 with a Texas Instruments PCM5100. I also do that PDM output myself (in addition the the mic input) $\endgroup$ Jan 11 at 13:34

1 Answer 1

0
$\begingroup$

This definitively was a problem with my scaling! Before the AGC I had added a pre-downscale which caused a need for up or downscale in the AGC which then got wrong, because I hadn't done the upscale in the AGC! Dropping the initial downscale fixed the problem. I discovered this for the sine because it didn't fill the range of the mic samples.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.