필터 지우기
필터 지우기

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 CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by