フィルターのクリア

How to write my own filter function with initial condition similar to Filter.m?

3 ビュー (過去 30 日間)
Hossein
Hossein 2013 年 2 月 5 日
コメント済み: Mariasole Laureti 2019 年 10 月 7 日
I have read the documents on how MATLAB implements Filter(b,a,y,z0). To fully understand the concept and learn more about Signal Processing, I tried to implement it by myself, but the answer is different from MATLAB filter.m
Could anyone let me know what I am missingg?! :-(
function y =myfilter(num, den, x, zi)
N = length(x);
% assuming order of Num and Den are the same.
ord = (length(num)-1)/2;
y = zeros(N,1);
for i=1:N
c = 0;
for j=1:2*ord
if i-j < 1
c = c+1;
xo(j) = zi(c);
yo(j) = 0;
else
xo(j) = x(i-j);
yo(j) = y(i-j);
end
end
y(i) = num(1)*x(i) + sum(num(2:end).*xo') - sum(den(2:end).*yo');
end

採用された回答

Hossein
Hossein 2013 年 2 月 6 日
Ok, I searched online and found out that I was wrong on the concept :) Here' the correct formulation of 1D filtering with delay initial values: SciPY Filtering Documentation, and it outputs the same result as MATLAB filter() does.
  1 件のコメント
Mariasole Laureti
Mariasole Laureti 2019 年 10 月 7 日
Hi, I have the same problem, can I ask you if you can show me your code? I would be very grateful. Thank you very much

サインインしてコメントする。

その他の回答 (1 件)

ssp
ssp 2017 年 2 月 12 日
Hi! Greetings!
I was also trying to write my filter function. However y=filter(b,a,x) seems easy to implement, but I am stuck at implementing y=filter(b,a,x,zi). What would be the new sequence of the following sequence after applying initial condition zi? y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb) - a(2)*y(n-1) - ... - a(na+1)*y(n-na)
Thanks! SSP
  1 件のコメント
Jan
Jan 2017 年 2 月 12 日
編集済み: Jan 2017 年 2 月 12 日
Please do not attach a question as an answer to another question.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFrequency Transformations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by