たたみこみによるデジタルフィルタの計算

clear; close all;
h=[1 4 -2];
x=[2 -1 3 1];

hlength=length(h);
xlength=length(x);
ylength=hlength+xlength-1;

hzero=[h zeros(1,xlength-1)];
xzero=[x zeros(1,hlength-1)];

y=zeros(1,ylength);

for n=1:ylength-1
    for k=0:n
       y(n+1)=y(n+1)+hzero(k+1)*xzero(n-k+1);
    end
end

subplot(311);
plot(x);
title('x: filter input');
subplot(312);
plot(h);
title('h: filter as impulse response');
subplot(313);
plot(y);
title('y: filter output');
end

f:id:seinzumtode:20191022135903p:plain