Teensy 3.1 - DSP - Matlab Digital filter

Status
Not open for further replies.

Deadp1xels

Well-known member
I've undertaken the task of getting a Matlab digital filter onto the Teensy 3.1 because of its onboard DAC.

I've been using Matlab at my Uni and have designed a filter using the FDAtool and i think i can get the M file from it.

Its a simple butterworth filter nothing special
All i simply want to do is generate some form of waveform, filter it and output the filtered signal through the DAC

I'm understanding i can generate C Code straight from Matlab is this correct?
How do i define my DAC so the filtered signal is output from there?

Is there a guide that covers the process from designed filter to working to implementing on hardware that i could look at?
 
The audio library has a very specific API, so it's unlikely Matlab will output C code that is compatible or easily adaptable to the necessary API.

Probably the easiest way to get started, even if it's not able to fully meet your filtering requirements, would be the IIR biquad filter. That's currently the only filter which exists in the library. Here's the example code:

https://github.com/PaulStoffregen/Audio/blob/master/examples/Filter/Filter.ino

In theory, you could use Matlab to generate those 5 coefficients. Here's a message about using a web-based tool.

http://forum.pjrc.com/threads/24793-Audio-Library?p=40179&viewfull=1#post40179

The key point is to convert the floating point coefficients to the 32 bit format. You just multiply by 1073741824, and possibly change the sign on 2 of them. Also, the coefficients need to be in the range of -2.0 to +2.0. If your design tool gives you a number more than 2.0, change gain or Q or other settings to get it under 2.0.

That object theoretically supports a cascade of biquads, but that hasn't been tested and probably doesn't work. Of course, you can cascade them by simply creating multiple objects and feeding the output of one into the input of the next.

For FIR or other filter types, objects will need to be added to the library. Then you could import your coefficients, much like the biquad filter. Here's a very preliminary document about creating new objects. It's meant to be read alongside a copy of the source code (someday I'll edit this to make it easier to follow as a stand-alone document)

https://github.com/PaulStoffregen/Audio/blob/master/new_objects.md
 
May I suggest http://www-users.cs.york.ac.uk/~fisher/mkfilter/trad.html

Here, you will find an interactive site for generating coefficients for a filter (e.g., Butterworth) IIR. Also included at this website is pseudo-C code (VERY SIMPLE) that implements the filter using the provided coefficients.

I have programmed it successfully in C# (yet not on the Teensy 3.1 yet).

I am interested to see your results on Teensy 3.1

RIchard
 
Hi, I am new to the boards. I figured my question would dovetail with this subject so I am posting here. I am fairly experienced in signal processing (just not a whole lot in fixed point) and I am comfortable using the teensy and other arduino boards.

I am trying to use teensy as a speaker management board, essentially a chain of biquads and, hopefully, a limiter/compressor of some kind.

I started by chaining a couple of biquads and while it DID implement the filters I intended (a 100hz butter HP followed by a parametric cut at 170 hz with moderate Q), there was some noise at low playback levels and a sustained noise / low level oscillation when the input was silent (or low level background noise at the input I suppose). The source was my iphone 5 plugged into the teensy's input (labled line in)

I dug into the code for biquad and it looks like the filter is implemented at 32 bit precision, which *should* be more than enough for audio applications even with rather long chains. But the noise I heard had a quality that made me suspect quantization error of some sort.

I made sure that none of the coefficients exceeded 2 (which I believe is needed to prevent overflow)

I also tried this with just one biquad at a time (either biquad had the same result). So this isn't necessarily a result of chaining them.

My questions are:
1. is the audio block format that connects filters also 32 bits (It appears yes..?)
2. What type of Direct Form is the filter and does it have noise shaping?
3. Unless you have a suggestion of where to look next, (maybe there is something silly I neglected?) I'd be happy to dig into the biquad code and make changes necessary to get it to work.

Thanks!

-Aurelio R. Ramos
 
Hmm, never mind my previous message, it appears the quantization noise I hear is due to A/D conversion. I tested with the pass thru example and I can still reproduce it. Is this just the way the codec is, or is there anything I can do on my end to improve the output (Of course, I know scaling the input signal adequately largely eliminates the problem and for most practical applications that would be OK, but the amount of noise still seems unreasonably high for low level inputs compared to other A/D hardware I have tried.

Thanks!

-Aurelio
 
Status
Not open for further replies.
Back
Top