Вы находитесь на странице: 1из 18

# Computer Assignment #1

## DPS Professor Sankar Computer Assignment 1

Ilian (William) A. Deering U#56849438 2 October 2012

Problem 1
Overview MatLab is versatile computer program that allows users to perform different level of simulation. In particular, signal simulation is the main purpose of problem 1. This exercise touches on the subject of discrete signal generation using the MatLab interface in order to achieve a hands on experience on digital signal processing. Euler's identity together with the investigation of complex discrete signals are the main aim of this exercise. Objective The main objective of this exercise is to introduce us to the generation of basic discrete signals using MatLab. In particular, three different complex signals are investigated. Moreover, their corresponding real and imaginary components are plotted in order to achieve a better understanding of their responses as system's inputs. Euler's identity is also investigated, as it allows easy access to the real and imaginary parts of a complex signal, aiding in the study of more general functions. Procedure Part (a) of this exercise required us to use Euler's Identity to generate a complex exponential. Furthermore, the results were plotted together with the real and imaginary parts of the signal over the range 0 n 24. The following graph shows the results obtained.

The real and imaginary components of the signals can be observed in this graph. As expected, they both depict discrete sinusoidal functions. Moreover, it is clear that these signals do not oscillate infinitely, but rather converge as the number of samples increases.

Another point of interest in this exercise was to investigate the graph of the real versus imaginary parts of the signal generated in part (a). Hence the following graph:

The last part for exercise 1 required the plotting of two different signals. Also, the real and imaginary components of these signals were graphed in order to gain better understanding. The following figures are representative of the results.

Again, this last set of graphs show a complex signal for which the real part is simply an increasing sinusoidal wave. Interpretation of the results It is clear from the procedure that the main objective of this exercise was to introduce us to the generation of discrete signals and the evaluation of each component in order to achieve a complete understanding of how signals behave in real life. Also, here I introduce the MatLab code for this exercise, on which I added personal comments of my interpretation on the code. MatLab code
% Problem 1 % % % % For part (a) of this problem we used Euler's identity in order to observe the real and imaginary components of a signal. The following code aided in the process and reproduced two graphs containing the required response.

n = 0:24; % The purpose of this is to indicate at how many samples the signal is investigated. f = (0.9).^(n).*exp(i*n*pi/4); % This is the discrete function that we need to analyse. subplot(211) % This allows us to graph the signal. stem(n, real(f)) % This portion of the code specifies the indices of the real component of the signal. title('Real Part'), xlabel('Index (n)') % This allows us to define parameters for

the axes of the graph. subplot(212) stem(n, imag(f)) % This is exactly as above, but now we use it to plot the imaginary component. title('Imaginary Part'), xlabel('Index (n)') % '' % Part (b) of problem 1 required us to graph the the imaginary part versus % real part of the signal in part (a). The following code allowed us to % obtain the desired graph. subplot(3,1,3) plot (real(f), imag(f)) % This is simply a plot of the real vs the imaginary components. title('Real vs Imaginary') xlabel('Real (n)');ylabel('Imaginary (n)') % Part (c) of problem 1 consisted of graphing two different signals and % investigate the imaginary component as well as the real component. The % following two codes clearly allowed us to achieve this. n = 0:32; % The process for these two graphs is exactly as that for part (a) f = 3.*cos(n*pi/8)+4.*i.*sin(n*pi/8); subplot(211) stem(n, real(f)) title('Real Part'), xlabel('Index (n)') subplot(212) stem(n, imag(f)) title('Imaginary Part'), xlabel('Index (n)') n = 0:32; f = (1.1).^(n).*cos(n*pi/10+pi/4); subplot(211) stem(n, real(f)) title('Real Part'), xlabel('Index (n)') subplot(212) stem(n, imag(f)) title('Imaginary Part'), xlabel('Index (n)')

Problem 2. Overview This exercise mainly introduces us to the concept of difference equations and how they can be implemented to use as filters. The concept behind an infinite impulse response was crucial in understanding the purpose of this exercise. Using MatLab, difference equations can be represented by vectors defining the coefficients of the input as well as the response signal. Objective The purpose of this exercise was to deliver a formulation, a code, that can easily allow us to solve difference equations in order to study their response. Moreover, the responses were representative of filtering behaviors, and five different kinds of filters were observed by solving a particular difference equation. Procedure The first step in achieving the goal of this problem, was to solve a difference equation and observe its response. The following figure depicts the response of the analyzed system:

Something particular about this signal is that it was observed for an index of 100 samples. It is clear that the frequency response overshoots and eventually converges to zero. What is interesting about this response, however, is its phase response together with its low-pass filtering behavior. The following graphs make this clear:

## Here we observe the phase response of the signal.

The following picture is yet more interesting: Over one period, this frequency representation depicts the clear behavior of a low-pass filter. Again, this demonstrate the usefulness of MatLab in furnishing a representation of useful filtering behavior by pure application of difference equations and their response behavior. Moreover, the pole, zero plot also can be obtain, which is useful in understanding the position of a

## system's poles together with its zeros.

From this figure, it is clear that this system possess two zeros together with two poles on the right hand side of the complex plane. It follows that four other difference equations were analyzed using MatLab in order to observe their filtering behavior.

This figure shows the frequency response of a difference equation that behaves as a band stop filter, as shown by the following figure:

Similarly, for three more difference equations, the frequency response together with their filtering behavior will be listed.

This impulse response together with the filter behavior, depict a band-pass filter. However, I want to point out that initially I believed this to be a high pass filter, until I studied its period and found out that in reality over one period this is a band-pass filter.

However, these two graphs obtained from a different difference equation are a clear representation of what a high pass filter would behave like.

Lastly, the final difference equation delivers the behavior of an all-pass filter. Interpretation of results It is clear that the purpose of this problem was to introduce us to the filtering behavior of the response

to certain difference equations. By analyzing five different equations we obtained the behavior of five different filtering schemes which are rather useful and common in practical applications. Similarly, the ways of solving difference equations was aided by a MatLab code, which serves as a template to other involved and high level designs. The following MatLab code was used to develop these graphs. Once again, I have added my personal comments to the code in order to enhance my understanding of MatLab. MatLab code
% This function is defined such that we are able to solve a difference % equation by simply defining the vector a, b, and value L, which serve as % the arguments of y=de. function y=de(b,a,L) index = 0:(L-1); % generate an impulse imp = zeros(L,1); % vector imp with all zero elements imp (1) = 1; % imp(n=0) = 1 x = imp; y = filter (b,a,x); stem (index,y) end % % a b L These are the vectors defining the coefficients for the difference equation. = [1 -1.6*cos(pi/8) 0.64]; % coefficients from the difference equation = [1 0.5 0]; = 101;

% This will graph the solution to the difference equation. figure y = de(b,a,L); [H,W] = freqz (b,a,512,'whole'); title('Frequency Response'), ylabel('y[n]'), xlabel('Index (n)') % This piece of code will allow us to observe the phase response of the % solution. figure plot(W,angle(H)) title('Phase Response'), ylabel('Angle'), xlabel('Frequency') % This part of the code will provide a figure representing the magnitude of % the response. Moreover, it is clear that this response is that of a low-pass % filter. figure plot(W, abs(H)) title('--- filter behaviour'), ylabel('Magnitude'), xlabel('Frequency') % This last piece was used in order to obtain the Pole Zero Plot of the % system. [z, p, k] = tf2zp(b,a); % b and a are the coefficients from the difference eqn. zplane(z, p)

Problem 3.

Overview The goal of this exercise is to introduce the student to the concept behind the discrete time Fourier transform. Moreover, forward and inverse Fourier transforms are studied in this problem. Objective This problem aims to study the concepts behind the discrete time Fourier transform. Moreover, it shows how a signal can be represented by its Fourier transform in order to extract valuable data such as frequency response and power, which are no easily obtained via time domain analysis. Procedure This problem was rather straight forward. First the Fourier transform of a signal was developed by hand. Furthermore, we used MatLab to develop a code that can easily find the Fourier transform of a discrete signal, which may be finite in length, using the fast Fourier transform algorithm. Consequently, two figures were developed showing the result from taking the Fourier transform of a signal together with its phase response.

This figure shows the response of the so-called asinc function and its phase response. Nevertheless, it

is clear that its zeros happen at equally distributed intervals, unlike when the length of the signal is odd. The following picture represents the findings of taking the Fourier transform of a signal of odd length.

It is obvious that the zeros are not distributed evenly, and its phase response changes dramatically, in comparison with an evenly distributed signal. Interpretation of the results This part of the project seems to touch over the notion of a transform and its inverse in order to extract crucial data from a system. Among the many benefits of studying signals in the frequency domain are the extraction of the zeros and poles of a system, which can give a good understanding of system stability as well as signal power and frequency response. The following MatLab code was used to create these graphs. MatLab code
% This code basically calls the discrete time fourier transform as an % operator. Moreover, this will be used together with the following code in % order to generate the transform of a signal. function [H,W] = dtft(h,N) % This function calculates DTFT at N equally spaced frequencies % Usage H = dtft(h,N) % h : finite-length input vector, whose length is L % N : number of frequencies for evaluation over [ -pi, pi )

% ==> constraint : N >= L % % H : DTFT values (complex) % W : (2nd output) vector of frequencies where DTFT is computed % N = fix(N); L = length(h); h = h(:); %<-- for vectors ONLY !!! if (N < L) error(' DTFT : # data samples cannot exceed # freq samples') end W = ( 2* pi / N ) * [ 0 : (N-1) ]'; mid = ceil( N / 2 ) + 1; W(mid : N) = W( mid : N ) - 2 * pi; % <-- move [pi, 2pi) to [pi, 0) W = fftshift(W); H = fftshift( fft ( h, N ) ); % < -- move negative freq components % This piece of % discrete time format compact, a (1:10)=ones evaluate. code basically allows us to evaluate and investigate the fourier transform of a discrete signal. subplot (111) % This will aid in graphing the result. ; a (11:20)= zeros; % This defines the length of the function to be % the matlab file containing the function dtft

## [X, W] = dtft ( a, 128);

% This subplot simply depicts the magnitude response together with a normalised frequency. subplot (211), plot ( W / 2 / pi, abs(X) ); grid, title (' MAGNITUDE RESPONSE') xlabel (' NORMALIZED FREQUENCY'), ylabel (' | H(w) | ') % Similarly, this will show the phase response of the signal after taking % the discrete time fourier transform. subplot (212), plot( W / 2 / pi, 180 / pi * angle(X) ); grid, xlabel(' NORMALIZED FREQUENCY'), ylabel (' DEGREES ') title(' PHASE RESPONSE ') % Now, I will use the same code to generate a slighly longer signal format compact, subplot (111) % This will aid in graphing the result. a (1:15)=ones ; a (16:30)= zeros; % This defines the length of the function to be evaluate. [X, W] = dtft ( a, 128); % the matlab file containing the function dtft

% This subplot simply depicts the magnitude response together with a normalised frequency. subplot (211), plot ( W / 2 / pi, abs(X) ); grid, title (' MAGNITUDE RESPONSE') xlabel (' NORMALIZED FREQUENCY'), ylabel (' | H(w) | ') % Similarly, this will show the phase response of the signal after taking % the discrete time fourier transform. subplot (212), plot( W / 2 / pi, 180 / pi * angle(X) ); grid, xlabel(' NORMALIZED FREQUENCY'), ylabel (' DEGREES ') title(' PHASE RESPONSE ')