Dsp Manual Hamdard

Embed Size (px)

Citation preview

  • 8/10/2019 Dsp Manual Hamdard

    1/52

    Approved By: Engr. IR Rao

    Compiled By: Engr. Hira Waris

    Lab Manual

    Digital Signal Processing

    Submitted To:-------------------------------

    Submitted By:-------------------------------

    Registeration No.:-------------------------

  • 8/10/2019 Dsp Manual Hamdard

    2/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 1 Compiled By: Engr. Hira Waris

    TABLE OF CONTENTS

    LAB PAGE

    1.Introduction to MATLAB and Basic Signals 2

    2. Time Domain Analysis of LTI Systems 7

    3. Frequency Domain Analysis of LTI System 11

    4. System Analysis using Z-Transform 14

    5. Conversion from Continuous to Discrete Time Signal(Sampling) and effects of under Sampling (Aliasing) 17

    6. Realization of Digital Filters (IIR and FIR) 22

    7. IIR Filter Design and Analysis using FDATool and

    Script writing Techniques of MATLAB 24

    8. FIR Filter Design and Analysis using FDATool andScript writing Techniques of MATLAB 32

    9. Introduction to Texas InstrumentsTMS320c6713 DSP starter kit (DSK) DigitalSignal Processing Board 42

    10. Sampling in CCS & C6713 49

    11. FIR FilterDesigning inCCS 5012. IIR Filter Designing in CCS 51

  • 8/10/2019 Dsp Manual Hamdard

    3/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 2 Compiled By: Engr. Hira Waris

    LAB#01

    Introduction to MATLAB and Basic Signals

    MATLAB is the most popular tool used for Digital Signal Processing. It provides one of the strongest environments forstudy and simulation of the real-world problems and their solutions, especially in the field of engineering.

    MATLAB (abbreviation for Matrix Laboratory) is a matrix based system which is used for Engineering and Mathematicalcalculations. It integrates computation, visualization, programming to use environment where problems and solutions areexpressed in familiar mathematical notation. It is a kind of language which is designed to do matrix manipulations. Allvariables used in MATLAB are matrices. It means that MATLAB contains only one data type and a matrix or a rectangulararray of numbers. MATLAB contains a large set of routines to obtain graphical outputs. There are many predefinedfunctions in MATLAB which are called by the user to solve many different types of problems.

    Definition of variables

    Variables are assigned numerical values by typing the expression directly, for example, typing

    a = 1+2; yields: a = 3;

    The answer will not be displayed when a semicolon is put at the end of an expression, for example type

    a = 1+2;

    MATLAB utilizes the following arithmetic operators:

    + addition

    - subtraction

    * multiplication

    / division

    ^ power operator

    ' transpose

    If your expression does not fit on one line, use an ellipsis (three or more periods at the end of the line) and continue on thenext line.

    c = 1+2+3+...5+6+7;

    Pre defined functions in Matlab

    There are also a number of predefined functions that can be used when defining a variable. Some common functions thatare used in this text are:

  • 8/10/2019 Dsp Manual Hamdard

    4/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 3 Compiled By: Engr. Hira Waris

    absmagnitude of a number (absolute value for

    real numbers)

    angle Angle of a complex number, in radians

    cos cosine function, assumes argument is inradians

    sin sine function, assumes argument is in radians

    exp exponential function

    Definition of Matrices

    MATLAB is based on matrix and vector algebra; even scalars are treated as 11 matrices. Therefore, vector and matrixoperations are as simple as common calculator operations.

    M=[1 2 4; 3 6 8];

    creates the matrix.

    There are a number of special matrices that can be defined:null matrix:

    M=[ ];

    nm matrix of zeros:

    M=zeros(n,m);

    nm matrix of ones:

    M=ones(n,m);

    nn identity matrix:

    M=eye(n);

    Operations that need to be performed element-by-element can be accomplished by preceding the operation by a ".".

    M-FILES

    M-files are macros of MATLAB commands that are stored as ordinary text files with the extension "m", that isfilename.m. An M-file can be either a function with input and output variables or a list of commands. MATLAB requiresthat the M-file must be stored either in the working directory or in a directory that is specified in the MATLAB path list.

    All variables used in a MATLAB function are local to that function only. Variables which are used in a script m-file whichis not a function are all global variables.

  • 8/10/2019 Dsp Manual Hamdard

    5/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 4 Compiled By: Engr. Hira Waris

    PLOTTING GRAPHS

    Commands: plot, xlabel, ylabel, title, grid, axis, axes, stem, subplot, zoom, hold

    BASIC SIGNALS

    UNIT IMPULSE

    =

    =else

    nn

    ;0

    0;1][d

    ==-

    else

    nnnn;0;1][

    0

    0d

    UNIT STEP

    =else

    nnu

    ;0

    0;1][

    =-else

    nnnnu

    ;0

    ;1][ 00

    HOME TASKS:

    PROBLEM 1:

    Implement a function for generating and plotting

    ][][ 0nnmnx -= d bna Try it for

    (i)

    n0 = 5, m = 0.9, a = 1, b = 20(ii)

    n0 = -7, m = 4.5, a = -10, b = 0

    -10 -5 0 5 100

    0.5

    1

    -10 -5 0 5 100

    0.5

    1

  • 8/10/2019 Dsp Manual Hamdard

    6/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 5 Compiled By: Engr. Hira Waris

    PROBLEM 2:

    Implement a function for generating and plotting

    ][][ 0nnmunx -= bna You can implement above signal by modifying function in Problem 1.Try it for

    (i)

    n0 = 10, m = 1.9, a = 1, b = 20(ii)

    n0 = -7, m = 1.8, a = -20, b = 20

    PROBLEM 3:

    Generate and plot

    PROBLEM 4:

    Consider a continuous time signal )()( q+= tACostx . We can sample a continuous time signal at equally spaced time

    instants nTsT= and get a discrete time signal )(][ nTsxnx = . The individual values of x[n] are called samples ofcontinuous time signal. The fixed time interval between samples, Ts, can also be expressed as a fixed sampling rate, Fs, insamples per second.

    s

    sT

    F1

    = ; samples / second

    If we sample )()( qw += tACostx using this approach, then by using nTst= ; we get

    )()()( qw +== nTsACosnTsxnx = )(^

    qw +nACos .

    Here we have definedFs

    Ts w

    ww ==

    ^

    .

    The signal x[n] is a discrete time cosine signal, and^

    w is its discrete time frequency. We use hat over wto denote that this isa new frequency variable. It is a normalized version of the continuous time radian frequency with respect to the samplingfrequency.

    a.

    Generate and plot the signal )()( q+= tACostx with the following values A=3, Frequency=100 Hz, t = -0.01: 0.00001: 0.02and q= 0.

    b.

    Generate and plot the Discrete time signal x[n] from the Continuous time signal x(t) using values in part (A) .Usethe sampling frequency Fs=2000.

    c.

    Repeat part (B) for Fs=500.

    NOTE: All the plots should be in the same window (use subplot command for this purpose)

  • 8/10/2019 Dsp Manual Hamdard

    7/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 6 Compiled By: Engr. Hira Waris

    PROBLEM 5:

    Implement and plot the following equation.

    ]3[4

    0

    lnAl

    l=

    -d

    The values are A0=2 , A1=4 , A2=6 , A3=8 , A4=10 and 155 - n .

    PROBLEM 6:

    Write MATLAB coding for plotting the following Continuous Time Signals in same window. Use the value of

    001.0=st and ss ttt --= 2::2 : .

  • 8/10/2019 Dsp Manual Hamdard

    8/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 7 Compiled By: Engr. Hira Waris

    LAB#02

    Time Domain Analysis of LTI Systems

    Introduction

    Mathematically, a discrete-time system is described as an operator T[.] that takes a sequencex(n) called excitation and transforms it into another sequence y(n) (called response). Discretetime systems can be classified into two categories i) LTI systems ii) NON-LTI systems. Adiscrete system T[.] is a linear operator L[.] if and only if L[.] satisfies the principle ofsuperposition, namely

    L[a1x1(n) + a2x2(n)] = a1L[x1(n)] + a2Lx2(n)] and

    A discrete system is time-invariant if

    Shifting the input only causes the same shift in the output

    A system is said to be bounded-input bounded-output(BIBO) stable if every bounded input

    produces a bounded output.

    An LTI system is BIBO stable if and only if its impulse response is absolutely summable.

    A system is said to be causal if the ouput at index n0 depends only on the input up to andincluding the index no; that is output does not depend on the future values of the input. AnLTI system is causal if and only if the impulse response is

    1. Linearity and Non-LinearityWe now investigate the linearity property of a causal system of described by followingequation

    y[n]0.4y[n1]+0.75y[n2] = 2.2403x[n]+2.4908x[n1]+2.2403x[n2]

    Following program simulates the above mentioned equation.clear all, close alln = 0:40;a = 2; b = -3;x1 = cos(2*pi*0.1*n);x2 = cos(2*pi*0.4*n);

    x = a*x1 + b*x2;num = [2.2403 2.4908 2.2403];den = [1 -0.4 0.75];ic = [0 0]; % Set zero initial conditionsy1 = filter(num,den,x1,ic); % Compute the output y1[n]y2 = filter(num,den,x2,ic); % Compute the output y2[n]y = filter(num,den,x,ic); % Compute the output y[n]yt = a*y1 + b*y2;d = y - yt; % Compute the difference output d[n]% Plot the outputs and the difference signal

  • 8/10/2019 Dsp Manual Hamdard

    9/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 8 Compiled By: Engr. Hira Waris

    subplot (3,1,1)stem(n ,y);ylabel('Amplitude');title('Output Due to Weighted Input');subplot(3,1,2)stem(n,yt);

    ylabel('Amplitude');title('Weighted Output');subplot(3,1,3)stem(n,d);xlabel('Time index n');ylabel('Amplitude');title('Difference Signal');

    Question 1: Run above program and compare y[n] obtained with weighted input withyt[n] obtained by combining the two outputs y1[n] and y2[n] with the same weights. Arethese two sequences equal? Is this system linear?Exercise 1: Consider another system described by y[n] = x[n] x[n 1]. Modify given

    program to compute the output sequences y1[n], y2[n], and y[n] of the above system.Compare y[n] with yt[n]. Are these two sequences equal? Is this system linear?

    2. Time-Invariant and Time-Varying SystemsWe next investigate the time-invariance property. Following Program simulatesfollowing difference equation

    y[n]0.4y[n1]+0.75y[n2] = 2.2403x[n]+2.4908x[n1]+2.2403x[n2]

    Two input sequences x[n] and x[n - D], are generated and corresponding outputsequences y1[n], y2[n] are plotted.

    close all, clear alln = 0:40; D = 10;a = 3.0;b = -2;x = a*cos(2*pi*0.1*n) + b*cos(2*pi*0.4*n);

    xd = [zeros(1,D) x];num = [2.2403 2.4908 2.2403];den = [1 -0.4 0.75];ic = [0 0];% Set initial conditions% Compute the output y[n]y = filter(num,den,x,ic);% Compute the output yd[n]yd = filter(num,den,xd,ic);% Compute the difference output d[n]d = y - yd(1+D:41+D);% Plot the outputssubplot(3,1,1)stem(n,y);

    ylabel('mplitude');title('Output y[n]');grid;subplot(3,1,2)stem(n,yd(1:41));ylabel('Amplitude');Digital Signal ProcessingLab Manual Fall 201010title(['Output Due to Delayed Input x[n , num2str(D),]']);grid;subplot(3,1,3)

  • 8/10/2019 Dsp Manual Hamdard

    10/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 9 Compiled By: Engr. Hira Waris

    stem(n,d);xlabel('Time index n'); ylabel('Amplitude');title('Difference Signal');grid;Exercise 2: Consider another system described by:

    y[n] = nx[n] +x[n 1]

    Modify Program to simulate the above system and determine whether this system istime-invariant or not.

    3. Impulse Response computationFollowing equation computes impulse response of following difference eq

    y[n]0.4y[n1]+0.75y[n2] = 2.2403x[n]+2.4908x[n1]+2.2403x[n2]% Compute the impulse response yclose all, clear all

    N = 40;num = [2.2403 2.4908 2.2403];den = [1 -0.4 0.75];y = impz(num,den,N);% Plot the impulse responsestem(y);xlabel('Time index n'); ylabel('Amplitude');title('Impulse Response'); grid;

    Exercise 3: Write a MATLAB program to generate and plot the step response of a causalLTI system.

    y[n]0.4y[n1]+0.75y[n2] = 2.2403x[n]+2.4908x[n1]+2.2403x[n2]

    Using this program compute and plot the first 40 samples of the step response abovementioned LTI system.

    4. Stability of LTI Systemsclose all, clear allx = [1 zeros(1,40)];% Generate the inputn = 0:40;% Coefficients of 4th-order systemclf;num = [1 -0.8]; den = [1 1.5 0.9];

    N = 200;h= impz(num,den,N+1);

    parsum = 0;for k = 1:N+1;

    parsum = parsum + abs(h(k));if abs(h(k)) < 10^(-6),break, endend% Plot the impulse responsen = 0:N; stem(n,h), xlabel('Time index n'); ylabel('Amplitude');% Print the value of abs(h(k))

    disp('Value =');disp(abs(h(k)));

    Exercise 4: What is the discrete-time system whose impulse response is beingdetermined by above Program? Run Program to generate the impulse response. Is thissystem stable? If |h[K]| is not smaller than 106but the plot shows a decaying impulseresponse, run the program again with a larger value of N.

  • 8/10/2019 Dsp Manual Hamdard

    11/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 10 Compiled By: Engr. Hira

    Waris

    Exercise 5: Consider the following discrete-time system characterized by the differenceequation

    y[n] =x[n] 4x[n 1] + 3x[n 2] + 1.7y[n 1] y[n 2].Modify the Program to compute and plot the impulse response of the above system. Isthis system stable?

    Exercise 6: Consider the following discrete-time system characterized by the differenceequationy[n] =x[n] 4x[n 1] + 3x[n 2] + 1.7y[n 1] y[n 2].Modify the Program to compute and plot the impulse response of the above system. Isthis system stable?

    5. Cascade of LTI systemsFollowing fourth order difference equationcan be represented as cascade of following two difference equations%cascade exampleclose all, clear alln = 0:100; a = 3.0;b = -2;x = a*cos(2*pi*0.1*n) + b*cos(2*pi*0.4*n);den = [1 1.6 2.28 1.325 0.68];num = [0.06 -0.19 0.27 -0.26 0.12];% Compute the output of 4th-order systemy = filter(num,den,x);% Coefficients of the two 2nd-order systemsnum1 = [0.3 -0.2 0.4];den1 = [1 0.9 0.8];num2 = [0.2 -0.5 0.3];den2 = [1 0.7 0.85];% Output y1[n] of the first stage in the cascadey1 = filter(num1,den1,x);% Output y2[n] of the second stage in the cascadey2 = filter(num2,den2,y1);% Difference between y[n] and y2[n]d = y - y2;% Plot output and difference signalssubplot(3,1,1);

    stem(n,y);ylabel('Amplitude');title('Output of 4th-order Realization');grid;subplot(3,1,2);stem(n,y2)Digital Signal ProcessingLab Manual Fall 201013ylabel('Amplitude');title('Output of Cascade Realization');grid;subplot(3,1,3);stem(n,d)xlabel('Time index n');ylabel('Amplitude');

    title('Difference Signal');grid;

  • 8/10/2019 Dsp Manual Hamdard

    12/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 11 Compiled By: Engr. Hira

    Waris

    LAB#03

    Frequency Domain Analysis of LTI System

    Introduction

    If x(n) is absolutely summable, that is then its discrete-time Fouriertransform is given by

    The inverse discrete-time Fourier transform (IDTFT) of X(ejw) is given by

    1. Fourier anaylsis of discrete systems described by difference equation

    Provide the plots for the following along with the title of each by matching its response toLow pass, high pass, band pass or band stop filter. Also include in the title whether thesystem is FIR or IIR. The frequency response can be obtained using freqz(num,den).Poles and zero plot is obtained using zplane(num,den). Comment on the poles and zeroslocation of each filter.

    a. Y[n] = 0.08x[n] + 0.34x[n-1] + 0.34x[n-2] + .34x[n-3] + 0.08x[n]b = [0.08 0.34 0.34 0.34 0.08];subplot(2,1,1), freqz(b,1)subplot(2,1,2), zplane(b,1)

    b. Y[n] 1.11y[n-1] + 0.57 y[n-2] = x[n] + 2x[n-1] + x[n-2]b = [ 1 2 1];a = [1 -1.11 0.57 ];

    figuresubplot(2,1,1), freqz(b,a)subplot(2,1,2), zplane(b,a)c. Y[n] = -0.21x[n] -0.17x[n-1] + 0.81x[n-2] -0.17x[n-3] -0.21x[n-4]

    b = [-0.21 -0.17 0.81 -0.17 -0.21];figuresubplot(2,1,1), freqz(b,1)subplot(2,1,2), zplane(b,1)d. Y[n] 1.11y[n-1] + 0.57y[n-2] = x[n] 2x[n-1] + x[n-2]

    b = [1 -2 1];a = [ 1 -1.11 0.57];figuresubplot(2,1,1), freqz(b,a)

    subplot(2,1,2), zplane(b,a)e. Y[n] = -0.35x[n] + 0.2x[n-1] -0.07x[n-2] + 0.20x[n-3] 0.35x[n-4]b = [-0.35 0.20 -0.07 0.20 -0.35];figuresubplot(2,1,1), freqz(b,1)subplot(2,1,2), zplane(b,1)f. 2y[n] + 1.63y[n-1] + 0.65y[n-2] = x[n] x[n-2]

    b = [ 1 0 -1];a = [2 1.63 0.65];

  • 8/10/2019 Dsp Manual Hamdard

    13/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 12 Compiled By: Engr. Hira

    Waris

    figure

    subplot(2,1,1), freqz(b,a)subplot(2,1,2), zplane(b,a)2. Properties of DTFTIn this part fft(x,n) function will be used to prove some of the Fourier transform

    properties.a. Linearity

    The discrete-time Fourier transform is a linear transformation; that is,

    For every , , x1(n), and x2(n)close all, clear alln = -2*pi:.01:2*pi;size(n);x1=sin(10*2*pi*n);x2=sin(20*2*pi*n);y1 = 10*x1;y2 = 5*x2;Y1 = abs(fft(y1));Y2 = abs(fft(y2));

    subplot(3,1,1) , plot(Y1+Y2)title('F[aX1 + bX2]');X1 = abs(fft(x1));X2 = abs(fft(x2));X1 = 10*X1;X2 = 5*X2;subplot(3,1,2) , plot(X1+X2)title('aF[X1] + bF[X2]');diff = X1 + X2 - (Y1 + Y2);subplot(3,1,3) , plot(diff)title('aF[X1] + bF[X2] - F[aX1 + bX2]');

    b. Time shiftingA shift in the time domain corresponds to the phase shifting

    close all, clear allx = rand(1,11);n = 0:10;k = 0:500;w = (pi/500)*k;X = x*(exp(-j*pi/500)).^(n'*k);% X signal shifted by two samplesy =x;m = n+20;Y = y*(exp(-j*pi/500)).^(m'*k);% X verificationY_check = (exp(-j*20).^w).*X;

    subplot(2,1,1), plot(abs(X))subplot(2,1,2), plot(abs(Y))error = max(abs(Y-Y_check))c. Frequency shiftingMultiplication by a complex exponential corresponds to a shift in the frequencyDomain

  • 8/10/2019 Dsp Manual Hamdard

    14/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 13 Compiled By: Engr. Hira

    Waris

    close all, clear alln=0:100;x = cos(pi*n/2);k = -100:100;w = (pi/100)*k;

    X = x*(exp(-j*pi/100)).^(n'*k);y = exp(j*pi*n/4).*x;Y = y*(exp(-j*pi/100)).^(n'*k);subplot(2,2,1) ; plot(w/pi, abs(X)); grid; axis( [-1, 1,0,60])xlabel('frequencg in pi units'); ylabel('|X1|')title('Hagnitude of X')subplot (2,2,2) ; plot (w/pi ,angle(X)/pi); grid; axis([-1, 1, -1, 1])xlabel('frequency in pi units'); ylabel('radiauds/pi')title('hgle of X')subplot (2,2,3) ; plot (w/pi, abs (Y)) ; grid; axis( [-1,1,0,60])xlabel('frequency in pi units'); ylabel('|Y|')title('Magnitude of Y')subplot (2,2,4) ; plot (w/pi,angle(Y)/pi) ; grid; axis( [-1 1 -1 1])

    xlabel('frequency in pi units'); ylabel('radians/pi')title('Angle of Y')

    Exercise 1: Write a program which proves the convolution property described by

    Excercise2: Write a program which proves the multiplication property

  • 8/10/2019 Dsp Manual Hamdard

    15/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 14 Compiled By: Engr. Hira

    Waris

    LAB#04

    System Analysis using Z-Transform

    IntroductionJust as the Fourier transform forms the basis of signal analysis, the z-transform forms the

    basis of system analysis. If x[n] is a discrete signal, its z-transform X(z) is given by:

    The z-transform maps a signal in the time domain to a power series in the complex(frequency) domain: x[n] X(z).There are many advantages to working with z-transformed signals:linearity and superposition are preservedx[n k] zkX(z)x[n] X(1/z)anx[n] X(z/a)x[n] y[n] X(z)Y (z)The overall result is that the algebra of system analysis becomes greatly simplified in the zdomain. The only tradeoff is the necessity of taking an inverse transform to obtain timedomain responses.

    Since the response y[n] of an LTI system to input x[n] is given by the convolution x[n]

    h[n],where h[n] is the impulse reponse, we have

    The ratio H(z) = Y (z)/X(z) defines the impulse response (and so the system response), and iscalled the transfer function of the system.

    1. Convolution propertya. If X1(Z) = 2 + 3z-1 + 4z-2 and X2(z) = 3 + 4z-1 + 5z-2 + 6z-3. Determine X3(z) = X1(z)X2(z).clear all, close allx1 = [2,3,4]; x2 = [3 4 5 6];x3 = conv(x1,x2)x3 =6 17 34 43 38 24

    Hence,X3(z) = 6 + 17z-1 + 34z-2 + 43z-3 + 38z-4 + 24z-5

    b. If we are given X3(z) and want to compute X2(z) then we need to divide X3(z) by X1(Z).In MATLAB this can be done using deconv function.x3 = [ 6 17 34 43 38 24];x1 = [2,3,4];x2 = deconv(x3,x1)x2 =3 4 5 6Hence,

  • 8/10/2019 Dsp Manual Hamdard

    16/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 15 Compiled By: Engr. Hira

    Waris

    X2(z) = 3 + 4z-1 + 5z-2 + 6z-3

    Exercise 3: If X1(z) = 2 + 3z-1 + z-2 and X2(z) = 3 + 5z-1 + 4z-2 + 2z-2. Determine X3(z) =X1(z)X2(z).

    2. Zero and pole analysis in MATLABIf the numerator and denominator of the proper form of a transfer function arefactored, the zeros and poles become apparent:

    The location of the zeros and poles of the transfer function determines the response ofan LTI system.Example: H(z) = (z2 + 2z) / ( z2 + 0.2)Zeros : z=0, -2Poles: z=0.2 jGain: k =1

    b = [1 2];a = [1 0 0.2];[z,p,k] = tf2zpk(b,a)zplane(z,p)

    3. Zero-Pole placement in Filter DesignLTI systems, particularly digital filters, are often designed by positioning zeros and

    poles in the z-plane. The strategy is to identify passband and stopband frequencieson the unit circle and then position zeros and poles by cosidering the following.i. Conjugate symmetryAll poles and zeros must be paired with their complex conjugatesii. CausalityTo ensure that the system does not depened on future values, the number of

    zeros must be less than or equal to the number of polesiii. OriginPoles and zeros at the origin do not affect the magnitude responseiv. StabilityFor a stable system, poles must be inside the unit circle. Pole radius is

    proportional to the gain and inversely proportional to the bandwidth.Passbands should contian poles near the unit circle for larger gain.v. Minimum phaseZeros can be placed anywhere in the z-plane. Zeros inside the uint circleensure minimum phase. Zeros on the unit circle give a null response.Stopbands should contain zeros on or near the unit circle.vi. Tranistin bandA steep transition from passband to stopband can be achieved when stopband

    zeros are paired with poles along (or near) the same radial line and close tothe unit circle.vii. Zero-pole interactionZeros and poles interact to produce a composite response that might notmatch design goals. Poles closer to the unit circle or farther from one another

    produce smaller interactions. Zeros and poles might have to be repositionedor added, leading t a higher filter order.Zero-Pole-Gain Editing in SPTool

  • 8/10/2019 Dsp Manual Hamdard

    17/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 16 Compiled By: Engr. Hira

    Waris

    Run:SptoolTo acces the Pole/Zero Editor in SPTool, do the following:1. Click the New button under the Filters list in SPTool.2. Select the Pole/Zero Editor in the Algorithm list.3. View system characteristics as you position poles and zeros.

    Exercise 4: Provide examples of all seven properties mentioned above by placing

    zero/poles as outlined.

    4. Rational Z-transform to partial fraction formWhen taking inverse z-transform it is most convenient that the transfer function bein partial fraction form. To convert from rational z-transform to partial fraction formMATLAB residuez function can be used.Example:

    clear all, close all

    b = [ 0 1 0];a = [3 -4 1];[z,p,k] = residuez(b,a)z =

    0.5000-0.5000

    p =1.00000.3333k =0Z Zeros

    P

    PolesK GainHence,

    5. Partial fraction form to z-transformMATLAB residuez function can also be used to convert from partial fractionexpression into rational z-transform.Example

    z = [ .5 -.5];p = [1 0.3333];k = [];[b,a] = residuez(z,p,k)

    b =0 0.3334a =

  • 8/10/2019 Dsp Manual Hamdard

    18/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 17 Compiled By: Engr. Hira

    Waris

    1.0000 -1.3333 0.3333Exercise 5: Determine the inverse z-transform of

    LAB#05

    Conversion from Continuous to Discrete Time Signal

    (Sampling) and effects of under Sampling (Aliasing)

    PERIODIC SIGNALS

    A sequence ][nX is said to be periodic when it satisfies the following relation

    ][][ NnXnX += The fundamental period of the signal is defined as the smallest positive value of N for which above equation holds true.

    Now consider a signal ][nY which is formed by the addition of the two signals ][1 nX and ][2 nX .

    ][][][ 21 nXnXnY +=

    If the signal ][1 nX is periodic with the fundamental period 1N and ][2 nX is periodic with the fundamental period 2N ,

    then the signal ][nY will be periodic with the period N given by the following relation:

    ),( 21

    21

    NNGCD

    NNN

    =

    THE SAMPLING THEORM

    A continuous time signal ][tX with frequencies no higher than Fmax can be reconstructed exactly from its samples

    )(][ snTXnX = , if the samples are taken at a rates

    sT

    F1

    = that is greater than 2Fmax

    The minimum sampling rate of 2Fmaxis called the Nyquist Rate .From Sampling theorem it follows that the reconstructionof a signal is possible if we have at least 2 samples per period. If we do not sample at a rate that satisfies the samplingtheorem then aliasing occurs.

    SAMPLING A CONTINUOUS TIME SIGNAL

    For example we want to sample continuous time signal )100()( tCostX p= . The frequency of this signal is 50 Hz andaccording to sampling theorem the minimum sampling frequency should be 100 samples/sec. But we sample it at a ratemuch higher than the Nyquist rate so that it has many samples over one cycle giving an accurate representation of thesampled discrete time signal.

  • 8/10/2019 Dsp Manual Hamdard

    19/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 18 Compiled By: Engr. Hira

    Waris

    In the figure below the continuous time signal )100()( tCostX p= is sampled at Fs=1000 samples/second).Therefore it

    will have 2050

    1000==

    f

    Fs samples per cycle.

    CONCEPT OF ALIASING

    T=0.03;N=1024;fs=1000;n=[0:1/fs:T];F=[-N/2+1:N/2]*fs/N;f=125;x1=cos(2*pi*f*n);X1=abs(fftshift(fft(x1,N)));f=500;x2=cos(2*pi*f*n);X2=abs(fftshift(fft(x2,N)));f=625;x3=cos(2*pi*f*n);

    X3=abs(fftshift(fft(x3,N)));f=875;x4=cos(2*pi*f*n);X4=abs(fftshift(fft(x4,N)));subplot(421);stem(n,x1);grid on;title('sinusoidal signal of f=125 Hz');subplot(422);plot(F,X1);grid on;title('fft of sinusoidal signal of f=125 Hz');subplot(423);stem(n,x2);grid on;title('sinusoidal signal of f=500 Hz');subplot(424);plot(F,X2);grid on;title('fft of sinusoidal signal of f=500 Hz');subplot(425);stem(n,x3);grid on;title('sinusoidal signal of f=625 Hz');subplot(426);plot(F,X3);grid on;title('fft of sinusoidal signal of f=625 Hz');subplot(427);stem(n,x4);grid on;title('sinusoidal signal of f=825 Hz');subplot(428);plot(F,X4);grid on;title('fft of sinusoidal signal of f=825 Hz');

    0 5 10 15 20 25 30 35 40-1

    -0.5

    0

    0.5

    1

    x=cos(100*pi*t) sampled with Fs=1000 (samples / sec)

  • 8/10/2019 Dsp Manual Hamdard

    20/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 19 Compiled By: Engr. Hira

    Waris

    HANDLING MEDIA FILES

    wavread reads Microsoft WAVE (".wav") sound file.Y=wavread(FILE) reads a WAVE file specified by the string FILE, returning the sampled data in Y. The ".wav" extensionis appended if no extension is given. Amplitude values are in the range [-1,+1].

    [Y,FS,NBITS]=wavread(FILE) returns the sample rate (FS) in Hertz and the number of bits per sample (NBITS) used toencode the in the file.

    wavplay plays sound using Windows audio output device.wavplay(Y,FS) sends the signal in vector Y with sample frequency of FS Hertz to the Windows WAVE audio device.Standard audio are 8000, 11025, 22050, and 44100 Hz.wavplay(Y) automatically sets the sample rate to 11025 Hz. For stereo playback, Y should be an N-by-2 matrix.Following is a sample program that will enable us to understand the concept of sampling and aliasing.

    close allclear allclc

    [x,fs,nbits]=wavread('chimes.wav');ts=1/fs;N=length(x);t=[0:N-1]*ts;

    s=2*cos(2*pi*50*t);

    xs=x+s';load filter.mat

    0 0.005 0.01 0.015 0.02 0.025 0.03-1

    0

    1

    sinusoidal signal of f=125 Hz

    -500 0 5000

    10

    20

    fft of sinusoidal signal of f=125 Hz

    0 0.005 0.01 0.015 0.02 0.025 0.03-1

    0

    1sinusoidal signal of f=500 Hz

    -500 0 5000

    20

    40fft of sinusoidal signal of f=500 Hz

    0 0.005 0.01 0.015 0.02 0.025 0.03-1

    0

    1

    sinusoidal signal of f=625 Hz

    -500 0 5000

    10

    20

    fft of sinusoidal signal of f=625 Hz

    0 0.005 0.01 0.015 0.02 0.025 0.03-1

    0

    1sinusoidal signal of f=825 Hz

    -500 0 5000

    10

    20fft of sinusoidal signal of f=825 Hz

  • 8/10/2019 Dsp Manual Hamdard

    21/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 20 Compiled By: Engr. Hira

    Waris

    y=filter(Num,Den,xs);

    wavplay(x,fs)wavplay(xs,fs)wavplay(y,fs)

    [x,fs,nbits]=wavread('chimes.wav');ts=1/fs;

    N=length(x);t=[0:N-1]*ts;

    tind=find(t>=2.4 & t

  • 8/10/2019 Dsp Manual Hamdard

    22/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 21 Compiled By: Engr. Hira

    Waris

    f.

    Fs=130

    PROBLEM 3:

    Consider a signal )25.0( nCosX p= over the range n=0:40. What will be the aliases of the signal X. Plot the signal X

    and its two aliases all in the same window. (Actually a signal can have infinite number of aliases)

    PROBLEM 4:

    Sample the signal )150(5 tSinXt p= to get sampled signal )150(5 nTsSinXn p= such that there is no aliasing. Choosean appropriate value of sampling frequency and choose time such that the graph contains 4 cycles of the signal and eachcycle has 22 samples. Plot both signals Xt and Xn in the same window.

  • 8/10/2019 Dsp Manual Hamdard

    23/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 22 Compiled By: Engr. Hira

    Waris

    LAB#06

    Study of Digital Filters (IIR and FIR)Introduction

    Filters shape the frequency spectrum of a sound signal. Filters generally do not add frequency components to a signal that are not there

    to begin with. Boost or attenuate selected frequency regions

    The Basic on Filters

    Filters work by using one or both of the following methods:

    Delay a copy of the input signal (by x number of samples), and combine thedelayed input signal with the new input signal. (Finite Impulse Response, FIR, or feedforward filter)

    Delay a copy of the output signal (by x number of samples), and combine it withthe new input signal.

    (Infinite Impulse Response, IIR, feedback filter)

    Digital Filtering:

    In signal processing, the function of a filter is to remove unwanted parts of the signal,such as random noise, or to extract useful parts of the signal, such as the componentslying within a certain frequency range

    Analog Filter: Input: electrical voltage or current which is the direct analogue of a physical

    quantity (sensor output) Components: resistors, capacitors and op amps Output: Filtered electrical voltage or current Applications: noise reduction, video signal enhancement, graphic equalisers

    Digital Filter:

    Input: Digitized samples of analog input (requires ADC) Components: Digital processor (PC/DSP/ASIC/FPGA)

    Output: Filtered samples (requires DAC)Types: lowpass, highpass, bandpass, bandreject (notch).

    First, how we label things: x is the input signal

    y is the output signal n is the sample index (all samples are numbered, or indexed)

  • 8/10/2019 Dsp Manual Hamdard

    24/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 23 Compiled By: Engr. Hira

    Waris

    n x[0] is the first sample of input; y[0] is the first sample of output. x[n] is the currentsample; x[n - 1] is the previous sample.

    FIR filtering

    Finite Impulse Response (FIR) filters use past input samples only

    Example:

    y(n)=0.1x(n)+0.25x(n-1)+0.2x(n-2)

    Z-transform: Y(z)=0.1X(z)+0.25X(z)z-1+0.2X(z)z-2

    Transfer function:H(z)=Y(z)/X(z)=0.1+0.25z-1+0.2z-2

    No poles, just zeroes. FIR is stable

    Home Task:

    A filter is described by the following equation: y(n)=0.5x(n) + 1x(n-1) + 0.5x(n-2), with initial condition y(-1) = 0

    What kind of filter is it? Plot the filters transfer function on the z plane Is the filter stable?

    Plot the filters unit step response Plot the filters unit impulse response

    IIR Filtering

    Infinite Impulse Response (IIR) filters use past outputs together with past inputsIIR Filter Implementation

    y(n)=b(0)x(n)+b(1)x(n-1)+b(2)x(n-2)+b(3)x(n-3) + a(0)y(n)+

    a(1)y(n-1)+a(2)y(n-2)+a(3)y(n-3)

    Home Task

    A filter is described by the following equation: y(n)=0.5x(n) + 0.2x(n-1) + 0.5y(n-1) + 0.2y(n-2),with initial condition y(-1)=y(-2) = 0

    What kind of filter is it? Plot the filters transfer function on the z plane

    Is the filter stable? Plot the filters unit step response Plot the filters unit impulse response

  • 8/10/2019 Dsp Manual Hamdard

    25/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 24 Compiled By: Engr. Hira

    Waris

    LAB#07

    IIR Filter Design and Analysis using FDATool and script

    writing Techniques of MATLAB

    Filter Design:

    The goal of Filtering is to perform frequency-dependent alteration of a signal. A simple design specification for a Filtermight be to remove noise above a certain cutoff frequency. A more complete specification might call for a specific amountof passband ripple (Rp, in decibels), stopband attenuation (Rs, in decibels), or transition width (Wp - Ws, in hertz). A

    precise specification might ask to achieve the performance goals with the minimum Filter order, call for an arbitrarymagnitude response, or require an FIR Filter.IIR Filter design methods differ from FIR primarily in how performance is specified. For loosely specified requirements, asin the previous paragraph, a Butterworth Filter is often sufficient. More rigorous Filter requirements can be met with so-called Chebyshev and elliptic Filters. The Signal Processing Toolbox order selection functions estimate the minimum Flterorder that meets a given set of requirements.

    Filter Configurations

    First, recall that when dealing with sampled signals, we can normalize the frequencies to the Nyquist frequency (defined asone-half the sampling frequency). All the filter design functions in the Signal Processing Toolbox operate with normalizedfrequencies,

    v Lowpass flters remove high frequencies (near 1)v

    Highpass flters remove low frequencies (near 0)v Bandpass flters pass a specifed range of frequencies between 0 & 1v Bandstop flters remove a specifed range of frequencies between 0 & 1

    To calculate the normalized frequency (nf):fs = 1e4;f = 400;nf = 400/(fs/2)

    Filter Speciations in Matlab

    v Wp - Passband cutoff frequencies (normalized)v Ws - Stopband cutoff frequencies (normalized)

    v

    Rp - Passband ripple: deviation from maximum gain (dB) in the passbandv Rs - Stopband attenuation: deviation from 0 gain (dB) in the stopband

    FDA Tool:

    Introduction to the Filter Design and Analysis Tool (FDATool):

  • 8/10/2019 Dsp Manual Hamdard

    26/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 25 Compiled By: Engr. Hira

    Waris

    The Filter Design and Analysis Tool (FDATool) is a powerful graphical user interface (GUI) in the Signal ProcessingToolboxfor designing and analyzing filters. FDATool enables you to quickly design digital FIR or IIR filters by settingfilter performance specifications, by importing filters from your MATLAB workspace or by adding, moving or deleting

    poles and zeros. FDATool also provides tools for analyzing filters, such as magnitude and phase response plots and pole-zero plots. You can use FDATool as a convenient alternative to the command line filter design functions.

    Getting Started

    Type fdatool at the MATLAB command prompt:>>fdatoolin command window, FDAtool will be opened. There you can select FIR or IIR filter,order of filter and cutoff frequency ofa filter (either HPF, LPF or BPF). That code will automatically generate .m file for you. Record your voice. Analyze theeffect of lowpass filtering on speech signal. Use the Filter Design and Analysis Tool (FDATool) of MATLAB for the

    purpose of designing LPF filter. Consider separately FIR and IIR filter. A detail demo of the FDATool is available in thewebsite of The Mathworks which I recommend you to visit for acquiring more knowledge in Matlab.

    The GUI has three main regions: The Current Filter Information region The Filter Display region and The Design panel

    The upper half of the GUI displays information on filter specifications and responses for the current filter. The Current

    Filter Information region, in the upper left, displays filter properties, namely the filter structure, order, number of sectionsused and whether the filter is stable or not. It also provides access to the Filter manager for working with multiple filters.The Filter Display region, in the upper right, displays various filter responses, such as, magnitude response, group delayand filter coefficients.The lower half of the GUI is the interactive portion of FDATool. The Design Panel, in the lower halfis where you define your filter specifications. It controls what is displayed in the other two upper regions. Other panels can

    be displayed in the lower half by using the sidebar buttons.

    Designing a Filter

  • 8/10/2019 Dsp Manual Hamdard

    27/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 26 Compiled By: Engr. Hira

    Waris

    We will design a low pass filter that passes all frequencies less than or equal to 20% of the Nyquist frequency (half thesampling frequency) and attenuates frequencies greater than or equal to 50% of the Nyquist frequency.We will use an FIREquiripple filter with these specifications:

    v Passband attenuation 1 dBv Stopband attenuation 80 dBv A passband frequency 0.4 [Normalized (0 to 1)]v A stopband frequency 0.5 [Normalized (0 to 1)]

    To implement this design, we will use the following specifications:1. Select Lowpass from the dropdown menu under Response Type and butter worth under IIR Design Method. Ingeneral, when you change the Response Type or Design Method, the filter parameters and Filter Display region updateautomatically.2. Select Specify order in the Filter Order area and enter 30 or you can selectMinimum order option.3. Select Normalized (0 to 1) in the Units pull down menu in the Frequency Specifications area.4. Enter 0.6 for wpass and 0.7 for wstop in the Frequency Specifications area.4. Enter 1 db for Apass and 80db for Astop in the Frequency Specifications area.5. After setting the design specifications, click the Design Filter button at the bottom of the GUI to design the filter.Themagnitude response of the filter is displayed in the Filter Analysis area after the coefficients are computed.

    Viewing other Analyses:

    Once you have designed the filter, you can view the following filter analyses in the display window by clicking any of thebuttons on the toolbar:In order from left to right, the buttons are

  • 8/10/2019 Dsp Manual Hamdard

    28/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 27 Compiled By: Engr. Hira

    Waris

    v Magnitude responsev Phase responsev Magnitude and Phase responsesv Group delay responsev Phase delay responsev

    Impulse responsev

    Step responsev

    Pole-zero plotv

    Filter Coefficientsv Filter Information

    Exporting the Filter

    Once you are satisfied with your design, you can export your filter to the following destinations:v

    MATLAB workspacev

    MAT-filev

    Text-file

    Select Export from the File menu.

    Filter Design using Script Writing Techniques

    Butter Worth Examplefigure;

    wp = 0.6;ws = 0.75;rp=1;

  • 8/10/2019 Dsp Manual Hamdard

    29/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 28 Compiled By: Engr. Hira

    Waris

    rs=80;[n,wn]=buttord(wp,ws,rp,rs)[b,a]=butter(n,wn,'low');freqz(b,a)

    N=1024;fs=100;n=[0:1:100];F=[-N/2+1:N/2]*fs/N;

    x1=cos(2*pi*(10/fs)*n)+cos(2*pi*(20/fs)*n)+cos(2*pi*(30/fs)*n);X1=abs(fftshift(fft(x1,N)));y=filter(b,a,x1);Y=abs(fftshift(fft(y,N)));figure;subplot(411);stem(n,x1);grid on;title('sinusoidal signal Xn');subplot(412);plot(F,X1);grid on;title('fft of sinusoidal signal Xn');subplot(413);stem(n,y);grid on;title('sinusoidal signal Xn');subplot(414);plot(F,Y);grid on;title('fft of sinusoidal signal Xn');

    IIR filter types

    v

    BUTTERWORTH FILTER

    v CHEBYSHEV TYPE I FILTER

    v

    CHEBYSHEV TYPE II FILTERv

    ELLIPTIC FILTER

    BUTTERWORTH FILTER

    Butterworth filters are defined by the property that the magnitude response is maximally flat in the pass band. Anotherproperty is that the approximation is monotonic in the pass band and the stop band.

    CHEBYSHEV TYPE I FILTERThe Chebyshev type I filter minimizes the absolute difference between the ideal and actual frequency response over theentire pass band by incorporating an equal ripple of Rp dB in the pass band .Stop band response is maximally flat.The transition from pass band to stop band is more rapid than for the Butterworth filter.

  • 8/10/2019 Dsp Manual Hamdard

    30/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 29 Compiled By: Engr. Hira

    Waris

    CHEBYSHEV TYPE II FILTER

    The Chebyshev type II filter minimizes the absolute difference between the ideal and actual frequency response over theentire stop band, by incorporating an equal ripple of Rs dB in the stop band. Pass band response is maximally flat. The stop

    band does not approach zero as quickly as the type I filter (and does not approach zero at all for even-valued n). Theabsence of ripple in the pass band, however, is often an important advantage.

    ELLIPTIC FILTER

    Elliptic filters are equiripple in both the pass band and stop band. They generally meet filter requirements with the lowestorder of any supported filter type. Given a filter order n, pass band ripple Rp in decibels, and stop band ripple Rs indecibels, elliptic filters minimize transition width.

    PROBLEM 1

    Design a Low pass Filter for the following IIR types

    v

    BUTTERWORTH FILTERv

    CHEBYSHEV TYPE I FILTER

    v CHEBYSHEV TYPE II FILTER

    v ELLIPTIC FILTER

    Filter Specifications are

    v

    Use minimum order for each case

    v Normalized passband cutoff frequencies:

    Wp = 0.5

    v

    Normalized stopband cutoff frequencies:Ws = 0.6

    v

    Passband ripple:

    Rp = 1dB

    v Stopband attenuation:

    Rs = 80dB

  • 8/10/2019 Dsp Manual Hamdard

    31/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 30 Compiled By: Engr. Hira

    Waris

    PROBLEM 2

    Design a High pass Filter for the following IIR types

    v BUTTERWORTH FILTER

    v CHEBYSHEV TYPE I FILTER

    v

    CHEBYSHEV TYPE II FILTER

    v ELLIPTIC FILTER

    Filter Specifications are

    v Use minimum order for each case

    v

    Normalized passband cutoff frequencies:

    Wp = 0.4

    v Normalized stopband cutoff frequencies:

    Ws = 0.3

    v

    Passband ripple:Rp = 1dB

    v Stopband attenuation:

    Rs = 80dB

    PROBLEM 3

    Design a Bandpass for the following IIR types

    v

    BUTTERWORTH FILTER

    v CHEBYSHEV TYPE I FILTER

    v CHEBYSHEV TYPE II FILTER

    v

    ELLIPTIC FILTER

    Filter Specifications are

    v Use minimum order for each case

    v

    Normalized passband cutoff frequencies:

    Wp = [0.3 0:7]

    v Normalized stopband cutoff frequencies:

    Ws = [0.2 0.8]

    v Passband ripple:

    Rp = 1dB

    v

    Stopband attenuation:

    Rs = 80dB

  • 8/10/2019 Dsp Manual Hamdard

    32/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 31 Compiled By: Engr. Hira

    Waris

    PROBLEM 4

    Design a Band Stop for the following IIR types

    v BUTTERWORTH FILTER

    v CHEBYSHEV TYPE I FILTER

    v

    CHEBYSHEV TYPE II FILTER

    v

    ELLIPTIC FILTER

    Filter Specifications are

    v Use minimum order for each case

    v

    Normalized passband cutoff frequencies:

    Wp = [0.3 0:7]

    v

    Normalized stopband cutoff frequencies:

    Ws = [0.4 0.6]

    v Passband ripple:

    Rp = 1dB

    v Stopband attenuation:

    Rs = 80dB

    PROBLEM 5

    1.

    Use help command to learn the use of following commands:

    butter, buttord, cheby1, cheb1ord, cheby2, cheb2ord, ellip, ellipord

    2. Generate the following signal with 100 samples and then plot it against time.

    Fs=100Hz,F1=10Hz,F2=20Hz,F3=30Hz

    X(t)=cos(2*pi*f1*t)+ cos(2*pi*f2*t)+ cos(2*pi*f3*t);

    3.

    Plot the DFT of the above signal versus frequency. Choose an appropriate value of N .

    4. Remove the highest frequency component of the signal using Butterworth, Chebyshev Type I, Chebyshev Type IIand Elliptic filters. Use freqz to plot the frequency response for each of the filters used. Plot DFT of the filteredsignal for each case.

    5.

    Repeat part 3 to remove the intermediate frequency component.

    6.

    Repeat part 3 to remove the Highest frequency component.

    7.

    Repeat part 3 to remove the lowest frequency component.8.

    Comment on the results obtained by using different filters

  • 8/10/2019 Dsp Manual Hamdard

    33/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 32 Compiled By: Engr. Hira

    Waris

    LAB#08

    FIR Filter Design and Analysis using FDATool and script

    writing Techniques of MATLAB

    Filter Design Using Fir1 Command:Design of FIR filters are based on directly approximating the desired frequency response of the discrete time system. Mosttechniques used to design FIR filters use linear phase constraint. The simplest method of FIR filter design is called windowmethod. To obtain a casual FIR filter a window truncates frequency response of the ideal filter. According to the type of

    window that is selected different approximation of the filter will be obtained.In order to design a FIR filter using Matlab we can use fir1and Filtercommands.The format of fir1is as follows:LOW PASS:B = FIR1(N,Wn) designs an N' th order low pass FIR digital filter and returns the filter coefficients in length

    N+1 vector B.For example in order to design a FIR filter assuming a sampling rate of 48khz and having a low pass filter with the cut offfrequency of 10khz by windowing method:B=fir1(40,10.0/(48.0/2))=fir1( N, fc/(fs/2) )HIGH PASS:B = FIR1(N,Wn,'high')=FIR1(N,fc/(fs/2),high) designs an N'th order high pass filter.BAND PASS:If Wn is a two-element vector, Wn = [W1 W2], FIR1 returns an order N band pass filter with pass band W1< W < W2. Example: FIR1( N , [f1/(fs/2) f2/(fs/2)] )BAND STOP:If Wn = [W1 W2], B = FIR1(N,Wn,'stop') will design a band stop filter.

    FIR1( N , [ f1/(fs/2) f2/(fs/2) ], stop)

    FILTERcommand (One-dimensional digital filter) :Y = FILTER(B,A,X) filters the data in vector X with the filter described by vectors A and B to create the filtered data Y.For FIR filters A=1 because they do not contain any poles.

    FREQZ(b,1,f,fs) will plot frequency response of the filter designed above for the designated f vector.

    Example 1: Design a 48th-order FIR low filter with ws=0.6,

    b = fir1(48,0.6,low);

  • 8/10/2019 Dsp Manual Hamdard

    34/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 33 Compiled By: Engr. Hira

    Waris

    freqz(b,1,512)

    Example 2:Design a 48th-order FIR bandpass filter with passband 0.35 0.65:

    b = fir1(48,[0.35 0.65]);freqz(b,1,512)

    Example 2 : Design a 48th-order FIR high filter with ws=0.2,

    0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-3000

    -2000

    -1000

    0

    Normalized Frequency (p rad/sample)

    Phase(degrees)

    0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-100

    -50

    0

    50

    Normalized Frequency (p rad/sample)

    Magnitude(dB)

    0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-2000

    -1000

    0

    1000

    Normalized Frequency (prad/sample)

    Phase(degrees)

    0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-100

    -50

    0

    50

    Normalized Frequency (prad/sample)

    Magnitude(dB)

  • 8/10/2019 Dsp Manual Hamdard

    35/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 34 Compiled By: Engr. Hira

    Waris

    B = FIR1(30,0.2,'high')freqz(B,1,512)

    Script Writing Technique:Low Pass FIR using Kaiser Window Method

    fsamp = 8000;

    fcuts = [1000 1500];

    mags = [1 0];

    devs = [0.05 0.01];

    [n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,fsamp);

    hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');

    [H,f] = freqz(hh,1,1024,fsamp);figure;plot(f,abs(H)), grid on,ylabel('Magnitude');xlabel('Frequencies in Hz');title('Low Pass Filter');

    0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-3000

    -2000

    -1000

    0

    1000

    Normalized Frequency (prad/sample)

    Phase(degrees)

    0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-100

    -50

    0

    50

    Normalized Frequency (prad/sample)

    Mag

    nitude(dB)

  • 8/10/2019 Dsp Manual Hamdard

    36/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 35 Compiled By: Engr. Hira

    Waris

    High FIR using Kaiser Window Method

    clc

    fsamp = 8000;

    fcuts = [1000 1500];

    mags = [0 1];

    devs = [0.01 0.05];

    [n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,fsamp);

    hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');

    [H,f] = freqz(hh,1,1024,fsamp);

    figure;

    plot(f,abs(H)), grid on,ylabel('Magnitude');xlabel('Frequencies in Hz');title('High Pass Filter');

  • 8/10/2019 Dsp Manual Hamdard

    37/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 36 Compiled By: Engr. Hira

    Waris

    Band Pass FIR using Kaiser Window Method

    fsamp = 8000;

    fcuts = [1000 1500 2500 3000];

    mags = [0 1 0];

    devs = [0.01 0.05 0.01];

    [n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,fsamp);

    hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');[H,f] = freqz(hh,1,1024,fsamp);

    figure;

    plot(f,abs(H)), grid on,ylabel('Magnitude');xlabel('Frequencies in Hz');title('Band Pass Filter');

  • 8/10/2019 Dsp Manual Hamdard

    38/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 37 Compiled By: Engr. Hira

    Waris

    Band Stop FIR using Kaiser Window Method

    fsamp = 8000;

    fcuts = [1000 1500 2500 3000];

    mags = [1 0 1];

    devs = [0.05 0.01 0.05];

    [n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,fsamp);

    hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');[H,f] = freqz(hh,1,1024,fsamp);

    figure;

    plot(f,abs(H)), grid on,ylabel('Magnitude'); xlabel('Frequencies in Hz');title('Band Stop Filter');

  • 8/10/2019 Dsp Manual Hamdard

    39/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 38 Compiled By: Engr. Hira

    Waris

    FDA Tool Problems

    PROBLEM 1

    Design a Low pass FIR Filter for the following Windows types .

    v Kaiserv Hammingv Hanningv Rectangularv

    Blackmanv

    Bartlett

    Filter Specifications are

    Fs=8000hzFc=-2000hzRp = 1dB,Rs = 80dB

    PROBLEM 2

    Design a High pass FIR Filter for the following Windows types.

  • 8/10/2019 Dsp Manual Hamdard

    40/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 39 Compiled By: Engr. Hira

    Waris

    v

    Kaiserv

    Hammingv

    Hanningv Rectangularv Blackmanv Bartlett

    Filter Specifications are

    Fs=8000hzFc=-2000hzRp = 1dB,Rs = 80dB

    PROBLEM 3

    Design a Band pass FIR Filter for the following Windows types.

    v Kaiserv Hamming

    v

    Hanningv Rectangularv Blackmanv Bartlett

    Filter Specifications are

    Fs=8000hzFc1=-2000hzFc1=3000hzRp = 1dB,Rs = 80dB

    PROBLEM 4

    Design a Band Stop FIR Filter for the following Windows types.

    v

    Kaiserv Hammingv Hanningv Rectangularv Black anv Bartlett

    Filter Specifications are

    Fs=8000hz

    Fc1=-2000hzFc1=3000hzRp = 1dB,Rs = 80dB

    PROBLEM 5

  • 8/10/2019 Dsp Manual Hamdard

    41/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 40 Compiled By: Engr. Hira

    Waris

    Design a FIR Filter for the using Kaiser Window Method.

    vLow Pass FilterWp = 0.5,Ws = 0.6

    Rp = 1dB,Rs = 80dB

    v High Pass Filter

    Wp = 0.4,Ws = 0.3Rp = 1dB,Rs = 80dB

    v Band Pass Filter

    Wp = [0.3 0:7]

    Ws = [0.2 0.8]

    Rp = 1dB,Rs = 80dB

    Fs=8000hz

    Fc1=-2000hzFc1=3000hz

    v Band Stop Filter

    Wp = [0.3 0:7]

    Ws = [0.4 0.6]

    Rp = 1dB,Rs = 80dB

    Script Writing Techniques

    PROBLEM 69.

    Use help command to learn the use of following commands:

    Kaiserord, fir1

    10. Generate the following signal with 100 samples and then plot it against time.

    Fs=100Hz,F1=10Hz,F2=20Hz,F3=30Hz

    X(t)=cos(2*pi*f1*t)+ cos(2*pi*f2*t)+ cos(2*pi*f3*t);

    11. Plot the DFT of the above signal versus frequency. Choose an appropriate value of N .

    12.

    Remove the highest frequency component of the signal using Kaiser window method. Use freqz to plot thefrequency response for each of the filters used. Plot DFT of the filtered signal for each case.

    13.

    Repeat part 4 to remove the intermediate frequency component.

    14. Repeat part 4 to pass only the lowest frequency component.

  • 8/10/2019 Dsp Manual Hamdard

    42/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 41 Compiled By: Engr. Hira

    Waris

    15.

    Repeat part 4 to remove the lowest frequency component.

    16. Comment on the results obtained by using different filters

    LAB#09

    INTRODUCTION TO TEXASINSTRUMENTS TMS320C6713 DSP

    STARTER KIT (DSK) DIGITAL SIGNAL

    PROCESSING BOARDIntroductionDigital signal processing, or DSP, is a rapidly growing industry within Electrical andComputer Engineering. With processing power doubling every 18 months (according toMoores law), the number of applications suitable for DSP is increasing at a comparable rate.In this course, our aim is to show how mathematical algorithms for digital signal processingmay be encoded for implementation on programmable hardware. In this first lab, you will

    become familiar with a development system for programming DSP hardware. You will study:Code Composer StudioTMS320C6713 DSP chip and supporting chip set (DSK) architectureThe C programming language

    1. Hardware and Software1.1. DSP Chip ManufacturersMany companies produce DSP chips. Some of the more well known include AgereSystems, Analog Devices, Motorola, Lucent Technologies, NEC, SGS-Thompson,Conexant, and Texas Instruments. In this course, we will use DSP chips designed andmanufactured by Texas Instruments (TI). These DSP chips will be interfaced throughCode Composer Studio (CCS) software developed by TI.1.2. Code Composer Studio (CCS)CCS is a powerful integrated development environment that provides a useful

    transition between a high-level (C or assembly) DSP program and an on-board machinelanguage program. CCS consists of a set of software tools and libraries for developingDSP programs, compiling and linking them into machine code, and writing them intomemory on the DSP chip and on-board external memory. It also contains diagnostictools for analyzing and tracing algorithms as they are being implemented on-board. Inthis class, we will always use CCS to develop, compile, and link programs that will bedownloaded from a PC to DSP hardware.1.3. TMS320 DSP ChipsIn 1983, Texas Instruments released their first generation of DSP chips, the TMS320single-chip DSP series. The first generation chips (C1x family) could execute aninstruction in a single 200-nanosecond (ns) instruction cycle. The current generation ofTI DSPs includes the C2000, C5000, and C6000 series, which can run up to 8 32-bit

    parallel instructions in one 4.44ns instruction cycle, for an instruction rate of 1.8*109

    instructions per second. The C2000, and C5000 series are fixed-point processors. TheC6000 series contains both fixed point and floating-point processors. For this lab, wewill be using the C6713 processor, a member of C67x family of floating-point

    processors.The different families in the TMS320 seriea are targetted at different applications. TheC2000 and C5000 series of chips are primarily used for digital control. They consumevery little power and are used in many portable devices including 3G cell phones, GPS(Global Positioning System) receivers, portable medical equipment, and digital music

    players. Due to their low power consumption (40mW to 160mW of active power), they

  • 8/10/2019 Dsp Manual Hamdard

    43/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 42 Compiled By: Engr. Hira

    Waris

    are very attractive for power sensitive portable systems. The C6000 series of chipsprovides both fixed and floating point processors that are used in systems that requirehigh performance. Since these chips are not as power efficient as the C5000 series ofchips (.5W to 1.4W of active power), they are generally not used in portable devices.Instead, the C6000 series of chips is used in high quality digital audio applications,

    broadband infrastructure, and digital video/imaging, the latter being associated almostexclusively with the fixed-point C64x family of processors. When designing a product,

    the issues of power consumption, processing power, size, reliability, efficiency, etc. willbe a concern.Learning how to implement basic DSP algorithms on the C6713 will provide you withthe tools to execute complex designs under various constraints in future projects. Atone time, assembly language was preferred for DSP programming. Today, C is the

    preferred way to code algorithms, and we shall use it for fixed- and floating-pointprocessing.1.4. DSP Starter Kit (DSK)The TMS320C6713 DSP chip is very powerful by itself, but for development of

    programs, a supporting architecture is required to store programs and data, and bringsignals on and off the board. In order to use this DSP chip in a lab or developmentenvironment, a circuit board containing appropriate components, designed andmanufactured by Spectrum Digital, Inc, is provided. Together, CCS, the DSP chip, andsupporting hardware make up the DSP Starter Kit, or DSK.

    In this lab, we will go over the basic components of the DSK and show how softwaremay be downloaded onto the DSK.2. Programming LanguagesAssembly language was once the most commonly used programming language for DSPchips (such as TIs TMS320 series) and microprocessors (such as Motorolas 68MC11series). Coding in assembly forces the programmer to manage CPU core registers(located on the DSP chip) and to schedule events in the CPU core. It is the most timeconsuming way to program, but it is the only way to fully optimize a program.Assembly language is specific to a given architecture and is primarily used to scheduletime critical and memory critical parts of algorithms. In this course, we will useassembly code to gain intuition into the structure of digital filtering algorithms.The preferred way to code algorithms is to code them in C. Coding in C requires acompiler that will convert C code to the assembly code of a given DSP instruction set. C

    compilers are very common, so this is not a limitation. In fact, it is an advantage, sinceC coded algorithms may be implemented on a variety platforms (provided there is a Ccompiler for a given architecture and instruction set). Most of the programs created inthis course will be coded in C. In CCS, the C compiler has four optimization levels. Thehighest level of optimization will not achieve the same level of optimization that

    programmer-optimized assembly programs will, but TI has done a good job in makingthe optimized C compiler produce code that is comparable to programmer- optimizedassembly code.Lastly, a cross between assembly language and C exists within CCS. It is called linearassembly code. Linear assembly looks much like assembly language code, but it allowsfor symbolic names and does not require the programmer schedule events and manageCPU core registers on the DSP. Its advantage over C code is that it uses the DSP moreefficiently, and its advantage over assembly code is that it requires less time to

    program with. This will be apparent in future labs when assembly and linear assemblycode are given.3. CodecThe codec (coder/decoder) is a chip located on-board the DSK which interfaces the DSPchip to the analog world, specifically signal generator(s) and either an oscilloscope orstereo headphones.The codec contains a coder, or analog-to-digital converter(ADC), and a decoder ordigital-to-analog converter (DAC). Both coder and decoder run at sample rates whichcan be set from 8KHz to 96KHz and support data word lengths of 16b, 20b, 24b, and

  • 8/10/2019 Dsp Manual Hamdard

    44/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 43 Compiled By: Engr. Hira

    Waris

    32b at the digital interfaces.4. C6713 DSP ChipThe C6713 DSP chip is a floating point processor which contains a CPU (CentralProcessing Unit), internal memory, enhanced direct memory access (EDMA) controller,and on-chip pe-ripheral interfaces. These interface include a 32-bit external memoryinterface (EMIF), four Multi-channel Buffered Serial Ports (McASP and McBSP), two

    32-bit timers, a host port in-terface (HPI) for high-speed communication between chips

    in a multi-DSP system, an interrupt selector, and a phase lock loop (PLL), along withhardware for Boot Configurationsand Power Down Logic.5. TimingThe DSP chip must be able to establish communication links between the CPU (DSPcore), the codecs, and memory. The two McBSPs, serial port 0 (SP0) and serial port 1(SP1), are used to establish bidirectional asynchronous links between the CPU and thecodec or alternately an external daughter card (not used in this course). SP0 is used tosend control data between the codec and CPU; SP1 plays a similar role for digital audiodata. The McBSPs use frame synchronization to communicate with external devices[6]. Each McBSP has seven pins. Five of them are used for timing and the other twoare connected to the data receive and data transmit pins on the on-board codec ordaughter card. Also included in each McBSP is a 32-bit Serial Port Control Register(SPCR). This register is updated when the on-board codec (or daughter card) is ready tosend data to or receive data from the CPU. The status of the SPCR will only be a

    concern to us when polling methods are implemented.6. Establishing a File StructureIn this section, we are going to develop a file structure on your u:\ drive that will makeimple-menting DSP algorithms easier on the DSK. Specifically, there is a set of supportfiles that are needed to run the DSK for every algorithm implemented in this class.Since these files will be used many times, it will prove to be beneficial to store them ina specific folder.Our goal here is to create the following two paths on your u:\ drive that contain thefollowing types of files:1. u:\DSP\Support { .h initialization header files, .c initialization source code files, .lib

    pre-compiled binary library files, .asm vector files, and .cmd linker command file }2. u:\DSP\Lab 08\ { .c project source code }To create the first path, open Windows Explorer and create the folder DSPto save

    your work for this class. This folder will contain all of the sub-folders in this class. Thisorganization is crucial and cannot be over-stressed. Now double click on your newfolder DSP. and copy the sub-folder Support. The Supportfolder contains thefollowing files:c6713dskinit.cc6713dskinit.hdsk6713.hdsk6713 aic23.hdsk6713 dip.hdsk6713 flash.hdsk6713 led.hcsl6713.libdsk6713bsl.lib

    rts6700.libVectors intr.asmVectors poll.asmc6713dsk.cmd

    Now that you have these support files, go back toWindows Explorer and create anotherfolder: Lab 08in the path u:\DSP\Lab 08\ Copy the file led.c into your newly createdfolder Lab 08. You now have all of the support files that you will need to implementany of the projects in this class and you also have the files required to create your first

    project. At this point, you should have the following file structure established on your

  • 8/10/2019 Dsp Manual Hamdard

    45/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 44 Compiled By: Engr. Hira

    Waris

    u:\ drive.1. u:\DSP\Supportc6713dskinit.c,...2. u:\DSP\Lab 08led.c

    7. Creating the First Project on the DSK7.1 Creating the Project File Lab07.pjtIn CCS, select Projectand then New. A window named Project Creationwill appear.In the field labelled Project Name, enter Lab08. In the field Location, click on the . ..on the right side of the field and navigate to the folder u:\DSP\Lab 07\. In the fieldProject Type, verify that Executable (.out)is selected, and in the field Target, verifythat TMS32067XXis selected. Finally, click on Finish. CCS has now created a projectfile Lab08.pjt, which will be used to build an executable program. This file is stored onyour u:\ drive in the pathu:\DSP\lab 08. See Figure below.

    7.2. Adding Support Files to a ProjectThe next step in creating a project is to add the appropriate support files to the fileLab08. In the CCS window, go to Projectand then Add Files to Project . . .. In thewindow that appears, click on the folder next to where it says Look In:. Make surethat you are in the path u:\DSP\Support. You should be able to see the filec6713dskinit.c. Notice that the Files of typefield is C source code. Click onc6713dskinit.c and then click on Open. Re-peat this process two more times adding thefiles Vectors_intr.asm and c6713dsk.cmd to the project file sine gen.pjt. For field, Filesof type, select Asm Source Files (*.a*). Click on Vectors_intr.asm and then click onOpen. For field, Files of type, select Linker Command File (*.cmd). Click onc6713dsk.cmd and then click on Open. You have now charged your project fileu:\DSP\Lab 08\Lab08{Lab08.pjt}.The C source code file contains functions for initializing the DSP and peripherals. The

    Vectors file contains information about what interrupts (if any) will be used and givesthe linker information about resetting the CPU. This file needs to appear in the firstblock of program memory. The linker command file (c6713dsk.cmd) tells the linker howthe vectors file and the internal, external, and flash memory are to be organized inmemory. In addition, it specifies what parts of the program are to be stored in internalmemory and what parts are to be stored in the external memory. In general, the

    program instructions and local/global variables will be stored in internal random accessmemory or IRAM.7.3. Adding Appropriate Libraries to a Project

  • 8/10/2019 Dsp Manual Hamdard

    46/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 45 Compiled By: Engr. Hira

    Waris

    In addition to the support files that you have been given, there are pre-compiled filesfrom TI that need to be included with your project. For this project, we need run-timesupport libraries. For the C6713 DSK, there are three support libraries needed:csl6713.lib, dsk6713bsl.lib, and rts6700.lib. The first is a chip support library, thesecond a board support library, and the third is a real-time support library.Besides the above support libraries, there is a GEL (general extension language) file(dsk6211 6713.gel) used to initialize the DSK. The GEL file was automatically addedwhen the project file Lab07.pjt was created, but the other libraries must be explicitly

    included in the same manner as the pre-vious files. Go to Projectand then Add Filesto Project. For Files of type, select Ob-ject and Library Files (*.o*,*.l*). Navigate tothe path u:\DSP\Support and select the files csl6713.lib,. . . . In the left sub-window ofthe CCS main window, double-click on the folder Librariesto make sure the file wasadded correctly.These files, along with our other support files, form the black box that will be requiredfor every project created in this class. The only files that change are the source codefiles that code a DSP algorithm and possibly a vectors file.7.4 Adding Source Code Files to a ProjectThe last file that you need to add to led.pjt is your C source code file. This file willcontain the code needed to control the leds through the DIP switch. Go back to Projectand then Add Files to Project . . ., but this time browse to the path u:\DSP\Lab 08.Click on the file led.c and add it to your project by clicking on Open. You may have

    noticed that the .h files cannot be added there is no Files of typeentry for .h files.Instead, they are added in the following manner: go to Projectand select Scan AllDependencies. In CCS, double-click on led.ctand then double-click on Include. Youshould see any header files on an #include line in your source files (includingc6713dskinit.c) plus approximately 14 other header files found by the scan step. Thelatter files are supplied with the Code Composer Studio software and are used toconfigure the DSP chip and board. CCS automatically found and included all neededheader files starting from the header files included in the source files. Openc6713dskinit.c and observe that it includes c6713dskinit.h; this header and dsk6713aic23.h (included in led.c) include other header files which in turn include others,leading to the list observed. Note that some include files are prefixed csl ; these are chipsupportheader files supplied by TI. The file dsk6713.h is a top level header file supplied

    by the DSK board manufacturer, Spectrum Digital, Inc.

    The project file Lab08.pjt has now been charged with all of the files required to build thefirst executable .out file.7.5. Build OptionsThe next objective is to customize the compiler and linker options so that theexecutable file gets built correctly. Also, the compiler will first convert the C coded

    programs into DSP assembly programs before it compiles them into machine code. Byselecting the appropriate options, we can keep these intermediate assembly files. Foryour own amusement, you can open these files in word processing program to see howthe DSP assembly is coded.To make these customizations, click on the Projectpull-down menu, go to BuildOptions. This will open up a new window. In this window, click on the Compilertab.In the Categorycolumn, click on Basicand select the following:Target Version: 671x

    Generate Debug Info: Full Symbolic Debug (-g)Opt Speed vs. Size: Speed Most Critical (no ms)Opt Level: NoneProgram Level Opt: NoneThen click on the Advancedentry in the Categorycolumn and select:Memory Models: Farand click on the Preprocessorentry in the Categorycolumn and type into the boxesthe following text:Include Search Path (-i): u:\DSP\Support

  • 8/10/2019 Dsp Manual Hamdard

    47/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 46 Compiled By: Engr. Hira

    Waris

    Pre-defined Symbol (-d) : CHIP_6713In the top part of the current window, you should see:-g -k -s -fru:\dsp\lab 01\sine gen\Debug-i..\..\Support-d"CHIP 6713"-mv6710 --mem model:data=farSee Figure below.

    Now click on the Linkertab on the top of the current window and make sure thefollowing command appears in the top-most window (See Figur below):

    -q -c -o".\Debug\sine gen.out" -xThe options -g, -k, -s in the compiler options and -g, -c, -o in the linker options do serveapurpose, but we will not be concerned with them just yet.Your project and project file Lab07.prj has now been created. This process iscumbersome, but it only needs to be done once. In future projects, you will be able tocopy this project file into another folder and make a few simple modifications. Thesemodifications include altering the C code and editing one linker option.

  • 8/10/2019 Dsp Manual Hamdard

    48/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 47 Compiled By: Engr. Hira

    Waris

    7.6. Building and Running the ProjectNow you must build and run the project. To build the first project, go to Projectpulldownmenu in the CCS window, then select Build(or press the button with three red

    down arrows on the top toolbar in the CCS window). A new sub-window will appear onthe bottom of the CCS window. When building is complete, you should see the followingmessage in the new sub-window:Build Complete,0 Errors, 2 Warnings, 0 Remarks.When CCS builtyour project, it compiled the C coded source files and header filesinto assembly code, using a built-in compiler. Then it assembled the assembly code intoa COFF (common object file format) file that contains the program instructions,organized into modules. Finally, the linker organized these modules and the run-timesupport library (rts6701.lib) into memory locations to create the executable .out fileled.out. The executable file, led.out, may be downloaded onto the DSK. When led.out isloaded onto the DSK, the assembled program instructions, global variables, and runtimesupport libraries are loaded to their linker-specified memory locations.At this point, you should have the following file structure established on your u:\ drive:

    1. u:\DSP\Supportc6713dsk.h. . .2. u:\DSP\Lab07\led.pjt, led.c3. u:\DSP\Lab07\Debugled.outIn order to test the program led.out on the DSK, it must first be loaded onto the DSK

    board. Before a new program is loaded onto the board, it is good practice to reset the

  • 8/10/2019 Dsp Manual Hamdard

    49/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 48 Compiled By: Engr. Hira

    Waris

    CPU. To reset the CPU, click on the Debugpull-down menu and select Reset CPU.

    Then, to load the program onto the DSK, click on the Filepull-down menu and selectLoad Program. In the new window that appears, double-click on the folder Debug,click on the file led.out, and click on Open. This will download the executable fileled.out onto the DSK. A new window will appear within CCS entitled Disassembly,which contains the assembled version of your program. Ignore this window for now.

    In CCS, select the

    Debug

    pull down menu and then select

    Run

    , or just simply click onthe top running manon the left side toolbar. Verify by pressing down the DIPswitches that which led turns on. After you have completed both of these tasks, eitherclick on the icon of the blue running manwith a red Xon it or go to the Debugpulldownmenu to select Halt.

  • 8/10/2019 Dsp Manual Hamdard

    50/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 49 Compiled By: Engr. Hira

    Waris

    LAB 10

    SAMPLING IN CCS AND C6713

    Introduction

    In this laboratory you will learn to configure sampling rate in CCS. Lab will also gothrough signal generation using lookup tables. A table is created via MATLAB withthe values of sine wave. The sampling frequency that is set in CCS is used togenerate the table in MATLAB.1. Open and run the tone.pjt project located at

    C:\CCStudio_v3.1\examples\dsk6713\bsl\tone2. The frequency of the signal is 1KHz. Change this frequency to 2KHz.Hint: Use MATLAB to get a signal of 2 KHz and use its value.3. Now, change the frequency to 3 KHz.4. This time change the frequency to 4 KHz. What do you notice?5. Change the sampling frequency to 48 KHz. The following instruction can beused to change the frequency of the codec.DSK6713_AIC23_setFreq(hAIC23_handle, DSK6713_AIC23_FREQ_48KHZ);You will have to obtain a new lookup table for 1 KHz signal from MATLAB.

  • 8/10/2019 Dsp Manual Hamdard

    51/52

    DSP Lab Manual Approved By: Engr. IR Rao

    Hamdard University, Islamabad Campus Page 50 Compiled By: Engr. Hira

    Waris

    LAB 11: FIR FILTER DESIGN IN CCS

    Introduction

    In this laboratory you will design FIR filters and will learn more about the capabilities of theC6713. Filtering is one of the most useful signal processing operations. DSPs are nowavailable to implement digital filters in real time. A FIR filter operates on discrete-timesignals and can be implemented on a DSP such as the TMS320C6x. This process involves theuse of an ADC to acquire an external input signal, processing of the samples, and sendingthe result through a DAC. Filter characteristics such as center frequency, bandwidth, andfilter type can be readily implemented and modified.Lab Excercises:1. Open and run the FIR project2. There are four different filter coefficients saved in four *.dat files. Providethe time and frequency plots for each.3. Apply a signal from MATLAB and show the effect on the signal after it

    passes through the filter(s).

  • 8/10/2019 Dsp Manual Hamdard

    52/52

    DSP Lab Manual Approved By: Engr. IR Rao

    LAB 12: IIR FILTER DESIGN IN CCS

    Introduction

    In this laboratory you will design IIR filters with different. The FIR discussed inthe previous laboratory does not have an analog counterpart. Design of IIR filters,on the other hand, usually makes use of the vast knowledge already available onanalog filters. The design procedure involves converting an analog filter to adiscrete filter using a transformation.Consider the general input-output equation

    or equivalently,

    This recursive equation represents an IIR. The z-domain representation of the

    input-output equation described above can be implemented using differentstructures: namely Direct Forms I & II. The Direct Form I structure requires 2Ndelay elements for an Nth order filter. Direct Form II is one of the most commonlyused structures as it requires half as many delays. A Direct Form II implementationwould require the use of an intermediate variable w(n),

    Taking the z-transform we find,

    Thus

    It is possible to implement higher order systems, i.e. fourth order IIR structures, asa cascade of Direct Form II second sections.Digital Signal ProcessingLab Manual Fall 201052Lab Excercises:1. Open and run the IIR project2. There are four different filter coefficients saved in four *.dat files. Providethe time and frequency plots for each.

    3. Apply a signal from MATLAB and show the effect on the signal after itpasses through the filter(s).