FIR filter doesn't work after using TFilter design tool

Status
Not open for further replies.

josechow

Well-known member
Code below works for pass thru, and compiles for implementing the low pass filter, but does not output anything on the dac or respond to serial. I am at a loss. Does the filter need to be of a specific size? I only saw the max of 200 constraint

Code:
#include <Audio.h>

AudioInputAnalog         audio_in(A3);   //xy=179,383
AudioFilterFIR           fir1;           //xy=342,383
AudioOutputAnalog        dac1;           //xy=519,360
AudioRecordQueue         amdf_samples;   //xy=543,409

AudioConnection          patchCord1(audio_in, fir1);
AudioConnection          patchCord2(fir1, dac1);
AudioConnection          patchCord3(fir1, amdf_samples);

/*

FIR filter designed with
http://t-filter.appspot.com

sampling frequency: 44100 Hz

fixed point precision: 16 bits

* 0 Hz - 6000 Hz
  gain = 1
  desired ripple = 5 dB
  actual ripple = n/a

* 15000 Hz - 22050 Hz
  gain = 0
  desired attenuation = -60 dB
  actual attenuation = n/a

*/

#define FILTER_TAP_NUM 11

const short filter_lowpass[FILTER_TAP_NUM] = {
  -779,
  -2839,
  -2707,
  5409,
  19375,
  26657,
  19375,
  5409,
  -2707,
  -2839,
  -779
};

unsigned long last_time = millis();

void setup() {
  Serial.begin(9600);
  delay(300);

  // allocate memory for the audio library
  AudioMemory(100);

  //fir1.begin(FIR_PASSTHRU, 0);
  
  // Initialize the filter
  fir1.begin(filter_lowpass, FILTER_TAP_NUM);
}

void loop()
{

  // print information about resource usage
  // Proc = 18 (18),  Mem = 4 (5)
  if (millis() - last_time >= 2000) {
    Serial.print("Proc = ");
    Serial.print(AudioProcessorUsage());
    Serial.print(" (");    
    Serial.print(AudioProcessorUsageMax());
    Serial.print("),  Mem = ");
    Serial.print(AudioMemoryUsage());
    Serial.print(" (");    
    Serial.print(AudioMemoryUsageMax());
    Serial.println(")");
    last_time = millis();
  }
}
 
[SOLVED] filter declaration must be of an even number

Used the default example and just started cutting down the number of sample points and it turns out odd number of filter elements caused failures. Re-ran the tfilter design tool and added 1 to the minimum number of elements.

Though, I would like to know if the number of delay elements would reduce or increase the stability of the filter?

Code:
/*
FIR filter designed with
http://t-filter.appspot.com

sampling frequency: 44100 Hz

fixed point precision: 16 bits

* 0 Hz - 6000 Hz
  gain = 1
  desired ripple = 5 dB
  actual ripple = n/a

* 15000 Hz - 22050 Hz
  gain = 0
  desired attenuation = -60 dB
  actual attenuation = n/a
*/

const short FILTER_TAP_NUM = 12;

const short filter_taps[FILTER_TAP_NUM] = {
  -369,
  -2022,
  -3644,
  171,
  12206,
  24284,
  24284,
  12206,
  171,
  -3644,
  -2022,
  -369
};
 
Status
Not open for further replies.
Back
Top