MATLAB Question Solution
Problem 9:
Solution:
MATLAB code:
%hw553714
clc;clear;close all
load hw553714 % loads w, H(w), Noisy Data y(n), Original Data x(n)
%Note - Original data is given here only for illustration
figure(1)
plot(w,abs(Hw),'-*') %Plot noisy channel frequency response data
title('Noisy Frequency response of the channel ');
[Num_H,den_H]=invfreqz(Hw,w,1,0) %Esimated Channel Model
Poles_of_inv_filter=roots(Num_H); % To make sure Inverse filter "1/H" is
stable
%Model Validation
figure(2)
plot(w,abs(Hw),'-*')
title('Frequency response of the channel ')
hold on;
[ModelHw,w]=freqz(Num_H,den_H);
plot(w,abs(ModelHw),'-r')
title('Model Validation - |H(w)| (Blue) and |Model-H(w)| (Red) ')
hold off;
% Inverse filtering to restore original data
yf=filter(den_H,Num_H,y); %filter y(n) to restore x(n)
figure(3)
n=[1:length(x)]';
%plot([x y yf])
plot(n,x,'k',n,y,'b',n,yf,'r')
title('Plots of Original Data (Black), Noisy Data (Blue), and Restored (Inv-
Filter) data (Red)')
output in command window:
Plot of abs (Hw) against w:
Figure 9.1 Plot of abs (Hw) Vs. w
Frequency response of the channel:
Figure 9.2 Frequency channel response
Plot of Yf(n):
Figure9. 3 Plot of Yf(n)