Create a filter function without using filter function (of course)

So I want to create a function that filters an input sequence using the transfer function of a filter. But the catch is I want to do this function at the frequency domain, and the only way to do this is to implement Discrete Fourier transform. So the inputs to my function are (B,A,S) where B is the numerator coefficients of the transfer function, A is the denominator coefficients of the transfer function, and S is the input sequence. The output is the time domain sequence. I want the function to be implemented in the frequency domain, so I would first convert S array to its frequency components using DFT. Then I would get the frequency response of the transfer function by using freqz. Multiplying the sequences will net you Y(W) right? So using IDFT you can get the time domain signal. But using this would net a different answer when filter function is used. I'm quite a noob at DSP but pls can someone help me?

 Accepted Answer

If you want to filter in the frequency domain, use the Signal Processing Toolbox fftfilt function. It uses the overlap-and-add method. See the documentation for details.

7 Comments

Do you by chance know the algorithm behind the fftfilt function? I mean how does it process the entire filtering technique? Thank you so much!
And another function, how do you implement this fftfilt function if the filter is an IIR system? Is there another way or do we need to approximate the IIR to become a FIR filter?
My pleasure!
You can read about the fftfilt algorithm in the documentation. Its description is better than anything I could write.
The documentation for fftfilt says that it ‘works only with FIR filters’, so I am not inclined to disagree with it.
I strongly recommend the designfilt function to design your filter. I’ve used the lower-level design functions to design filters, and while useful for simple filters, for filters with more complicated designs and constraints, designfilt is the best option.
Thanks again! I'm reading the fftfilt and it's super helpful in the filtering of sequences using an FIR filter.
But Iwant to know how the algorithm works for an IIR filter, since a function needs to be workable in every situation. I'm trying to make a filter function myself that is working for an FIR and an IIR filter, and since the FIR algorithm is based on the overlap save method, i wanna know how is it behind the IIR filters. Thank you!!
I take exception to ‘since a function needs to be workable in every situation’, because real-world applications all have constraints. Some functions are only defined (supported) on a particular set of inputs, for example, and are not defined outside those limits.
You would have to go to the cited reference (Oppenheim, et al.) for a discussion of the fftfilt algorithm and its requirements. It’s too involved to describe here. I’m inclined to agree with the MATLAB implementation.
OK. Thank you! You're a lifesaver.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!