フィルターのクリア

How can I replicate filter's function for floating point values?

1 回表示 (過去 30 日間)
Andreas Prokopiou
Andreas Prokopiou 2019 年 1 月 9 日
Hello all!
I'm trying to replicate the filter function in order to study how it computes the series of values from input to output.
I made my own version:
function y = homemade_filter(b, a, x)
b = make_row_vector(b);
x = make_row_vector(x);
if length(a) > 1
error('Only FIR filter is implemented.')
end
b = b/a; % normalise
y = zeros(1,length(x));
x = [zeros(1,length(b)-1) x];
for n = 1:length(y)
y(n) = b * fliplr(x(n:n+length(b)-1))';
end
end
function z = make_row_vector(z)
[r,c] = size(z);
if r > c
z = z';
end
end
This function works if I use integer values for x , b and a , however if I use float values it does not give the same value:
x = 1:200;
b = 1:8;
y = filter(b,1,x);
y_test = homemade_filter(b,1,x);
isequal(y,y_test) % gives result of 1
x = 1:0.2:200;
b = 1:8;
y = filter(b,1,x);
y_test = homemade_filter(b,1,x);
isequal(y,y_test) % gives result of 0
The difference between y and y_test when the isequal test fails is in the order of e-14, so it falls within the range of floating point presision limits.
My question is, why is this the case? Shouldn't it be that the presision limits create the same error values in both algorithms and hence make the same output? In a sense, both values are "wrong" but shouldn't they be the same amount of "wrong"?
Thanks in advance!
A.

回答 (0 件)

カテゴリ

Help Center および File ExchangeDigital Filter Analysis についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by