필터 지우기
필터 지우기

How to design aFIR filter without filter function

조회 수: 9 (최근 30일)
farhad vaseghi
farhad vaseghi 2020년 3월 13일
댓글: farhad vaseghi 2020년 3월 13일
please help me implement this as function to take a,b,x and give me y
  댓글 수: 1
farhad vaseghi
farhad vaseghi 2020년 3월 13일
I wanna impeliment this whith a seprate function
and without,without any use of filter() function!!!!!!!!!!!

댓글을 달려면 로그인하십시오.

채택된 답변

Sriram Tadavarty
Sriram Tadavarty 2020년 3월 13일
편집: Sriram Tadavarty 2020년 3월 13일
Hi Farhad,
This code should do what is asked for. Since, you asked for FIR filter, a will be a scalar with value 1.
function y = filterbax(b,a,x)
% The function expects inputs to be column vectors
M = length(b);
N = length(a);
xbuffer = [];
ybuffer = [];
for i = 1:length(x)
xbuffer = [x(i);xbuffer];
if length(xbuffer) < M
index = length(xbuffer);
else
index = M;
end
if length(ybuffer) < N-1
yindex = length(ybuffer);
else
yindex = N-1;
end
y(i) = (1/a(1)).*(sum(b(1:index).*xbuffer(1:index)) - sum(a(2:yindex+1).*ybuffer(1:yindex)));
ybuffer = [y(i);ybuffer];
end
y = y(:); % Return as column vector
end
Note that more optimizations can be done, but this should work.
% In command prompt,
% try the following
>> b = [2,3];
>> a = [1,0.2];
>> x = randn(10000,1);
>> y = filterbax(b,a,x); % Custom function
% Compare the output from custom written function and MATLAB function
>> y1 = filter(b,a,x); % MATLAB function
>> max(abs(y-y1).^2)
Hope this helps.
Regards,
Sriram
  댓글 수: 3
Sriram Tadavarty
Sriram Tadavarty 2020년 3월 13일
Hi farhad, This is not the same filter function. The name of the function is placed as filterbax which is independent of filter. The bottom code in the answer is just the test with the inbuilt Matlab function. Hope it clears. Regards, Sriram
farhad vaseghi
farhad vaseghi 2020년 3월 13일
Tanks Sriram
your a great man
thats the answer
you helped me this day i wish god bless you
tanks bro

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Filter Banks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by