finished exercise
This commit is contained in:
43
Assignment5_211/assignment5.2.m
Normal file
43
Assignment5_211/assignment5.2.m
Normal file
@@ -0,0 +1,43 @@
|
||||
clear; close all; clc;
|
||||
|
||||
n = 0:599; % 3 periods (3 × 200 samples)
|
||||
|
||||
x = sin(2*pi*0.005*n) ...
|
||||
+ (1/3)*sin(2*pi*0.005*3*n) ...
|
||||
+ (1/5)*sin(2*pi*0.005*5*n) ...
|
||||
+ (1/7)*sin(2*pi*0.005*7*n);
|
||||
|
||||
stem(n,x)
|
||||
grid on
|
||||
xlabel('n')
|
||||
ylabel('x[n]')
|
||||
title('Signal over 3 periods')
|
||||
|
||||
load("Filter_coefficients.mat","-mat")
|
||||
|
||||
y_FIR = filter(b1,a1,x);
|
||||
y_IIR = filter(b2,a2,x);
|
||||
|
||||
figure
|
||||
|
||||
plot(n,x,'y','LineWidth',1.5)
|
||||
hold on
|
||||
|
||||
plot(n,y_FIR,'b')
|
||||
plot(n,y_IIR,'r')
|
||||
|
||||
legend('Original','FIR','IIR')
|
||||
grid on
|
||||
title('Comparison of Signals')
|
||||
|
||||
figure
|
||||
|
||||
subplot(2,1,1)
|
||||
freqz(b1,a1)
|
||||
title('FIR Frequency Response')
|
||||
|
||||
figure
|
||||
|
||||
subplot(2,1,2)
|
||||
freqz(b2,a2)
|
||||
title('IIR Frequency Response')
|
||||
47
Assignment5_211/assignment5.4.m
Normal file
47
Assignment5_211/assignment5.4.m
Normal file
@@ -0,0 +1,47 @@
|
||||
clear; close all; clc;
|
||||
% Define filter coefficients
|
||||
b0 = 1;
|
||||
|
||||
b = b0 * [1 1 1 1];
|
||||
a = [1 -1.5 0.625];
|
||||
|
||||
% Frequency response
|
||||
[H,w] = freqz(b,a,1024);
|
||||
|
||||
% Magnitude and phase plots
|
||||
figure;
|
||||
|
||||
subplot(2,1,1);
|
||||
plot(w/pi, 20*log10(abs(H)), 'LineWidth', 1.5);
|
||||
grid on;
|
||||
xlabel('Normalized Frequency (\times\pi rad/sample)');
|
||||
ylabel('Magnitude (dB)');
|
||||
title('Magnitude Response');
|
||||
|
||||
subplot(2,1,2);
|
||||
plot(w/pi, unwrap(angle(H)), 'LineWidth', 1.5);
|
||||
grid on;
|
||||
xlabel('Normalized Frequency (\times\pi rad/sample)');
|
||||
ylabel('Phase (rad)');
|
||||
title('Phase Response');
|
||||
|
||||
% Define filter coefficients
|
||||
b0 = 1;
|
||||
|
||||
b = b0 * [1 1 1 1];
|
||||
a = [1 -1.5 0.625];
|
||||
|
||||
% Generate impulse signal
|
||||
n = 0:50;
|
||||
x = [1 zeros(1,50)];
|
||||
|
||||
% Compute impulse response
|
||||
h = filter(b,a,x);
|
||||
|
||||
% Plot impulse response
|
||||
figure;
|
||||
stem(n,h,'filled');
|
||||
grid on;
|
||||
xlabel('n');
|
||||
ylabel('h[n]');
|
||||
title('Impulse Response (0 \leq n \leq 50)');
|
||||
Reference in New Issue
Block a user