Ee648hw4 Bokhtiar
Ee648hw4 Bokhtiar
1
EE648 HW4 QUESTION 3a %%
Define the poles and zeros
1
Published with MATLAB® R2024a
2
EE648 HW4 QUESTION 3c %%
% Define the poles and zeros
zeros = [exp(1j*pi/3), exp(-1j*pi/3), -1.1765];
poles = [0.9*exp(1j*pi/3), 0.9*exp(-1j*pi/3), -0.85];
1
Published with MATLAB® R2024a
2
% EE648 HW4 QUESTION 4a %%
1
EE648 HW4 QUESTION 4d %%
Define the numerator and denominator coefficients for H_min(z)
1
2
Published with MATLAB® R2024a
3
Table of Contents
EE648 QUESTION 5 %% .................................................................................................................... 1
a ...................................................................................................................................................... 1
b ...................................................................................................................................................... 2
c ...................................................................................................................................................... 3
d ...................................................................................................................................................... 4
e ...................................................................................................................................................... 5
f ....................................................................................................................................................... 5
g ...................................................................................................................................................... 6
h ...................................................................................................................................................... 7
i ....................................................................................................................................................... 7
j ....................................................................................................................................................... 8
EE648 QUESTION 5 %%
close all,
clear all,
clc,
a
n=-1000:1:1000;
Xn = (1/4)*sinc(n/4);
figure
plot(n,Xn); title(' Xn Plot '); xlabel('n'); ylabel('Xn'); grid on
1
b
xd = downsample(Xn,3);
Xe = upsample(xd,3);
figure,
plot(n,Xe); title(' Xe Plot '); xlabel('n'); ylabel('Xe'); grid on
2
c
nfilt=50;
filt = fir1(nfilt,1/3,'low');
figure, plot(filt); title(' Filter Coefficients '); grid on
3
d
figure,
freqz(filt,1,512);
4
e
Scale=3;
Xr = Scale*filter(filt,1,Xe);
f
figure,
plot(n,Xn);
hold on,
plot(n,Xr,'r');
title('Input and reconstructed sequences'); xlabel('n'); ylabel('Xr/Xn');
legend('Xn', 'Xr'); grid on
5
g
delay = grpdelay(filt);
avg_delay = mean(delay);
X_trunc = Xn(1:end-avg_delay);
Xr_Shift = Xr((avg_delay+1):end);
figure,
plot(X_trunc);
hold on
plot(Xr_Shift,'r');
grid on
title('X trunc and Xr Shift Plot');
legend('X trunc','Xr Shift')
% Display the average delay
disp(['Average delay (avg_delay) introduced by the filter: ',
num2str(avg_delay)]);
6
h
%MSE = sumsqr(X_trunc - Xr_Shift)/length(X_trunc);
i
FilterOrder = [10, 20, 50, 100, 200];
NewMSE = zeros(1, length(FilterOrder));
GroupDelay = zeros(1, length(FilterOrder));
for r = 1:length(FilterOrder)
nfilt = FilterOrder(r);
filt = fir1(nfilt, 1/3, 'low');
Scale = 3;
7
Xr = Scale * filter(filt, 1, Xe);
delay = mean(grpdelay(filt));
X_trunc = Xn(1:end-delay);
Xr_Shift = Xr((delay+1):end);
difference = X_trunc - Xr_Shift;
squaredDifference = difference .^ 2;
sumOfSquaredDifferences = sum(squaredDifference);
MSE = sumOfSquaredDifferences / length(X_trunc);
NewMSE(r) = MSE;
GroupDelay(r) = delay;
end
% Create a table for the results
resultsTable = table(FilterOrder', NewMSE', 'VariableNames', {'Filter
Order', 'MSE'});
disp(resultsTable);
10 3.7207e-06
20 2.5196e-07
50 3.4134e-10
100 2.1172e-10
200 4.7458e-11
j
Create a table for the results
% Observations
fprintf('\nObservations:\n');
fprintf('1. As the filter order increases, the MSE generally decreases,
indicating better signal reconstruction.\n');
fprintf('2. Higher filter orders introduce longer group delays, which need
to be compensated for when aligning the signals.\n');
fprintf('3. Beyond a certain filter order, the reduction in MSE becomes less
significant, indicating diminishing returns.\n');
fprintf('4. The group delay increases approximately linearly with the filter
order.\n');
10 3.7207e-06 5
20 2.5196e-07 10
50 3.4134e-10 25
100 2.1172e-10 50
200 4.7458e-11 100
8
Observations:
1. As the filter order increases, the MSE generally decreases, indicating
better signal reconstruction.
2. Higher filter orders introduce longer group delays, which need to be
compensated for when aligning the signals.
3. Beyond a certain filter order, the reduction in MSE becomes less
significant, indicating diminishing returns.
4. The group delay increases approximately linearly with the filter order.