% 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}#%% Template for the echo cancelling problem#\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}$  fs = 8e3;                          $\color{mgrey}$% sampling frequency (Hz)$\color{black}$$\\
 \hspace*{-1.6em}{\scriptsize 5}$  f = 400;                           $\color{mgrey}$% sinusoid frequency (Hz)$\color{black}$$\\
 \hspace*{-1.6em}{\scriptsize 6}$  Tdur = 0.2;                        $\color{mgrey}$% pulse duration (s)$\color{black}$$\\
 \hspace*{-1.6em}{\scriptsize 7}$  x = pulse(f,Tdur,fs);              $\color{mgrey}$% Generates a pulse of frequency f, duration Tdur, and sampling frequency fs$\color{black}$$\\
 \hspace*{-1.6em}{\scriptsize 8}$  x = [x zeros(1, 2*length(x))];     $\color{mgrey}$% zero pad for processing$\color{black}$$\\
 \hspace*{-1.6em}{\scriptsize 9}$  n = 0:length(x)-1;                 $\color{mgrey}$% discrete-time vector$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 10}$  t = n/fs;                          $\color{mgrey}$% continuous-time vector$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 11}$  $\\
 \hspace*{-2em}{\scriptsize 12}$  plot(t, $\color{mdarkgrey}$x);                 $\color{black}$$\color{mgrey}$% Plot signal$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 13}$  xlabel($\color{mdarkgrey}$'Time (s)'$\color{black}$) $\\
 \hspace*{-2em}{\scriptsize 14}$  ylabel($\color{mdarkgrey}$'Amplitude'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 15}$  title($\color{mdarkgrey}$'Original pulse: 400-Hz sinusoid, 200-ms Hann window'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 16}$  sound(x, $\color{mdarkgrey}$fs);               $\color{black}$$\color{mgrey}$% Play the sound$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 17}$  $\\
 \hspace*{-2em}{\scriptsize 18}$  $\color{mgrey}#%% Your code goes here#\color{black}$$\\
 \hspace*{-2em}{\scriptsize 19}$  alpha = 0.5;$\\
 \hspace*{-2em}{\scriptsize 20}$  Techo = 0.1;$\\
 \hspace*{-2em}{\scriptsize 21}$  N = Techo*fs;$\\
 \hspace*{-2em}{\scriptsize 22}$  $\\
 \hspace*{-2em}{\scriptsize 23}$  $\color{mgrey}$% Echo generation system 1$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 24}$  a1 = 1;$\\
 \hspace*{-2em}{\scriptsize 25}$  b1 = zeros(1, N+1); $\color{mgrey}$% b1 has N+1 coefficients$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 26}$  b1(1) = 1;$\\
 \hspace*{-2em}{\scriptsize 27}$  b1(N+1) = alpha;$\\
 \hspace*{-2em}{\scriptsize 28}$  $\\
 \hspace*{-2em}{\scriptsize 29}$  y1 = filter(b1, a1, x);$\\
 \hspace*{-2em}{\scriptsize 30}$  figure$\\
 \hspace*{-2em}{\scriptsize 31}$  plot(t, $\color{mdarkgrey}$y1);                 $\color{black}$$\color{mgrey}$% Plot signal$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 32}$  xlabel($\color{mdarkgrey}$'Time (s)'$\color{black}$, $\color{mdarkgrey}$'FontSize'$\color{black}$, 12) $\\
 \hspace*{-2em}{\scriptsize 33}$  ylabel($\color{mdarkgrey}$'Amplitude'$\color{black}$, $\color{mdarkgrey}$'FontSize'$\color{black}$, 12)$\\
 \hspace*{-2em}{\scriptsize 34}$  saveas(gca, $\color{mdarkgrey}$'../figs/hw01q2_echoed1'$\color{black}$, $\color{mdarkgrey}$'epsc'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 35}$  sound(y1, $\color{mdarkgrey}$fs);               $\color{black}$$\color{mgrey}$% Play the sound$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 36}$  $\\
 \hspace*{-2em}{\scriptsize 37}$  $\color{mgrey}$% Echo generation system 2$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 38}$  a2 = zeros(1, N+1);         $\color{mgrey}$% a1 has N+1 coefficients$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 39}$  a2(1) = 1;                  $\\
 \hspace*{-2em}{\scriptsize 40}$  a2(N+1) = -alpha;$\\
 \hspace*{-2em}{\scriptsize 41}$  b2 = 1;$\\
 \hspace*{-2em}{\scriptsize 42}$  $\\
 \hspace*{-2em}{\scriptsize 43}$  y2 = filter(b2, a2, x);$\\
 \hspace*{-2em}{\scriptsize 44}$  figure$\\
 \hspace*{-2em}{\scriptsize 45}$  plot(t, $\color{mdarkgrey}$y2);                 $\color{black}$$\color{mgrey}$% Plot signal$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 46}$  xlabel($\color{mdarkgrey}$'Time (s)'$\color{black}$, $\color{mdarkgrey}$'FontSize'$\color{black}$, 12) $\\
 \hspace*{-2em}{\scriptsize 47}$  ylabel($\color{mdarkgrey}$'Amplitude'$\color{black}$, $\color{mdarkgrey}$'FontSize'$\color{black}$, 12)$\\
 \hspace*{-2em}{\scriptsize 48}$  saveas(gca, $\color{mdarkgrey}$'../figs/hw01q2_echoed2'$\color{black}$, $\color{mdarkgrey}$'epsc'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 49}$  sound(y2, $\color{mdarkgrey}$fs);               $\color{black}$$\color{mgrey}$% Play the sound$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 50}$  $\\
 \hspace*{-2em}{\scriptsize 51}$  $\color{mgrey}#%% Echo cancellation#\color{black}$$\\
 \hspace*{-2em}{\scriptsize 52}$  $\color{mgrey}$% System 1$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 53}$  xrec1 = filter(a1, b1, y1); $\color{mgrey}$% We just need to switch the coefficients (a1, b1)$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 54}$  figure$\\
 \hspace*{-2em}{\scriptsize 55}$  plot(t, $\color{mdarkgrey}$xrec1);                 $\color{black}$$\color{mgrey}$% Plot signal$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 56}$  xlabel($\color{mdarkgrey}$'Time (s)'$\color{black}$, $\color{mdarkgrey}$'FontSize'$\color{black}$, 12) $\\
 \hspace*{-2em}{\scriptsize 57}$  ylabel($\color{mdarkgrey}$'Amplitude'$\color{black}$, $\color{mdarkgrey}$'FontSize'$\color{black}$, 12)$\\
 \hspace*{-2em}{\scriptsize 58}$  saveas(gca, $\color{mdarkgrey}$'../figs/hw01q2_echoed_rec1'$\color{black}$, $\color{mdarkgrey}$'epsc'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 59}$  sound(xrec1, $\color{mdarkgrey}$fs);               $\color{black}$$\color{mgrey}$% Play the sound$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 60}$  $\\
 \hspace*{-2em}{\scriptsize 61}$  $\color{mgrey}$% System 2$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 62}$  xrec2 = filter(a2, b2, y2);$\\
 \hspace*{-2em}{\scriptsize 63}$  figure$\\
 \hspace*{-2em}{\scriptsize 64}$  plot(t, $\color{mdarkgrey}$xrec2);                 $\color{black}$$\color{mgrey}$% Plot signal$\color{black}$$\\
 \hspace*{-2em}{\scriptsize 65}$  xlabel($\color{mdarkgrey}$'Time (s)'$\color{black}$, $\color{mdarkgrey}$'FontSize'$\color{black}$, 12) $\\
 \hspace*{-2em}{\scriptsize 66}$  ylabel($\color{mdarkgrey}$'Amplitude'$\color{black}$, $\color{mdarkgrey}$'FontSize'$\color{black}$, 12)$\\
 \hspace*{-2em}{\scriptsize 67}$  saveas(gca, $\color{mdarkgrey}$'../figs/hw01q2_echoed_rec2'$\color{black}$, $\color{mdarkgrey}$'epsc'$\color{black}$)$\\
 \hspace*{-2em}{\scriptsize 68}$  sound(xrec1, $\color{mdarkgrey}$fs);               $\color{black}$$\color{mgrey}$% Play the sound$\color{black}$$\\
  
\UndefineShortVerb{\$} 
\UndefineShortVerb{\#}