Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am currently doing a signal analysis and filtering using Matlab. The filter I am using is Butterworthfilter model to filter scattered data (vector data).

I am using Matlab as follows:

function [y]=fButterworthfilter(input_data,f_cut)
rng default;
[b,a] = butter(8,f_cut/(200/2));
y=filtfilt(b,a,input_data); % zero-phase filtering

I want to see how can I do the Butterworthfilter filtering using Mathematica. I tried ButterworthFilterModel in the help but the input is a function not a vector data.

Let us say I have the following noisy data:

data1 = Table[Exp[-i^2], {i, -5, 5, .01}];
noise = RandomReal /@ RandomReal[{-0.3, 1}, Length[data]];
data2 = data1+noise;

How can I do Butterworthfilter filtering for this data? Thanks

share|improve this question

1 Answer 1

up vote 6 down vote accepted

Butterworth is a continuous-time recursive filter, so it needs to be translated to discrete form and then applied to the data using

 RecurrenceFilter[ToDiscreteTimeModel[ButterworthFilterModel[5], 1], data]

For example, with `data={1, 2, 3, 4, 3, 2, 1, -1}', the output is

 {0.00649005, 0.0585661, 0.254294, 0.718228, 1.49564, 2.44071, 3.20403, 3.38901}
share|improve this answer
Thank you fro you Replay, I got your idea but I am still not getting same answer that I am getting from Matlab. I don'e understand how to place the filtering inputs to produce same output as I am getting from. I will paste another Question and I would appreciate it if you look at it. – Algohi Apr 21 '14 at 3:16
The RecurrenceFilter here is like Matlab's function filt. If you want the same answer as filtfilt gives, you will have to do what filtfilt does: filter forwards and then backwards. – bill s Apr 21 '14 at 12:30
Thanks bill, i have done what you said, forwards and backwards filler as follows: Reverse[ RecurrenceFilter[ ToDiscreteTimeModel[ButterworthFilterModel[{c, a}], b], Reverse[ RecurrenceFilter[ ToDiscreteTimeModel[ButterworthFilterModel[{8, 0.04}], 3.2], data2]]]] is there any better way to do the backward and forward option? – Algohi Apr 21 '14 at 20:32
I showed what I think is an imitation of what Matlab is doing in this answer: If you don't want to write it all out each time, you can make a function (and call it filtfilt!) – bill s Apr 21 '14 at 21:11
Thank you. it works with me good. – Algohi Apr 21 '14 at 22:07

Your Answer


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.