
clc
clear all
close all
n = 0:64;
x = 0.1*sin(0.7*n);
figure("Name","Signal")
stem(n, x)
title("signal")
xlim([-1, 65])
ylim([-0.11, 0.11])
%%
%1
b_fir = [0.2, 0.3, 0.5, 0.7];
a_fir = 1;
y_fir = filter(b_fir, a_fir, x);
figure("Name","Finite Impulse Response Filter")
stem(y_fir)
axis auto
%%
%2
b_iir = [1, 1, 1, 1];
a_iir = [1, -0.3, 0.25, 0.4];
y_iir = filter(b_iir, a_iir, x);
figure("Name","Infinite Impulse Response Filter")
stem(y_iir)
%%
%3
h_hands = zeros(1, 64);
h(1) = 1;
h(2) = 1 + 0.3*h(1);
h(3) = 1 + 0.3*h(2) - 0.25*h(1);
h(4) = 1 + 0.3*h(3) - 0.25*h(2) - 0.4*h(1);
for n = 5:64
h(n) = 0.3*h(n-1) - 0.25*h(n-2) - 0.4*h(n-3);
end
figure("Name","h(n)")
bar(h)
ylim([-0.8, 1.31])
xlim([1, 40])
%%
%4
h_impz = impz(b_iir, a_iir, 80, 5000);
figure("Name","Impulse Response")
bar(h_impz);
clear all
close all
n = 0:64;
x = 0.1*sin(0.7*n);
figure("Name","Signal")
stem(n, x)
title("signal")
xlim([-1, 65])
ylim([-0.11, 0.11])
%%
%1
b_fir = [0.2, 0.3, 0.5, 0.7];
a_fir = 1;
y_fir = filter(b_fir, a_fir, x);
figure("Name","Finite Impulse Response Filter")
stem(y_fir)
axis auto
%%
%2
b_iir = [1, 1, 1, 1];
a_iir = [1, -0.3, 0.25, 0.4];
y_iir = filter(b_iir, a_iir, x);
figure("Name","Infinite Impulse Response Filter")
stem(y_iir)
%%
%3
h_hands = zeros(1, 64);
h(1) = 1;
h(2) = 1 + 0.3*h(1);
h(3) = 1 + 0.3*h(2) - 0.25*h(1);
h(4) = 1 + 0.3*h(3) - 0.25*h(2) - 0.4*h(1);
for n = 5:64
h(n) = 0.3*h(n-1) - 0.25*h(n-2) - 0.4*h(n-3);
end
figure("Name","h(n)")
bar(h)
ylim([-0.8, 1.31])
xlim([1, 40])
%%
%4
h_impz = impz(b_iir, a_iir, 80, 5000);
figure("Name","Impulse Response")
bar(h_impz);