Create DSP filter coefficients in C / Java for time-domain convolution

I am writing a smartphone application (Android, iPhone) that does some DSP. I am an experienced programmer. I also took one EE class for students in DSP and know how to use Matlab.

I would like to apply low-pass and band-pass filters to my signal in the time domain. In my opinion, I need to convolve my time domain samples and filter coefficients. In Matlab, I would use the fir1 () function to get the filter coefficients and the conv () / filter () functions to apply convolution.

I know how to write a convolution function in Java / C, but I don't know how to generate filter coefficients . I know that for the low-pass filter, the coefficients come from the sinc function, and the band-pass filter is basically a shifted low-pass filter. How can I programmatically generate these coefficients?

+4
source share
4 answers

There is code to generate FIR coefficients for lowpass and bandpass filters using the windowed-sinc method on the nicholson.com dsp webpage . The code is about 10 lines of the old-fashioned Basic, but should be trivially convertible to C or Java. There is an explanation on this page if you want to rewrite the code.

The art of using windowed-sinc is choosing the best window. A more modern method, which requires less guessing, is to use the Remez-exchange algorithm to generate a filter from the specifications.

+1
source

I found a tutorial that generates filter coefficients in C ++ code, which is relatively easy to translate into Java code. The tutorial can be found here: http://baumdevblog.blogspot.com/2010/11/butterworth-lowpass-filter-coefficients.html . I hope this will be helpful to you.

This is a rather interesting topic, and I plan to make a similar project myself :)

0
source

If you do not change the filter parameters (bandwidth, transition range, etc.), the easiest way is to generate coefficients in Matlab and hard code them in your program. You will find that Matlab can generate good filters with a significantly lower coefficient, which the window method can use. Given that convolution is the coefficient MxN (M = the number of filter coefficients and N is the number of samples), a decrease in M ​​can be of great importance in performance.

0
source

In the past, I have successfully used the version of the Parks-McClennan method (Remez exchange) written in C by Jake Janovec to programmatically generate coefficients for a bandpass FIR filter. You can try.

0
source

Source: https://habr.com/ru/post/1379696/


All Articles