DOC PREVIEW
PSU EE 351 - EE351 - MATLAB

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Some useful discrete‐time signals/systems MATLAB commands One of the biggest uses of MATLAB is to perform simulation/testing of discrete‐time systems. Some MATLAB commands that you will find useful are briefly described below. The on‐line help in MATLAB will provide more detailed information if you need it. Setting up the system model in MATLAB Assuming a discrete‐time system model with transfer function 00()()()MiiiNiiibzBzHzAzaz or alternately (in difference equation form) 01 2 01[] [ 1] [ 2] [ ] [] [ 1] [ ]NMayn ayn ayn a yn N bxn bxn b xn M     the system information is stored in MATLAB as 2 vectors: b012[...]Mbbbb & a012[ ... ]Naaa a Note: The coefficients are usually scaled so that 0a= 1 without loss of generality. For FIR systems, vector a=1 (i.e. 0a= 1 and all other coefficients = 0) and vector b is equivalent to the impulse response vector h. i.e. h012[...]Mbbbb. filter command The pre‐defined MATLAB function filter is used for generating the output of a causal difference equation (recursive or non‐recursive) given the equation parameters and the input signal. The format for this command is as follows: y=filter(b,a,x) ‐‐ The input signal in vector x is processed by the transfer function (or difference equation) described by vectors b and a, and the output is written to vector y. The system coefficients are scaled internally so that first coefficient of vector a is normalized to 1. The output can be plotted using plot (smooth curve) or stem (discrete points). The number of output points calculated will always be equal to the number of input points (i.e. length(y) = length(x)). If you want y to be longer, you need to zero pad vector x using the zeros function. y=filter(b,a,x,z)—This variation is used if there are initial conditions on the difference equation. The vector z is calculated from initial conditions on the output using the filtic command: z=filtic(b,a,yic,xic), where yic = [y[-1] y[-2] y[-3] …] and xic=[x[-1] x[-2] x[-3] …]. conv command The pre‐defined MATLAB function conv is used for generating the output of a causal non‐recursive difference equation given the impulse response and the input signal. The format of the command is as follows: y=conv(x,h)— The input signal in vector x is convolved with the impulse response in vector h and the output is written to vector y. The number of output points calculate d is always length(x)+length(h)-1. The conv command does not take initial conditions into account. The conv command is not well‐suited for recursive systems because the impulse response for recursive systems is infinite length. freqz command The pre‐defined MATLAB function freqz is used for generating frequency response data fo r a discrete‐time system. The format of the command is as follows: [H,W]=freqz(b,a,n) ‐‐ The frequency response of the system described by vectors b and a is calculated and stored in vector H. Input variable n (a scalar) determines the number of frequency points to calculate and output vector W contains the discrete‐time frequencies (Ω) at which the DTFT is calculated. The frequency response data is calculated at equi‐spaced frequency points in the range [0, π). Adding the text ‘whole’ as a 4th input field causes the frequency response to be calculated in the range [0, 2π). The discrete‐time frequency variable Ω (stored in vector W) (in rad/sample) can be changed to other frequency variables (F, f, or ) as desired via a simple MATLAB command. The most useful frequency variable for plotting is probably the continuous‐time frequency variable f, with units of Hz. It is calculated from W (Ω) using: f= W*Fs/(2*pi), where variable Fs is the sampling frequency in Hz (samples/sec). An alternative format for this function is [H,f] = freqz(b,a,n,Fs). If you use this format, then the frequency variable transformation from Ω to f is done for you automatically. Another alternate format for this function is H = freqz(b,a,W). In this format, the discrete‐time frequencies at which the frequency response is to be evaluated are provided by the user in vector W. In this format, it is assumed that the frequencies in W are given in rad/sample. Once the frequency response data is calculated, you can then plot it as follows: frequency response magnitude: plot(W,abs(H)) or plot(f,abs(H)) frequency response phase: plot(W,angle(H)) or plot(f,angle(H)) If the system’s impulse response h[n] (stored as vector h) is given instead of the system’s difference equation, the format for this function is [H,w]=freqz(h,1,n) or [H,F]=freqz(h,1,n,Fs). Recall that MATLAB differentiates between upper‐ and lower‐case variable names so h and H are different. The freqz command can also be used to calculate the frequency content of a discrete time signal (stored in vector x) by using [X,w]=freqz(x,1,n) or [X,F]=freqz(x,1,n,Fs). fft command The pre‐defined MATLAB function fft is used to estimate the frequency content of a discrete‐time signal via the discrete Fourier Transform (DFT). It can also be used to calculate discrete‐time Fourier Series (DTFS) coefficients for a periodic discrete‐time signal. X=fft(x)—The N‐point DFT of input signal is calculated, where N is the length of the input data sequence x. Alternately, if vector x is one period of a periodic discrete‐time signal, then X/N is equivalent to the DTFS coefficients DN. X=fft(x, N)— In this format, the input sequence x (of length < N) is automatically zero‐padded to length N prior to calculating the N‐point DFT. Unlike the freqz command, the frequency values themselves are not generated by the fft command, so they need to be generated explicitly. The kth entry in vector X corresponds to discrete‐time frequency 2( 1)kN. The frequency range is [0, 2 ‐ 2N], with a frequency spacing of 2N. The command fftshift can be used to chan ge the frequency range to [‐, ‐2N] (if N is even) or [‐+N,‐N] (if N is odd). Other useful discrete‐time signals and systems commands zplane(b,a) ‐‐ This function generates a pole/zero plot of the system described by vectors b and a. The plot is generated automatically. x = wavread(‘<filename.wav>’) – This function reads a standard .wav file into MATLAB and stores the data in


View Full Document
Download EE351 - MATLAB
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view EE351 - MATLAB and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view EE351 - MATLAB 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?