\documentclass{article} %% Better math support: \usepackage{amsmath, amssymb} %% Bibliography style: \usepackage{mathptmx} % Use the Times font. \usepackage{graphicx} % Needed for including graphics. \usepackage{url} % Facility for activating URLs. \usepackage{bigints} \usepackage{fancyhdr} % For customizing headers \usepackage{enumitem} % to be able to enumerate over letters, etc \usepackage{fancyhdr} % Required for custom headers \usepackage{lastpage} % Required to determine the last page for the footer \usepackage{extramarks} % Required for headers and footers \usepackage[usenames,dvipsnames]{color} % Required for custom colors \usepackage{listings} % Required for insertion of code \usepackage{courier} % Required for the courier font \usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template \usepackage{float} %allows to use [H] to force fig locations \usepackage[framed]{mcode} %% Set the paper size to be A4, with a 2cm margin %% all around the page. \usepackage[a4paper,margin=2cm]{geometry} %% textcomp provides extra control sequences for accessing text symbols: \usepackage{textcomp} \newcommand*{\micro}{\textmu} %% Here, we define the \micro command to print a text "mu". %% "\newcommand" returns an error if "\micro" is already defined. \newcommand{\Lim}[1]{\raisebox{0.5ex}{\scalebox{0.8}{$\displaystyle \lim_{#1}\;$}}} %this one puts the text of a limit under the limit writing %% This is an example of a new macro that I've created to save me %% having to type \LaTeX each time. The xspace command provides space %% after the word LaTeX where appropriate. \usepackage{xspace} \providecommand*{\latex}{\LaTeX\xspace} %% "\providecommand" does nothing if "\latex" is already defined. \newcommand*\xoverline[2][0.75]{% this bit allows to make lines over your characters; see problem 13.3 \sbox{\myboxA}{$\m@th#2$}% \setbox\myboxB\null% Phantom box \ht\myboxB=\ht\myboxA% \dp\myboxB=\dp\myboxA% \wd\myboxB=#1\wd\myboxA% Scale phantom \sbox\myboxB{$\m@th\overline{\copy\myboxB}$}% Overlined phantom \setlength\mylenA{\the\wd\myboxA}% calc width diff \addtolength\mylenA{-\the\wd\myboxB}% \ifdim\wd\myboxB<\wd\myboxA% \rlap{\hskip 0.5\mylenA\usebox\myboxB}{\usebox\myboxA}% \else \hskip -0.5\mylenA\rlap{\usebox\myboxA}{\hskip 0.5\mylenA\usebox\myboxB}% \fi} \makeatother %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Start of the document. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \pagestyle{fancy} \rhead{Lewis Guignard EE 102A HW 3 Lab 3 Page \thepage} \cfoot{} \begin{document} \date{\today} \title{\textbf{EE 102A HW 3: Laboratory}} \author{Lewis Guignard} \maketitle \Large % sets the fontsize for all except the section titles \section*{Task 1} \begin{lstlisting} type nconv function [ y, ty ] = nconv(x,tx,h,th) %Approximates a continuous time convolution calculation of x(t) and h(t) % nconv performs a numerical approximation to the % continuous time convolution using matlab’s conv() % function % % [y, ty] = nconv(x,tx,h,th) % % Inputs: % x -- input signal vector % tx -- times of the samples in x % h -- impulse response vector % th -- times of the samples in h % % outputs: % y -- output signal vector, % length(y)= length(x)+length(h)-1 % ty -- times of the samples in y % % The command plot(tx,x,th,h,ty,y) should properly % display your functions. % % Find the indexes of the convoluted function y, and save as ty % y_start = min(tx) + min(th); y_stop = max(tx) + max(th); dt = (max(tx) - min(tx))/(length(tx) - 1); % this finds the delta time ty = y_start:dt:y_stop; T = .01; % Set sampling period (I have arbitrarily chosen .01) % % Compute the convolution (scaled by T); % y = conv(x, h)*T; end % % % % % % % % % % % % % % Plot of problem 2: % % % % % % % % % \end{lstlisting} \ref{fig:1a} \begin{figure}[H] \centering \includegraphics[width=10cm]{Task1} \label{fig:1a} \end{figure} \section*{Task 2A} \begin{lstlisting} dt = 0.01; t = -.5:dt:0.5; x = [ones(1,101)]; x = x/(sum(x)*dt); [y,ty] = nconv(x,t,x,t); plot(ty,y,t,x) legend('y','x') title('Assignment 3 Task 2') xlabel('Time (s)') ylabel('Amplitude') \end{lstlisting} \ref{fig:Task2A} \begin{figure}[H] \centering \includegraphics[width=14cm]{Task2A} \label{fig:Task2A} \end{figure} \newpage \section*{Task 2B} \begin{lstlisting} [y,ty] = nconv(y,ty,x,t); plot(ty,y,t,x) legend('rect*rect*rect','rect') title('Assignment 3 Task 2B rect*rect*rect') xlabel('Time (s)') ylabel('Amplitude') \end{lstlisting} \ref{fig:Task2B} \begin{figure}[H] \centering \includegraphics[width=16cm]{Task2B} \label{fig:Task2B} \end{figure} \newpage \section*{Task 2C} \begin{lstlisting} %%%%%%%% make a function to do these N convolutions type multiNConv function [ y, ty ] = multiNConv(x, t, N ) %This function calculates multiple convolutions in a row! % will repeat a convolution of a function x on itself N times y = x; ty = t; for i = 1:N [y, ty] = nconv(y, ty, x, t); end % Normalize results y = sqrt(N)*y; ty = ty/sqrt(N); end [y_40_norm, ty_40_norm] = multiNConv(x, t, 40); [y_20_norm, ty_20_norm] = multiNConv(x, t, 20); [y_10_norm, ty_10_norm] = multiNConv(x, t, 10); [y_3_norm, ty_3_norm] = multiNConv(x, t, 3); sigma = .2915; plot(ty,g,ty_40_norm,y_40_norm,ty_20_norm,y_20_norm,ty_10_norm,y_10_norm,ty_3_norm,y_3_norm); legend('g','y2 N = 40','y2 N = 20','y2 N = 10','y2 N = 3') ylabel('Amplitude') xlabel('Time (s)') title('Assignment 3 Task 2C N convolutions of rect and a bell curve') \end{lstlisting} \ref{fig:Task2C} \begin{figure}[H] \centering \includegraphics[width=14cm]{Task2C} \label{fig:Task2C} \end{figure} \newpage \section*{Task 2Di} \begin{lstlisting} t = -.5:dt:.5; x = [ones(1,20) zeros(1,61) ones(1,20)]; x = x/(sum(x)*dt); %normalize x; g = 1/(sqrt(2*pi)*sigma)*exp(-(t.^2)/(2*sigma^2)); sigma = .4091; [y_40_norm, ty_40_norm] = multiNConv(x, t, 40); [y_20_norm, ty_20_norm] = multiNConv(x, t, 20); [y_10_norm, ty_10_norm] = multiNConv(x, t, 10); [y_3_norm, ty_3_norm] = multiNConv(x, t, 3); plot(t,g,ty_40_norm,y_40_norm,ty_20_norm,y_20_norm,ty_10_norm,y_10_norm,ty_3_norm, y_3_norm); title('Task 2Di Multiple N' ) legend('g','y2 N = 40','y2 N = 20','y2 N = 10','y2 N = 3') xlabel('time (s)') ylabel('amplitude') \end{lstlisting} \begin{figure}[H] \centering \includegraphics[width=14cm]{Task2Di} \label{fig:Task2Di} \end{figure} \newpage \section*{Task 2Dii} \begin{lstlisting} %%%%%%%%%% Make a function to find convergence and N type multiNConvUntilConvergence function [ y2, ty2, N ] = multiNConvUntilConvergence( x,t,g, sigma ) %This function performs multiNConvolutions on x until the test requirement %is met % test requirement is when max(y2 - g) < .01 y2 = x; ty2 = t; N = 1; while max(y2 - g) >= .01 [y2, ty2] = multiNConv(x, t, N); % we re-calculate g to get the length of 'g' the same as y2 (ty2 % changes) g = 1/(sqrt(2*pi)*sigma)*exp(-(ty2.^2)/(2*sigma^2)); N = N + 1; end end [y2, ty2,N] = multiNConvUntilConvergence(x, t, g, 0.4091 ); plot(t,g,ty2, y2) axis([-1,1,.7,1.1]); title('Task 2Dii Convergence of y2 and g' ) legend('g','y2') xlabel('time (s)') ylabel('amplitude') N N = 53 \end{lstlisting} \begin{figure}[H] \centering \includegraphics[width=10cm]{Task2Dii} \label{fig:Task2Dii} \end{figure} \end{document}