Initialize filter so that filtered output begins with initial value of the input
92 ビュー (過去 30 日間)
古いコメントを表示
I would like to implement a recursive exponential filter with the following function: filter([alpha 0],[1 alpha-1],data); This is equivalent of the following equation: y(n)=y(n-1) * (1-alpha) + alpha * x(n) where x is the input and y is the output. With the above function I get alpha * x(1) for y(1) which means that y(0) is assumed to be zero. I expected that with the following function filter([alpha 0],[1 alpha-1],data,data(1)); I would get x(1) for y(1), but it is not the case. What is the problem? How can I make sure that y(1)=x(1)? Thanks in advance.
1 件のコメント
Christoph F.
2017 年 4 月 25 日
y(n) = y(n-1)*(1-a) + a*x(n)
And you want x(1) = y(1) so:
x(1) = y(0)*(1-a) + a*x(1)
(1-a)*x(1) = (1-a)*y(0)
y(0) = x(1)
You need to set the initial condition y(0) of your filter to x(1). Note that the exact values of the initial conditions depend on the filter structure, so if you're using something other than direct form 1, the calculation of the initial values for the delay line is somewhat different.
Example, step response to x=1, with transition
a = 0.25; y=0; x=1; for ii=1:40; y = y*(1-a) + a*x; yout(ii)=y; end;plot( yout);
Example with y(0) set to x(1):
a = 0.25; y=1; x=1; for ii=1:40; y = y*(1-a) + a*x; yout(ii)=y; end;plot( yout);
I don't think using filtfilt is the answer, since it effectively doubles the filter order and changes the filters amplitude response significantly. Also, it is not possible to use forward-backward-filtering if real-time output is required.
回答 (3 件)
Star Strider
2017 年 3 月 12 日
I always use the filtfilt (link) function for filtering because it avoids this problem and also has a maximally flat phase response, so that all filters, regardless of design, have the phase response that a hardware Bessel filter would have.
If you want to use the filter (link) function, see the section of the documentation on Filter Data in Sections (link) for details on setting the initial conditions.
0 件のコメント
Christoph F.
2017 年 4 月 25 日
Oops. That was supposed to be an answer, not a comment. So I'm posting it again as an answer.
y(n) = y(n-1)*(1-a) + a*x(n)
And you want x(1) = y(1) so:
x(1) = y(0)*(1-a) + a*x(1)
(1-a)*x(1) = (1-a)*y(0)
y(0) = x(1)
You need to set the initial condition y(0) of your filter to x(1). Note that the exact values of the initial conditions depend on the filter structure, so if you're using something other than direct form 1, the calculation of the initial values for the delay line is somewhat different.
Example, step response to x=1, with transition
a = 0.25; y=0; x=1; for ii=1:40; y = y*(1-a) + a*x; yout(ii)=y; end;plot( yout);
Example with y(0) set to x(1):
a = 0.25; y=1; x=1; for ii=1:40; y = y*(1-a) + a*x; yout(ii)=y; end;plot( yout);
I don't think using filtfilt is the answer, since it effectively doubles the filter order and changes the filters amplitude response significantly. Also, it is not possible to use forward-backward-filtering if real-time output is required.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Digital Filtering についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!