Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to filter data using Butterworth filter. I am currently using Matlab and I want to know how to do it in Mathematica.

I have the following data:

data1 = Table[
   PDF[NormalDistribution[3.5, .8], i] + 
    PDF[NormalDistribution[6, 1], i], {i, -5, 15, .01}];
noise = RandomReal /@ RandomReal[{-0.2, .2}, Length[data1]];
data2 = data1 + noise;

I filtered this data using Matlab as follows:

[b,a] = butter(8,0.04);

filtfilt(b,a,data2 );

In the previous question's answer, bill s suggested to do it as follows in Mathematica:

RecurrenceFilter[
 ToDiscreteTimeModel[ButterworthFilterModel[{2, 0.04}], 1], data2
 ]

The result is as follows: enter image description here

The problem I am facing is whatever I change the filter order and frequency, I am not able to produce the same filtered data as I am getting from Matlab.

Can someone suggest for me what to do and what values to use to get the same filtered data as I am getting from Matlab?

Thanks

share|improve this question
1  
filtfilt does a forward-backward filtering. Have you tried filtering, reversing the output, filtering again and finally reversing again in Mathematica? –  rm -rf Apr 21 at 5:24
add comment

1 Answer 1

up vote 0 down vote accepted

filtfilt does a forwards and then a backwards filtering, as rm -rf suggests. To filter data in this way, you might try

forwards = RecurrenceFilter[ToDiscreteTimeModel[ButterworthFilterModel[5], 1], data];
backwards = RecurrenceFilter[ToDiscreteTimeModel[ButterworthFilterModel[5], 1], Reverse[data]];
forwards + Reverse[backwards]
share|improve this answer
    
Good. Great Thanks. –  Algohi Apr 21 at 22:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.