% This file was automatically created from the m-file 
% "m2tex.m" written by USL. 
% The fontencoding in this file is UTF-8. 
%  
% You will need to include the following two packages in 
% your LaTeX-Main-File. 
%  
% \usepackage{color} 
% \usepackage{fancyvrb} 
%  
% It is advised to use the following option for Inputenc 
% \usepackage[utf8]{inputenc} 
%  
  
% definition of matlab colors: 
\definecolor{mblue}{rgb}{0,0,1} 
\definecolor{mgreen}{rgb}{0.13333,0.5451,0.13333} 
\definecolor{mred}{rgb}{0.62745,0.12549,0.94118} 
\definecolor{mgrey}{rgb}{0.5,0.5,0.5} 
\definecolor{mdarkgrey}{rgb}{0.25,0.25,0.25} 
  
\DefineShortVerb[fontfamily=courier,fontseries=m]{\$} 
\DefineShortVerb[fontfamily=courier,fontseries=b]{\#} 
  
\noindent                                                                                  
 \hspace*{-1.6em}{\scriptsize 1}$  $\color{mgrey}#%% Linear equalization#\color{black}$$\\
 \hspace*{-1.6em}{\scriptsize 2}$  clear, $\color{mdarkgrey}$clc, close all$\color{black}$$\\
 \hspace*{-1.6em}{\scriptsize 3}$  $\\
 \hspace*{-1.6em}{\scriptsize 4}$  M = 8; $\color{mgrey}$% Filter order$\color{black}$$\\
 \hspace*{-1.6em}{\scriptsize 5}$  $\\
 \hspace*{-1.6em}{\scriptsize 6}$  $\color{mgrey}$% Filter coefficients$\color{black}$$\\
 \hspace*{-1.6em}{\scriptsize 7}$  c = [0.4032    0.3992    0.1976];$\\
 \hspace*{-1.6em}{\scriptsize 8}$  $\\
 \hspace*{-1.6em}{\scriptsize 9}$  $\color{mgrey}$% Impulse response of 1/C(z)$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 10}$  hc = impz(1, c);$\\
 \hspace*{-2em}{\scriptsize 11}$  $\\
 \hspace*{-2em}{\scriptsize 12}$  $\color{mgrey}#%% a) Window method with rectangular window#\color{black}$$\\
 \hspace*{-2em}{\scriptsize 13}$  hwin = hc(1:M+1);$\\
 \hspace*{-2em}{\scriptsize 14}$  $\\
 \hspace*{-2em}{\scriptsize 15}$  BER = simple_channel(hwin)$\\
 \hspace*{-2em}{\scriptsize 16}$  $\\
 \hspace*{-2em}{\scriptsize 17}$  $\color{mgrey}$% Plot results$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 18}$  [H, $\color{mdarkgrey}$w] = freqz(1, c);$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 19}$  Hwin = freqz(hwin, 1, w);$\\
 \hspace*{-2em}{\scriptsize 20}$  $\\
 \hspace*{-2em}{\scriptsize 21}$  figure, $\color{mdarkgrey}$hold on, box on$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 22}$  plot(w/pi, abs(H).^2, $\color{mdarkgrey}$'LineWidth'$\color{black}$, 2, $\color{mdarkgrey}$'displayname'$\color{black}$, $\color{mdarkgrey}$'H(z)'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 23}$  plot(w/pi, abs(Hwin).^2, $\color{mdarkgrey}$'LineWidth'$\color{black}$, 2, $\color{mdarkgrey}$'displayname'$\color{black}$, $\color{mdarkgrey}$'H_{win}(z)'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 24}$  xlabel($\color{mdarkgrey}$'\omega/\pi'$\color{black}$, $\color{mdarkgrey}$'FontSize'$\color{black}$, 12)$\\
 \hspace*{-2em}{\scriptsize 25}$  ylabel($\color{mdarkgrey}$'Magnitude'$\color{black}$, $\color{mdarkgrey}$'FontSize'$\color{black}$, 12)$\\
 \hspace*{-2em}{\scriptsize 26}$  legend($\color{mdarkgrey}$'-dynamiclegend'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 27}$  saveas(gca, $\color{mdarkgrey}$'../figs/eq_rect_win_mag'$\color{black}$, $\color{mdarkgrey}$'epsc'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 28}$  $\\
 \hspace*{-2em}{\scriptsize 29}$  figure, $\color{mdarkgrey}$hold on, box on$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 30}$  plot(w/pi, unwrap(angle(H)), $\color{mdarkgrey}$'LineWidth'$\color{black}$, 2, $\color{mdarkgrey}$'displayname'$\color{black}$, $\color{mdarkgrey}$'H(z)'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 31}$  plot(w/pi, unwrap(angle(Hwin)), $\color{mdarkgrey}$'LineWidth'$\color{black}$, 2, $\color{mdarkgrey}$'displayname'$\color{black}$, $\color{mdarkgrey}$'H_{win}(z)'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 32}$  xlabel($\color{mdarkgrey}$'\omega/\pi'$\color{black}$, $\color{mdarkgrey}$'FontSize'$\color{black}$, 12)$\\
 \hspace*{-2em}{\scriptsize 33}$  ylabel($\color{mdarkgrey}$'Phase (rad)'$\color{black}$, $\color{mdarkgrey}$'FontSize'$\color{black}$, 12)$\\
 \hspace*{-2em}{\scriptsize 34}$  legend($\color{mdarkgrey}$'-dynamiclegend'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 35}$  saveas(gca, $\color{mdarkgrey}$'../figs/eq_rect_win_phase'$\color{black}$, $\color{mdarkgrey}$'epsc'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 36}$  $\\
 \hspace*{-2em}{\scriptsize 37}$  $\color{mgrey}#%% c) Least-squares method#\color{black}$$\\
 \hspace*{-2em}{\scriptsize 38}$  $\color{mgrey}$% Calculate matrix Q$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 39}$  $\color{mgrey}$% This assumes even symmetry$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 40}$  N = 100;$\\
 \hspace*{-2em}{\scriptsize 41}$  w = linspace(-pi, pi).';$\\
 \hspace*{-2em}{\scriptsize 42}$  d = freqz(1, c, w);$\\
 \hspace*{-2em}{\scriptsize 43}$  $\\
 \hspace*{-2em}{\scriptsize 44}$  Q = zeros(N, M+1); $\color{mgrey}$% initialized$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 45}$  n = 0:M; $\color{mgrey}$% time vector$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 46}$  $#for#$ i = 1:N $\color{mgrey}$% for every frequency wi$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 47}$      Q(i, $\color{mdarkgrey}$:) = exp(-1j*w(i)*n);$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 48}$  $#end#$$\\
 \hspace*{-2em}{\scriptsize 49}$  $\\
 \hspace*{-2em}{\scriptsize 50}$  $\color{mgrey}$% Least-squares filter$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 51}$  hls = pinv(Q)*d;$\\
 \hspace*{-2em}{\scriptsize 52}$  $\\
 \hspace*{-2em}{\scriptsize 53}$  BER = simple_channel(hls)$\\
 \hspace*{-2em}{\scriptsize 54}$  $\\
 \hspace*{-2em}{\scriptsize 55}$  $\color{mgrey}$% Plot results$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 56}$  [H, $\color{mdarkgrey}$w] = freqz(1, c);$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 57}$  Hls = freqz(hls, 1, w);$\\
 \hspace*{-2em}{\scriptsize 58}$  $\\
 \hspace*{-2em}{\scriptsize 59}$  figure, $\color{mdarkgrey}$hold on, box on$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 60}$  plot(w/pi, abs(H).^2, $\color{mdarkgrey}$'LineWidth'$\color{black}$, 2, $\color{mdarkgrey}$'displayname'$\color{black}$, $\color{mdarkgrey}$'H(z)'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 61}$  plot(w/pi, abs(Hls).^2, $\color{mdarkgrey}$'LineWidth'$\color{black}$, 2, $\color{mdarkgrey}$'displayname'$\color{black}$, $\color{mdarkgrey}$'H_{win}(z)'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 62}$  xlabel($\color{mdarkgrey}$'\omega/\pi'$\color{black}$, $\color{mdarkgrey}$'FontSize'$\color{black}$, 12)$\\
 \hspace*{-2em}{\scriptsize 63}$  ylabel($\color{mdarkgrey}$'Magnitude'$\color{black}$, $\color{mdarkgrey}$'FontSize'$\color{black}$, 12)$\\
 \hspace*{-2em}{\scriptsize 64}$  legend($\color{mdarkgrey}$'-dynamiclegend'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 65}$  saveas(gca, $\color{mdarkgrey}$'../figs/eq_ls_mag'$\color{black}$, $\color{mdarkgrey}$'epsc'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 66}$  $\\
 \hspace*{-2em}{\scriptsize 67}$  figure, $\color{mdarkgrey}$hold on, box on$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 68}$  plot(w/pi, unwrap(angle(H)), $\color{mdarkgrey}$'LineWidth'$\color{black}$, 2, $\color{mdarkgrey}$'displayname'$\color{black}$, $\color{mdarkgrey}$'H(z)'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 69}$  plot(w/pi, unwrap(angle(Hls)), $\color{mdarkgrey}$'LineWidth'$\color{black}$, 2, $\color{mdarkgrey}$'displayname'$\color{black}$, $\color{mdarkgrey}$'H_{win}(z)'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 70}$  xlabel($\color{mdarkgrey}$'\omega/\pi'$\color{black}$, $\color{mdarkgrey}$'FontSize'$\color{black}$, 12)$\\
 \hspace*{-2em}{\scriptsize 71}$  ylabel($\color{mdarkgrey}$'Phase (rad)'$\color{black}$, $\color{mdarkgrey}$'FontSize'$\color{black}$, 12)$\\
 \hspace*{-2em}{\scriptsize 72}$  legend($\color{mdarkgrey}$'-dynamiclegend'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 73}$  saveas(gca, $\color{mdarkgrey}$'../figs/eq_ls_phase'$\color{black}$, $\color{mdarkgrey}$'epsc'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 74}$  $\\
 \hspace*{-2em}{\scriptsize 75}$  $\color{mgrey}$% d)$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 76}$  sigma2 = 0.001;$\\
 \hspace*{-2em}{\scriptsize 77}$  P = sigma2/(pi)*trapz(w, abs(Hls).^2) $\\
 \hspace*{-2em}{\scriptsize 78}$  $\color{mgrey}$% Note division by pi instead of 2pi since w is defined in the interval (0,$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 79}$  $\color{mgrey}$% pi)$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 80}$  $\\
 \hspace*{-2em}{\scriptsize 81}$  $\color{mgrey}$% Another way to calculate P$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 82}$  P = sigma2*sum(abs(hls).^2) $\color{mgrey}$% from Parseval's identity$\color{black}$$\\ 
  
\UndefineShortVerb{\$} 
\UndefineShortVerb{\#}