craiglindley
Well-known member
With the help of others on this forum I got my response plotting code to work but I'm having a hard time justifying what I am seeing. I've included the code and the response data below.

Basically I have two cascaded low pass filter section set at 1000Hz each connected to a peak detector so I can see the filtered output. A sine wave generator is being swept from 40 Hz to 20000Hz and is driving the filter network. If you look at the response data you will see that the cascaded filters are already over 12 db down at 1000Hz and 54 db down an octave out. I would expect the roll off to be approximately 24 db/octave but I'm getting 42 db/octave instead.
What am I missing ?
Response Data

Basically I have two cascaded low pass filter section set at 1000Hz each connected to a peak detector so I can see the filtered output. A sine wave generator is being swept from 40 Hz to 20000Hz and is driving the filter network. If you look at the response data you will see that the cascaded filters are already over 12 db down at 1000Hz and 54 db down an octave out. I would expect the roll off to be approximately 24 db/octave but I'm getting 42 db/octave instead.
What am I missing ?
Code:
// Attempt to plot response of low pass filter
#include <Audio.h>
// GUItool: begin automatically generated code
AudioSynthWaveformSine sine1; //xy=108,161
AudioFilterStateVariable filter1; //xy=298,164
AudioFilterStateVariable filter2; //xy=469,168
AudioOutputI2S i2s1; //xy=681,61
AudioAnalyzePeak peak1; //xy=687,168
AudioConnection patchCord1(sine1, 0, filter1, 0);
AudioConnection patchCord2(filter1, 0, filter2, 0);
AudioConnection patchCord3(filter2, 0, peak1, 0);
AudioConnection patchCord4(filter2, 0, i2s1, 0);
AudioConnection patchCord5(filter2, 0, i2s1, 1);
AudioControlSGTL5000 audioShield; //xy=160,391
// GUItool: end automatically generated code
void setup(void) {
Serial.begin(115200);
while (!Serial);
delay(2000);
AudioMemory(12);
audioShield.enable();
audioShield.volume(1.0);
sine1.amplitude(1.0);
// Set filter cutoff frequency
filter1.frequency(1000);
filter2.frequency(1000);
Serial.println("Begin Sweep");
for (int f = 40; f < 20000; f += 40) {
// Set osc frequency
sine1.frequency(f);
// Let osc settle
delay(10000/f+10);
// Wait for detector data to be available
while (! peak1.available()) {
delay(1);
}
// Read the detected value
float ampl = 20 * log(peak1.read());
Serial.printf("f = %d, ampl = %f dB\n", f, ampl);
}
Serial.println("End Sweep");
}
void loop() {
}
Response Data
Code:
Begin Sweep
f = 40, ampl = -0.003662 dB
f = 80, ampl = -0.014043 dB
f = 120, ampl = -0.031765 dB
f = 160, ampl = -0.036044 dB
f = 200, ampl = -0.112625 dB
f = 240, ampl = -0.179643 dB
f = 280, ampl = -0.274095 dB
f = 320, ampl = -0.400106 dB
f = 360, ampl = -0.400106 dB
f = 400, ampl = -0.782340 dB
f = 440, ampl = -0.782340 dB
f = 480, ampl = -1.254385 dB
f = 520, ampl = -1.771158 dB
f = 560, ampl = -2.026195 dB
f = 600, ampl = -2.325622 dB
f = 640, ampl = -2.881794 dB
f = 680, ampl = -3.852451 dB
f = 720, ampl = -4.325705 dB
f = 760, ampl = -5.587701 dB
f = 800, ampl = -6.283273 dB
f = 840, ampl = -7.287467 dB
f = 880, ampl = -8.432961 dB
f = 920, ampl = -9.745206 dB
f = 960, ampl = -11.040151 dB
f = 1000, ampl = -12.487360 dB
f = 1040, ampl = -14.098092 dB
f = 1080, ampl = -15.552906 dB
f = 1120, ampl = -17.224178 dB
f = 1160, ampl = -18.869970 dB
f = 1200, ampl = -20.489258 dB
f = 1240, ampl = -22.217897 dB
f = 1280, ampl = -23.903429 dB
f = 1320, ampl = -25.977728 dB
f = 1360, ampl = -27.475380 dB
f = 1400, ampl = -29.243902 dB
f = 1440, ampl = -31.236423 dB
f = 1480, ampl = -32.715675 dB
f = 1520, ampl = -34.411797 dB
f = 1560, ampl = -36.212891 dB
f = 1600, ampl = -37.833035 dB
f = 1640, ampl = -39.521088 dB
f = 1680, ampl = -41.331093 dB
f = 1720, ampl = -42.884201 dB
f = 1760, ampl = -44.568146 dB
f = 1800, ampl = -46.129368 dB
f = 1840, ampl = -47.796204 dB
f = 1880, ampl = -49.361015 dB
f = 1920, ampl = -50.902542 dB
f = 1960, ampl = -52.438026 dB
f = 2000, ampl = -54.046581 dB