Can filter function be replace by a fft/ifft operation?
Show older comments
Can filter function be replace by a fft/ifft operation?
for example:
out = filter(LPF,in);
replaced by:
one = ifft(ones(size(in))); oneout = filter(LPF,one); f_oneout = fft(oneout); out = ifft(f_oneout.*fft(in));
Is there any difference between these two? As I want the second result. But I just dont know why these are different?
Answers (1)
Honglei Chen
on 14 Jul 2014
I don't understand your approach of fft/ifft to filter the signal, so I cannot comment on that. But between filter and fft/ifft approach, it is important to realize that fft/ifft approach is equivalent to circular convolution while filter corresponds to linear convolution, so you need to be careful regarding the number of points
for example:
LPF = [1 1]
in = ones(1,10)
filter(LPF,1,in)
ifft(fft(LPF,length(in)).*fft(in))
See the difference. Now do
y = ifft(fft(LPF,length(in)+length(LPF)-1).*fft(in,length(in)+length(LPF)-1))
y(1:length(in))
Now it's the same as filter result.
HTH
4 Comments
Marco
on 14 Jul 2014
Not wanting to hijack the thread, but what is the difference between linear and circular convolution? Would you have a link for further reading about that? Thanks!
Honglei Chen
on 14 Jul 2014
Here is an example you can take a look
Essentially, you can imagine to stack the linear convolution result at every N points so the result becomes periodic with a period of N. Circular convolution simply extracts one period of the result.
JIN
on 15 Jul 2014
Honglei Chen
on 15 Jul 2014
filter is doing the right thing. In many applications, the number of outputs is the same as the number of inputs. You can use state with filter to achieve streaming. If you want to see the entire result and you have access for all the data, then you can consider using conv.
Categories
Find more on Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!