FIR filter with Teensy 4 + audio adapter

Status
Not open for further replies.

fred_france

Active member
Hello,

I am a beginner in the world of Teensy, and I bought a version 4.0 + the audio adapter.
I want to experiment audio filters (bandpass, high pass, low pass).

For this, I want to use an FIR filter, but I can't seem to get any valid response curves.

To start, I tried the example provided in Audio / Effects / Filter_FIR, and I measured the frequency response of the low pass filter: the shape is correct, but I only have -10dB of attenuation at 2Khz instead of -60 dB as advertised in the demo sketch.

Moreover, I tried to generate my own tables of coefficients with a tool (http://t-filter.engineerjs.com/), by setting: 44117hz, 200 taps, and changing "static int" to "const short ”, the results curves are catastrophic.

I noticed that the examples found on the internet are for a Teensy v3.x and not for v4, maybe some settings need to be adapted for my version 4?

thanks a lot for your help

(sorry for my bad english)
 
Datatype short is 16 bit - it is too low resolution for coefficients of a good filter. Also if you just change the data type from int to short, you will likely overflow the range, as short has only +/-2^15 range (-32768...+32767) while int spans much higher range (-2^31...+2^31) so all coefficients get wrong. To avoid overflowing the range, when changing from int to short you would need to divide all coefficients by 65536 (2^16). For good quality filters you need either int or float. Super sharp filter may even need double (note that the tool you pointed out only supports int and double).
 
Hello,

I am a beginner in the world of Teensy, and I bought a version 4.0 + the audio adapter.
I want to experiment audio filters (bandpass, high pass, low pass).

For this, I want to use an FIR filter, but I can't seem to get any valid response curves.

To start, I tried the example provided in Audio / Effects / Filter_FIR, and I measured the frequency response of the low pass filter: the shape is correct, but I only have -10dB of attenuation at 2Khz instead of -60 dB as advertised in the demo sketch.
Both the low-pass and band-pass work perfectly for me on T4.0 + audio adapter. You are using the left channel for the low pass?
Moreover, I tried to generate my own tables of coefficients with a tool (http://t-filter.engineerjs.com/), by setting: 44117hz, 200 taps, and changing "static int" to "const short ”, the results curves are catastrophic.

I noticed that the examples found on the internet are for a Teensy v3.x and not for v4, maybe some settings need to be adapted for my version 4?
Shouldn't make any difference
thanks a lot for your help

(sorry for my bad english)
 
I agree with tomas. Is there a tool for predicting how many bits you need for how much distortion?
 
Thank you for your answers.

I tried differently with another software "rePhase" more complete and easier to use

This software gives me coefficients in float.
To process these floats on the Teensy side, I found an example on the internet which converts them into shorts like this:

(short) (32768 * 0.00000122889570184005)

It works well, but I don't really understand why ...
 
This software gives me coefficients in float.
To process these floats on the Teensy side, I found an example on the internet which converts them into shorts like this:

(short) (32768 * 0.00000122889570184005)

It works well, but I don't really understand why ...


It works because you have converted (rescaled) floating point coefficients to fixed point. If you use short data type (16 bit), coefficients are supposed to be in the range of -32768 upto 32767 and that values represent fractions of -1.0..+1.0. See: https://en.wikipedia.org/wiki/Fixed-point_arithmetic
 
It works because you have converted (rescaled) floating point coefficients to fixed point. If you use short data type (16 bit), coefficients are supposed to be in the range of -32768 upto 32767 and that values represent fractions of -1.0..+1.0. See: https://en.wikipedia.org/wiki/Fixed-point_arithmetic

ok, i understand, thank you.

is it possible to increase the number of taps ? (more than 200), i've tried in filter_fir.h to set 400 instead 200, but it doesn't work with arrays with more than 200 coefs
 
You'd have to edit filter_fir.h to change the #define FIR_MAX_COEFFS to be more than 200.

Note the number of taps needs to be even and 4 or more to work with the ARM fir primitive used in filter_fir.cpp (for T4 at least).
 
You'd have to edit filter_fir.h to change the #define FIR_MAX_COEFFS to be more than 200.

Note the number of taps needs to be even and 4 or more to work with the ARM fir primitive used in filter_fir.cpp (for T4 at least).

yes this is the first thing i tried but after i tried a 250 array that didn't work .. has anyone tried?
 
The documentation for the arm primitives notes a restriction on scaling to prevent overflow - this might be why the 200 limit is there?
 
While it's only necessary for high resolution at low frequencies, I am able to run 12288 taps, stereo.
 
BTW why use FIR for simple audio LP/BP/HP filtering? Do you actually need linear-phase?

I am building a speaker frequency response analyzer, so I generate sounds (20hz to 20khz) in the loudspeaker to be tested, and I measure the signal level with the microphone.
So I need to filter the signal from the microphone to only have the one produced by the sound generator
 
Well if you don't need well defined phase response IIR filters are probably more straight-forward, and if you need several their coefficient
arrays are _much_ more compact.

For simple frequency analysis an FFT is normally used direct, you can do any filtering directly in the frequency domain once you have
the spectrum.
 
I got some new speakers. As always, the improvement with DRC was striking. Unless you have fantastic speakers and the perfect room and placement, I'd use it.

The process:

Measure speaker response with a calibrated microphone (eg, UMIK-1)
Export impulse response from REW
Calculate a correction impulse response with DRC by Denis Sbragion
recompile my version of DD4WH convolution code with the correction impulse response .h files and push to teensy 4
use teensy as a convolution based equalizer and USB to toslink adapter
 
I got some new speakers. As always, the improvement with DRC was striking. Unless you have fantastic speakers and the perfect room and placement, I'd use it.

The process:

Measure speaker response with a calibrated microphone (eg, UMIK-1)
Export impulse response from REW
Calculate a correction impulse response with DRC by Denis Sbragion
recompile my version of DD4WH convolution code with the correction impulse response .h files and push to teensy 4
use teensy as a convolution based equalizer and USB to toslink adapter

Hi Jonr,

I was wondering if you could provide your version of the code. Also, is it set up to take an input from the audio board and process that, then reoutput it through the audio board? Lastly, how is the file needing to be processed (presumably .wave), meant to be stored in the Teensy 4.0? I mean, how did you do it?

Many thanks, Elliott
 
Status
Not open for further replies.
Back
Top