You are on page 1of 82

M.E.

(3/4) I Semester
EC 667-1

ADVANCED SIGNAL PROCESSING LAB

List of Experiments Prescribed By Osmania University


(A) SECTION - 1
1. Generating Basic Waveforms (Impulse, Step, Ramp, Sin, Exponential.)
2. Digital FIR implementation and realizations: with and without windows.
3. Design of IIR filters (Butterworth and Chebychev).
4. Generation of Musical effects using digital filters.
5. Using the Simulink generate the basic waveforms (Impulse, Step, Ramp, Sin,
Exponential.), observe the waveforms on the CRO.
6. Using the Simulink generate the modulated waveforms.
7. Study and implementation of Sigma-Delta modulator/Transmultiplexer.
8.
(B) SECTION - 2
1. Declaring and initializing the variables and moving the data to and from Memory (register
to memory, memory to register)
2. Setting up Circular buffering, hardware loops:
a. Adding the 10 consecutive numbers
b. Splitting the number
c. Bit level operation
3. Understanding the DSP MAC capabilities: windowing, convolution & filtering.
4. Understanding the DSP parallel instruction optimization
a. FFT without parallel instructions
b. FFT with parallel instructions
5. Creation of periodic waveforms and noise sequences using the DSP kit
6. Interfacing the DSP processor in real-time.
7. Initialization of Audio Codec.

DIGITAL SIGNAL PROCESSING LAB


CONTENTS
S.No.

NAME OF THE EXPERIMENT

Page No.

CYCLE I (Using MATLAB)


*1

Generation of Sequences

*2

Operations on Sequences

Linear Convolution

14

Circular Convolution.

16

DFT and IDFT

18

Generation of Windows

23

FIR Filter Design using Windows

25

8.

IIR filters
a. IIR Butterworth filter
b. IIR Chebyshev filter (type-I)

30

FFT and IFFT

43

Sampling Theorem

45

Interpolation and decimation

47

9.
*10.
11

37

*Experiments beyond the syllabus

S.No.

NAME OF THE EXPERIMENT

Page No.

CYCLE - II (Using Code Composer Studio (CCS)


12.

Linear Convolution

49

13.

Circular Convolution

55

14.

Advance Discrete time filter design (FIR)

63

15.

Advance Discrete time filter design (IIR)

74

16.

Difference Equation

85

17.

Impulse Response

86

INTRODUCTION
MATLAB: MATLAB is a software package for high performance numerical computation
and visualization provides an interactive environment with hundreds of built in functions for
technical computation, graphics and animation. The MATLAB name stands for MATrix
Laboratory

At its core ,MATLAB is essentially a set (a toolbox) of routines (called m files or


mex files) that sit on your computer and a window that allows you to create new variables
with names (e.g. voltage and time) and process those variables with any of those routines (e.g.
plot voltage against time, find the largest voltage, etc).
It also allows you to put a list of your processing requests together in a file and save
that combined list with a name so that you can run all of those commands in the same order at
some later time. Furthermore, it allows you to run such lists of commands such that you pass
in data and/or get data back out (i.e. the list of commands is like a function in most
programming languages). Once you save a function, it becomes part of your toolbox (i.e. it
now looks to you as if it were part of the basic toolbox that you started with).
For those with computer programming backgrounds: Note that MATLAB runs as an
interpretive language (like the old BASIC). That is, it does not need to be compiled. It simply
reads through each line of the function, executes it, and then goes on to the next line. (In
practice, a form of compilation occurs when you first run a function, so that it can run faster

the next time you run it.)

MATLAB Windows:
MATLAB works with through three basic windows
Command Window : This is the main window .it is characterized by MATLAB command
prompt >> when you launch the application program MATLAB puts you in this window all
commands including those for user-written programs ,are typed in this window at the
MATLAB prompt
Graphics window: the output of all graphics commands typed in the command window are
flushed to the graphics or figure window, a separate gray window with white background
color the user can create as many windows as the system memory will allow
Edit window: This is where you write edit, create and save your own programs in files called
M files.
Input-output:MATLAB supports interactive computation taking the input from the screen
and flushing, the output to the screen. In addition it can read input files and write output files
Data Type: the fundamental data type in MATLAB is the array. It encompasses several
distinct data objects- integers, real numbers, matrices, charcter strings, structures and
cells.There is no need to declare variables as real or complex, MATLAB automatically sets
the variable to be real.
Dimensioning: Dimensioning is automatic in MATLAB. No dimension statements are
required for vectors or arrays .we can find the dimensions of an existing matrix or a vector
with the size and length commands.
Where to work in MATLAB?
All programs and commands can be entered either in
the a) Command window
b) As an M file using MATLAB editor
Note: Save all M files in the folder 'work' in the current directory. Otherwise you
have to locate the file during compiling. Typing quit in the command prompt>> quit,
will close MATLAB.
For any clarification regarding plot etc, which are built in functions type help
topic i.e. help plot
Basic Instructions in Mat lab
1. T = 0: 1:10
This instruction indicates a vector T which as initial value 0 and final value 10 with an
increment of 1

Therefore T = [0 1 2 3 4 5 6 7 8 9 10]
2. F= 20: 1: 100
Therefore F = [20 21 22 23 24 100]
3. T= 0:1/pi: 1
Therefore T= [0, 0.3183, 0.6366, 0.9549]
4. zeros (1, 3)
The above instruction creates a vector of one row and three columns whose values are zero
Output= [0 0 0]
5. zeros ( 2,4)
Output =

0000
0000

6. ones (5,2)
Output =

11
11
11
11
11
8. A=[1 2 3] B=[4 5 6] , then A.*B = [4 10 18]
9. If C=[2 2 2]
B.*C results in [8 10 12]
9. Plot (t,x)
If x= [6 7 8 9] t= [1 2 3 4]
This instruction will display a figure window which indicates the plot of x versus t

10. stem (t,x) :-This instruction will display a figure window as shown

11. Subplot: This function divides the figure window into rows and columns.
Subplot (2 2 1) divides the figure window into 2 rows and 2 columns 1 represent
number of the figure

Subplot (3 1 2) divides the figure window into 3 rows and 1 column 2 represent
number of the figure
12. Conv
Syntax: w = conv(u,v)
Description: w = conv(u,v) convolves vectors u and v. Algebraically, convolution is the same
operation as multiplying the polynomials whose coefficients are the elements of u and v.
13.Disp
Syntax: disp(X)
Description: disp(X) displays an array, without printing the array name. If X contains a text
string, the string is displayed. Another way to display an array on the screen is to type its
name, but this prints a leading "X=," which is not always desirable. Note that disp does not
display empty arrays.
14.xlabel
Syntax: xlabel('string')
Description: xlabel('string') labels the x-axis of the current axes.
15. ylabel

Syntax : ylabel('string')
Description: ylabel('string') labels the y-axis of the current axes.
16.Title
Syntax : title('string')
Description: title('string') outputs the string at the top and in the center of the current axes.
17.grid on
Syntax : grid on
Description: grid on adds major grid lines to the current axes.
18.FFT Discrete Fourier transform.
FFT(X) is the discrete Fourier transform (DFT) of vector X. For matrices, the FFT operation
is applied to each column. For N-D arrays, the FFT operation operates on the first nonsingleton dimension.
FFT(X,N) is the N-point FFT, padded with zeros if X has less than N points and truncated if
it has more.

19. ABS Absolute value.


ABS(X) is the absolute value of the elements of X. When X is complex, ABS(X) is the
complex modulus (magnitude) of the elements of X.
20. ANGLE Phase angle.
ANGLE(H) returns the phase angles, in radians, of a matrix with complex elements.

21.INTERP Resample data at a higher rate using lowpass interpolation.


Y = INTERP(X,L) resamples the sequence in vector X at L times the original sample rate.
The resulting resampled vector Y is L times longer, LENGTH(Y) = L*LENGTH(X).
22. DECIMATE Resample data at a lower rate after lowpass filtering.
Y = DECIMATE(X,M) resamples the sequence in vector X at 1/M times the original
sample rate. The resulting resampled vector Y is M times shorter, i.e., LENGTH(Y) =
CEIL(LENGTH(X)/M). By default, DECIMATE filters the data with an 8th order Chebyshev
Type I lowpass filter with cutoff frequency .8*(Fs/2)/R, before resampling.

1. Generation of Sequences
AIM: Generate different types of Sequences (Waveforms)
Apparatus Required: - System with MATLAB
Algorithm: - 1. Get the number of samples.
2. Generate the unit step, unit impulse, unit ramp using for and if else using C
syntax.
3. Generate ramp, sine, cosine and exponential signals using corresponding
general formula.
4. Plot the graph.
Procedure:-1) Open MATLAB
2) Open new M-file
3) Type the program
4) Save in current directory
5) Compile and Run the program
6) For the output see command window\ Figure window

1. Unit step.
r=6;
for n=-r:r
if(n>=0)
x=1
else
x=0
end
stem(n,x)
hold on
end

Fig.1
2. Unit Impulse.
r=6;
for n=-r:r
if(n==0)
x=1;
else
x=0;
end
stem(n,x);
hold on
end

Fig.2
3. Unit Ramp.
r=9;
for n=r
if(n>=0)
x=n;
else
x=0;
end
stem(n,x);
hold on
end

Fig.3
4. Sinusoidal sequence.
n=-0:(2*pi)/50:4*pi
x=sin(n)
stem(n,x)

Fig.4

5. Exponential Sequence.
n=0:.1:10
x=exp(n)
stem(n,x)

Fig.5
6. Complex Exponential.
clear all;
a=4

b=3
c=input('enter value of n=' )
d=100
for n=-c:0.1:c;
x=a*exp(b*n)*cos(d*n);
stem(n,x);
hold on
end
stem(n,x)

Fig .6

2. FIR Filter Design using Windows


AIM: Design FIR low-pass, hi-pass, band-pass, band-stop filters using windows
Apparatus Required: - System with MATLAB
Procedure:-1) Open MATLAB
2) Open new M-file
3) Type the program
4) Save in current directory
5) Compile and Run the program
6) For the output see command window\ Figure window
1. Low pass filter
N=input('enter order of filter');
Fp=input('enter pass band edge freq.');
Fs=input('enter sampling frequency');
Wp=2*pi*Fp/Fs;
b1=fir1(N,Wp,boxcar(N+1));
b2=fir1(N,Wp,triang(N+1));
[h,w]=freqz(b1,1);
plot(w/pi,20*log10(abs(h)));
hold on
[h,w]=freqz(b2,1);
plot(w/pi,20*log10(abs(h)),'-g');
holdo ff
INPUTS:
Enter order of filter=21
N = 21
Enter pass band edge freq.500
Fp = 500
Enter sampling frequency5000
Fs = 5000
OUTPUTS:
Wp = 0.6283

Fig .7
2. High pass Filter.
N=input('enter order of filter');
Fp=input('enter pass band edge freq.');
Fs=input('enter sampling frequency');
Wp=2*pi*Fp/Fs;
b1=fir1(N,Wp,'high',boxcar(N+1));
b2=fir1(N,Wp,'high',blackman(N+1));
[h,w]=freqz(b1,1);
plot(w/pi,20*log10(abs(h)));
hold on
[h,w]=freqz(b2,1);
plot(w/pi,20*log10(abs(h)),'-g');
xlabel('normalized frequency');
ylabel('Magnitude in Db');
title('Low pass frequency response');
hold off
INPUTS:
enter order of filter=20
N = 20
enter pass band edge freq.500

Fp = 500
enter sampling frequency5000
Fs = 5000
OUTPUT:

Fig .8
3. Band Stop filter
N=input('enter order of filter');
fl=input('enter lower cutoff freq.');
fh=input('enter higher cutoff freq.');
Fs=input('enter sampling frequency');
Wp1=2*pi*fl/Fs;
Wp2=2*pi*fh/Fs;
Wp=[Wp1,Wp2];
b1=fir1(N,Wp,'stop',hamming(N+1));
b2=fir1(N,Wp,'stop',Blackman(N+1));
[h,w]=freqz(b1,1);
plot(w/pi,20*log10(abs(h)));
hold on
[h,w]=freqz(b2,1);
plot(w/pi,20*log10(abs(h)),'-.g');
hold off

INPUT:
Enter order of filter20
Enter lower cutoff freq.200
Enter higher cutoff freq.800
Enter sampling frequency10000

Fig .9
4. Band Pass filter
N=input('enter order of filter');
fl=input('enter lower cutoff freq.');
fh=input('enter higher cutoff freq.');
Fs=input('enter sampling frequency');
Wp1=2*pi*fl/Fs;
Wp2=2*pi*fh/Fs;
Wp=[Wp1,Wp2];
b1=fir1(N,Wp,bartlett(N+1));
b2=fir1(N,Wp,Blackman(N+1));
[h,w]=freqz(b1,1);
plot(w/pi,20*log10(abs(h)));
hold on
[h,w]=freqz(b2,1);
plot(w/pi,20*log10(abs(h)),'-.g');
hold off
INPUT:
enter order of filter20

enter lower cutoff freq.200


enter higher cutoff freq.800
enter sampling frequency10000

Fig .10

3. a) IIR Butterworth Filter


AIM: Design IIR Butterworth low-pass, hi-pass, band-pass, band-stop filters
Apparatus Required: - System with MATLAB
Procedure:-1) Open MATLAB
2) Open new M-file
3) Type the program
4) Save in current directory
5) Compile and Run the program
6) For the output see command window\ Figure window

1. Low pass Filter


fp=input('Enter pass band freq :');
fs=input('Enter stop band freq :');
Fs=input('enter Sampling frequency');
rp=input('Enter pass band ripple:');
rs=input('Enter stop band ripple:');
wp=2*pi*fp/Fs;
ws=2*pi*fs/Fs;
[N,wc]=buttord(wp,ws,rp,rs);
[b,a]=butter(N,wc);
[h,w1]=freqz(b,a);
plot(w1/pi,20*log10(abs(h)));
xlabel('normalized frequency');
ylabel('Magnitude in dB');
title('Frequency response of High pass filter');
INPUTS:
Enter pass band freq: 200
fp = 200
Enter stop band freq: 800
fs = 800
enter Sampling frequency10000

Enter pass band ripple: 1


rp = 1
Enter stop band ripple: 20
rs = 20
OUTPUT:
Order N = 2
3dB-Cutoff frequency wc = 0.1970

Fig .11
2. High Pass Filter
fp=input('Enter pass band freq :')
fs=input('Enter stop band freq :')
Fs=input('enter Sampling frequency');
rp=input('Enter pass band ripple:');
rs=input('Enter stop band ripple:');
wp=2*pi*fp/Fs;
ws=2*pi*fs/Fs;
[N,wc]=buttord(wp,ws,rp,rs)
[b,a]=butter(N,wc,'high');
[h,w1]=freqz(b,a);
plot(w1/pi,20*log10(abs(h)));
xlabel('normalized frequency');
ylabel('Magnitude in dB');
title('Frequency response of High pass filter');

INPUTS:
Enter pass band freq: 200
fp = 200
Enter stop band freq: 100
fs = 100
enter Sampling frequency2000
Enter pass band ripple: 1
Enter stop band ripple: 20
OUTPUT:
N=3
wc = 0.5462

Fig .12

3. Band Pass Filter


fp1=input('Enter pass band freq1:')
fp2=input('Enter pass band freq2:')
fs1=input('Enter stop band freq1 :')
fs2=input('Enter stop band freq2 :')
Fs=input('Enter sampling Frequency');
rp=input('Enter pass band ripple:')
rs=input('Enter stop band ripple:')
fp=[fp1,fp2];
fs=[fs1,fs2];
wp=2*pi*fp/Fs;
ws=2*pi*fs/Fs;
[N,wc]=buttord(wp,ws,rp,rs)
[b,a]=butter(N,wc)
[h,w1]=freqz(b,a)
plot(w1/pi,20*log10(h))
xlabel('normalized frequency');
ylabel('Magnitude in Db');
title('Frequency response of Band pass filter');
INPUTS:
Enter pass band freq1:400
Enter pass band freq2:600
Enter stop band freq1 :200
Enter stop band freq2 :800
Enter sampling Frequency10000
Enter pass band ripple:1
Enter stop band ripple:20

OUTPUTS:
Order of the filter N = 3
3dB cutoff frequencies wc = 0.2346

0.3997

Fig .13
4. Band stop filter
fp1=input('Enter pass band freq1:');
fp2=input('Enter pass band freq2:');
fs1=input('Enter stop band freq1 :');
fs2=input('Enter stop band freq2 :');
Fs=input('Enter sampling Frequency');
rp=input('Enter pass band ripple:');
rs=input('Enter stop band ripple:');
fp=[fp1,fp2];
fs=[fs1,fs2];
wp=2*pi*fp/Fs;
ws=2*pi*fs/Fs;
[N,wc]=buttord(wp,ws,rp,rs)
[b,a]=butter(N,wc,'stop');
[h,w1]=freqz(b,a);
plot(w1/pi,20*log10(h));

xlabel('normalized frequency');
ylabel('Magnitude in Db');
title('Frequency response of Band stop filter');

INPUTS:
Enter pass band freq1:200
Enter pass band freq2:800
Enter stop band freq1 :400
Enter stop band freq2 :600
Enter sampling Frequency10000
Enter pass band ripple:1
Enter stop band ripple:20
OUTPUTS:
Order N = 3
3dB cutoff frequency wc = 0.1979

Fig .14

0.4566

3. b) IIR Chebyshev Filter (type-I)


AIM: Design IIR Chebyshev low-pass, hi-pass, band-pass, band-stop filters
Apparatus Required: - System with MATLAB
Procedure:-1) Open MATLAB
2) Open new M-file
3) Type the program
4) Save in current directory
5) Compile and Run the program
6) For the output see command window\ Figure window
1. Low Pass Filter
fp=input('Enter pass band freq :')
fs=input('Enter stop band freq :')
Fs=input('enter Sampling frequency');
rp=input('Enter pass band ripple:');
rs=input('Enter stop band ripple:');
wp=2*pi*fp/Fs;
ws=2*pi*fs/Fs;
[N,wc]=cheb1ord(wp,ws,rp,rs)
[b,a]=cheby1(N,rp,wc);
[h,w1]=freqz(b,a);
plot(w1/pi,20*log10(abs(h)));
xlabel('normalized frequency');
ylabel('Magnitude in dB');
title('Frequency response of Low pass filter');
axis([0,1,-5,0]);
INPUTS:
Enter pass band freq: 400
Enter stop band freq: 800
Enter Sampling frequency: 10000
Enter pass band ripple: 1
Enter stop band ripple: 20

OUTPUTS:
Order N = 3
3dB cutoff frequency wc = 0.2513

Fig .15
2. High Pass Filter
fp=input('Enter pass band freq :')
fs=input('Enter stop band freq :')
Fs=input('enter Sampling frequency');
rp=input('Enter pass band ripple:');
rs=input('Enter stop band ripple:');
wp=2*pi*fp/Fs;
ws=2*pi*fs/Fs;
[N,wc]=cheb1ord(wp,ws,rp,rs)
[b,a]=cheby1(N,rp,wc,'high');
[h,w1]=freqz(b,a);
plot(w1/pi,20*log10(abs(h)));
xlabel('normalized frequency');
ylabel('Magnitude in dB');
title('Frequency response of High pass filter');
axis([0,1,-5,0]);

INPUTS:
Enter pass band freq: 400
Enter stop band freq: 800
Enter Sampling frequency: 10000
Enter pass band ripple: 1
Enter stop band ripple: 20
OUTPUTS:
N=3
wc = 0.2513

Fig .16

3. Band Pass Filter.


rs=input('Enter stop band ripple:');
fp=[fp1,fp2];
fs=[fs1,fs2];
wp=2*pi*fp/Fs;
ws=2*pi*fs/Fs;
[N,wc]=cheb1ord(wp,ws,rp,rs)
[b,a]=cheby1(N,rp,wc)
[h,w1]=freqz(b,a)
plot(w1/pi,20*log10(abs(h)))
xlabel('normalized frequency');
ylabel('Magnitude in Db');
title('Frequency response of Band pass filter');
axis([0,1,-20,0]);

INPUTS:
Enter pass band freq1:400
Enter pass band freq2:600
Enter stop band freq1:200
Enter stop band freq2:800
Enter sampling Frequency: 10000
Enter pass band ripple: 1
Enter stop band ripple: 20
OUTPUTS:
Order of the filter N = 3
3dB cutoff frequency wc = 0.2513

0.3770

Fig .17
4. Band stop filter
rs=input('Enter stop band ripple:');
fp=[fp1,fp2];
fs=[fs1,fs2];
wp=2*pi*fp/Fs;
ws=2*pi*fs/Fs;
[N,wc]=cheb1ord(wp,ws,rp,rs)
[b,a]=cheby1(N,rp,wc,'stop');
[h,w1]=freqz(b,a);
plot(w1/pi,20*log10(abs(h)));
xlabel('normalized frequency');
ylabel('Magnitude in Db');
title('Frequency response of Band stop filter');
axis([0,1,-20,0]);
INPUTS:
Enter pass band freq1:200
Enter pass band freq2:800
Enter stop band freq1:400
Enter stop band freq2: 600
Enter sampling Frequency: 10000

Enter pass band ripple: 1


Enter stop band ripple: 20

OUTPUTS:
N=3
wc = 0.1257

0.5027

Fig .18

5. Generation of Musical Effects Using Digital Filters


AIM: To generate musical effects using digital filter
Apparatus Required: - System with MATLAB
Procedure:-1) Open MATLAB
2) Open new M-file
3) Type the program
4) Save in current directory
5) Compile and Run the program
6) For the output see command window\ Figure window

PROGRAM:
Definition of the function "note"
function tone = note(freq,dur,fs)
t=0:1/fs:dur;
x=t/dur;
envelope=x.*(1-x).*(exp(-8*x)+0.5*x.*(1-x));
beat=0.08;
harmonic0=sin(2*pi*freq*t*(1-beat))+sin(2*pi*freq*t*(1+beat));
harmonic1=sin(2*pi*2*freq*t*(1-beat))+sin(2*pi*2*freq*t*(1+beat));
harmonic2=sin(2*pi*3*freq*t*(1-beat))+sin(2*pi*3*freq*t*(1+beat));
tone=envelope.*(harmonic0+0.2*harmonic1+0.05*harmonic2);
tone=tone/max(tone);

Concatenating the tones using "note" function.


clc;
clear all;
close all;
freq=[1319 1319 1397 1568 1568 1397 1319 1175 1047 1047 1175 1319 1319 1175 1175];
dur=[ 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4];
music=[];
for i=1:length(freq)
m=note(freq(i),dur(i),16000);
music=[music,m];
end

Now we down sample the signal by a factor dsr:


clc;
clear all;
close all;
dsr=input('enter the down sampling factor');
msc=music(1:dsr:length(music));
subplot(3,1,1);
plot(music);
title('music');
subplot(3,1,2);
plot(msc);
title('down sampled music');

Filtering
f_c=fir1(64,1/dsr); %fir1 call will apply filter to the music
music_f=filter(f_c,1,music); %filter call will apply filter to the music
subplot(3,1,3);
plot(music_f);
title('filtered music');
soundsc(music);

Fig.19
Observations: Here we considered an oversampled data (music) and then down sampled it
without filtering in the first stage and then after filtering. We again down sampled thus the
quality improvement can be observed by listening to it using soundsc(); We can also observe
that for higher values of down sampling factor the spectrum is distorted. Hence an optimum
value is to be choosen.
Conclusion: We are able to generate an aliasing-free concatenated music tone by a three step
procedure by oversampling, then passing it through a filter and finally down sampling it.

Simulink Basics Tutorial


Simulink is a graphical extension to MATLAB for the modeling and simulation of
systems. In Simulink, systems are drawn on screen as block diagrams. Many elements of
block diagrams are available (such as transfer functions, summing junctions, etc.), as well as
virtual input devices (such as function generators) and output devices (such as
oscilloscopes). Simulink is integrated with MATLAB and data can be easily transferred
between the programs. In this tutorial, we will introduce the basics of using Simulink to
model and simulate a system.
Simulink is supported on Unix, Macintosh, and Windows environments, and it is
included in the student version of MATLAB for personal computers. For more information
on Simulink, contact the Math Works.
Starting Simulink
Simulink is started from the MATLAB command prompt by entering the following
command:
simulink
Alternatively, you can click on the "Simulink Library Browser" button at the top of the
MATLAB , command window as shown below:

The Simulink Library Browser window should now appear on the screen. Most of the blocks
needed for modeling basic systems can be found in the subfolders of the main "Simulink"
folder (opened by clicking on the "+" in front of "Simulink"). Once the "Simulink" folder
has been opened, the Library Browser window should look like:

Basic Elements
There are two major classes of elements in Simulink: blocks and lines. Blocks are used to
generate, modify, combine, output, and display signals. Lines are used to transfer signals
from one block to another.
Blocks
The subfolders underneath the "Simulink" folder indicate the general classes of blocks
available for us to use:
Continuous: Linear, continuous-time system elements (integrators, transfer
functions, state-space models, etc.)
Discrete: Linear, discrete-time system elements (integrators, transfer functions,
state- space models, etc.)
Functions & Tables: User-defined functions and tables for interpolating function
values
Math: Mathematical operators (sum, gain, dot product, etc.)
Nonlinear: Nonlinear operators (coulomb/viscous friction, switches, relays,
etc.) Signals & Systems: Blocks for controlling/monitoring signal(s) and for
creatingsubsystems
Sinks: Used to output or display signals (displays, scopes, graphs,

etc.) Sources: Used to generate various signals (step, ramp,


sinusoidal, etc.)
Blocks have zero to several input terminals and zero to several output terminals. Unused
input terminals are indicated by a small open triangle. Unused output terminals are indicated
by a small triangular point. The block shown below has an unused input terminal on the left
and an unused output terminal on the right.

Lines
Lines transmit signals in the direction indicated by the arrow. Lines must always transmit
signals from the output terminal of one block to the input terminal of another block. One
exception to this is that a line can tap off of another line. This sends the original signal to
each of two (or more) destination blocks, as shown below:

Lines can never inject a signal into another line; lines must be combined through the use
of a block such as a summing junction.
A signal can be either a scalar signal or a vector signal. For Single-Input, Single-Output
systems, scalar signals are generally used. For Multi-Input, Multi-Output systems, vector
signals are often used, consisting of two or more scalar signals. The lines used to transmit
scalar and vector
signals are identical. The type of signal carried by a line is determined by the blocks on
either end of the line.
Building a System
To demonstrate how a system is represented using Simulink, we will build the block
diagram for a simple model consisting of a sinusoidal input multiplied by a constant gain,
which is shown below:

This model will consist of three blocks: Sine Wave, Gain, and Scope. The Sine Wave is a
Source Block from which a sinusoidal input signal originates. This signal is transferred
through a line in the direction indicated by the arrow to the Gain Math Block. The Gain
block modifies its input signal (multiplies it by a constant value) and outputs a new signal
through a line to the Scope block. The Scope is a Sink Block used to display a signal
(much like an oscilloscope).
We begin building our system by bringing up a new model window in which to create the
block diagram. This is done by clicking on the "New Model" button in the toolbar of the
Simulink Library Browser (looks like a blank page).
Building the system model is then accomplished through a series of steps:
1. The necessary blocks are gathered from the Library Browser and placed in the model
window.
2. The parameters of the blocks are then modified to correspond with the system we
are modelling.
3. Finally, the blocks are connected with lines to complete the model.
Each of these steps will be explained in detail using our example system. Once a system is
built, simulations are run to analyze its behavior.
Gathering Blocks
Each of the blocks we will use in our example model will be taken from the Simulink
Library
Browser. To place the Sine Wave block into the model window, follow these steps:
1. Click on the "+" in front of "Sources" (this is a subfolder beneath the "Simulink"
folder)
to display the various source blocks available for us to use.
2. Scroll down until you see the "Sine Wave" block. Clicking on this will display a
short explanation of what that block does in the space below the folder list:

3. To insert a Sine Wave block into your model window, click on it in the Library
Browser and drag the block into your workspace. The same method can be used to place
the Gain and Scope blocks in the model window. The "Gain" block can be found in the
"Math" subfolder and the "Scope" block is located in the "Sink" subfolder. Arrange the
three blocks in the workspace (done by selecting and dragging an individual block to a
new location) so that they look similar to the following:

Modifying the Blocks


Simulink allows us to modify the blocks in our model so that they accurately reflect
the characteristics of the system we are analyzing. For example, we can modify the
Sine Wave block by double-clicking on it. Doing so will cause the following window
to appear:

This window allows us to adjust the amplitude, frequency, and phase shift of the
sinusoidal input. The "Sample time" value indicates the time interval between successive
readings of the signal. Setting this value to 0 indicates the signal is sampled
continuously.
Let us assume that our system's sinusoidal input
has: Amplitude = 2
Frequency = pi
Phase =
pi/2
Enter these values into the appropriate fields (leave the "Sample time" set to 0) and click
"OK" to accept them and exit the window. Note that the frequency and phase for our
system contain 'pi' (3.1415...). These values can be entered into Simulink just as they have
been shown.

Next, we modify the Gain block by double-clicking on it in the model window. The
following window will then appear:

Note that Simulink gives a brief explanation of the block's function in the top portion

of this window. In the case of the Gain block, the signal input to the block (u) is
multiplied by a constant (k) to create the block's output signal (y). Changing the
"Gain" parameter in this window changes the value of k.
For our system, we will let k = 5. Enter this value in the "Gain" field, and click "OK" to
close the window.
The Scope block simply plots its input signal as a function of time, and thus there are no
system parameters that we can change for it. We will look at the Scope block in more
detail after we have run our simulation.
Connecting the Blocks
For a block diagram to accurately reflect the system we are modeling, the Simulink blocks
must be properly connected. In our example system, the signal output by the Sine Wave
block is transmitted to the Gain block. The Gain block amplifies this signal and outputs its
new value to the Scope block, which graphs the signal as a function of time. Thus, we need
to draw lines from the output of the Sine Wave block to the input of the Gain block, and
from the output of the Gain block to the input of the Scope block.
Lines are drawn by dragging the mouse from where a signal starts (output terminal of
a block) to where it ends (input terminal of another block). When drawing lines, it is
important to make sure that the signal reaches each of its intended terminals. Simulink will
turn the mouse pointer into a crosshair when it is close enough to an output terminal to begin
drawing a line, and the pointer will change into a double crosshair when it is close enough to
snap to an input terminal. A signal is properly connected if its arrowhead is filled in. If the
arrowhead is open, it means the signal is not connected to both blocks. To fix an open
signal, you can treat the open arrowhead as an output terminal and continue drawing the line
to an input terminal in the same manner as explained before.

Properly Connected Signal

Open Signal

When drawing lines, you do not need to worry about the path you follow. The lines will
route themselves automatically. Once blocks are connected, they can be repositioned for a
neater appearance. This is done by clicking on and dragging each block to its desired
location (signals will stay properly connected and will re-route themselves).After drawing
in the lines and repositioning the blocks, the example system model should look like:

In some models, it will be necessary to branch a signal so that it is transmitted to two or


more different input terminals. This is done by first placing the mouse cursor at the location
where the signal is to branch. Then, using either the CTRL key in conjunction with the left
mouse button
or just the right mouse button, drag the new line to its intended destination. This method
was used to construct the branch in the Sine Wave output signal shown below:

The routing of lines and the location of branches can be changed by dragging them to their
desired new position. To delete an incorrectly drawn line, simply click on it to select it,
and hit the DELETE key.
Running Simulations
Now that our model has been constructed, we are ready to simulate the system. To do this,
go to the Simulation menu and click on Start, or just click on the "Start/Pause Simulation"
button in the model window toolbar (looks like the "Play" button on a VCR). Because our
example is a relatively simple model, its simulation runs almost instantaneously. With more
complicated systems, however, you will be able to see the progress of the simulation by
observing its running time in the the lower box of the model window. Double-click the
Scope block to view the output of the Gain block for the simulation as a function of time.
Once the Scope window appears,
click the "Autoscale" button in its toolbar (looks like a pair of binoculars) to scale the
graph to better fit the window. Having done this, you should see the following:

Note that the output of our system appears as a cosine curve with a period of 2 seconds and
amplitude equal to 10. Does this result agree with the system parameters we set? Its
amplitude makes sense when we consider that the amplitude of the input signal was 2 and
the constant gain of the system was 5 (2 x 5 = 10). The output's period should be the same
as that of the input signal, and this value is a function of the frequency we entered for the
Sine Wave block (which was set equal to pi). Finally, the output's shape as a cosine curve
is due to the phase value of pi/2 we set for the input (sine and cosine graphs differ by a
phase shift of pi/2).
The Scope graph should now look like the following:

Note that the only difference between this output and the one from our original system is the
amplitude of the cosine curve. In the second case, the amplitude is equal to 1, or 1/10th of
10, which is a result of the gain value being 1/10th as large as it originally was.

5. Generation of Basic Waveforms


AIM: Generation of Basic waveforms using Simulink
Apparatus Required: - System with MATLAB
MODEL:

Fig.20

Fig.21

6. Generation of Modulated Waveforms


AIM: Generation of Generated waveforms using Simulink
Apparatus Required: - System with MATLAB
MODEL:
a)

Amplitude Modulation

Fig.22
Output:

Fig.23
b)

Frequency Modulation

Fig.24
Output:

Fig.25

c) Phase Modulation

Fig.26
Output:

Fig.27

d)ASK & DSBSC

Fig.28
ASK output:

Fig.29

DSBSC output

Fig.30
d) SSB Moulation

Fig.31

SSB output:

Fig.32

7. Sigma Delta Modulation


AIM: Implementation of sigma delta modulation
Apparatus Required: - System with MATLAB
Procedure:-1) Open MATLAB
2) Open new M-file
3) Type the program
4) Save in current directory
5) Compile and Run the program
6) For the output see command window\ Figure window

Program: Decimation
clc
clear all
close all
t=[0:0.01:1]
m=sinc(2*pi*t)
subplot(211)
hold on
plot(m,'*black')
title('sinc pulse')
xlabel('time')
ylabel('amplitude')
d=2*pi/100
for n=1:1:100
if n==1
e(n)=m(n)
eq(n)=d*sign(e(n))
mq(n)=eq(n)
else
e(n)=m(n)-mq(n-1)
eq(n)=d*sign(e(n))
mq(n)=mq(n-1)+eq(n)
end
end
stairs(mq,'black')
hleg=legend('original signal','stair case approximated signal')
hold off
subplot(212)
hold on
m1=sin(2*pi*t)
plot(m1,'black')
title('sin wave')
xlabel('time')
ylabel('amplitude')
d=2*pi/100

for n=1:1:100
if n==1
e1(n)=m1(n)
eq1(n)=d*sign(e1(n))
mq1(n)=eq1(n)
else
e1(n)=m1(n)-mq1(n-1)
eq1(n)=d*sign(e1(n))
mq1(n)=mq1(n-1)+eq1(n)
end
end
stairs(mq1,'black')
hleg=legend('original signal','stair case approximated signal')
hold off
OUTPUT:

Fig.33

CODE COMPOSER STUDIO


&
TMS320CDSK6711

Code Composer Studio (CCS)


The Code Composer Studio (CCS) provides an integrated development environment
(IDE) to incorporate the software tools. CCS includes tools for code generation, such as a C
compiler, an assembler, and a linker. It has graphical capabilities and supports real-time
debugging. It provides an easy-to-use software tool to build and debug programs.
The C compiler compiles a C source program with extension .c to produce an
assembly source file with extension.asm. The assembler assembles an.asm source file to
produce a machine language object file with extension.obj. The linker combines object files
and object libraries as input to produce an executable file with extension.out. This executable
file represents a linked common object file format (COFF), popular in Unix-based systems
and adopted by several makers of digital signal processors [21]. This executable file can be
loaded and run directly on the C6711 processor.
To create an application project, one can add the appropriate files to the project.
Compiler/linker options can readily be specified. A number of debugging features are
available, including setting breakpoints and watching variables, viewing memory, registers,
and mixed C and assembly code, graphing results, and monitoring execution time. One can
step through a program in different ways (step into, or over, or out).
Real-time analysis can be performed using real-time data exchange (RTDX) associated
with DSP/BIOS (Appendix G).RTDX allows for data exchange between the host and the
target and analysis in real time without stopping the target. Key statistics and performance can
be monitored in real time. Through the Joint Team Action Group (JTAG), communication
with on-chip emulation support occurs to control and monitor program execution. The C6711
DSK board includes a JTA

Introduction to the C6711 DSK


The C6711 DSP Starter Kit provides system design engineers with an easy-to-use,
cost-effective way to take their high-performance TMS320C6000 designs from concept to
production. The TMS320C6711 DSK not only provides an introduction to 'C6000 technology,
but is also powerful enough to use for fast development of networking, communications,
imaging and other applications.
Operating at 150 MHz, the 'C6711 delivers an impressive 1200 MIPS and 600
MFLOPs using an innovative 2-level cache memory configuration, which provides highperformance in a very cost-effective solution. The C6711 DSK replaces and is a superset of
the C6211 DSK. The C6711 is binary code compatible with the C6211. The DSK comes with
CCS code development tools (does not include the simulator).

DSK6711 Contents
The TMS320C6711 (C6711) is based on the very-long-instruction-word (VLIW) architecture,
which is very well suited for numerically intensive algorithms. The internal program memory
is structured so that a total of eight instructions can be fetched every cycle.

Hardware
150 MHz C6711 DSP
TI 16-bit A/D Converter (AD535)
A 4-MHz clock onboard the DSK connects to this codec to provide a fixed sampling
rate of 8 kHz.
16MB (megabytes) of synchronous dynamic RAM (SDRAM) and 128kB (kilobytes) of
flash ROM
Daughter card expansion
Two connectors on the board provide input IN (J7) and output OUT (J6)
150 MHz onboard clock. Also onboard the DSK are voltage regulators that provide
1.8V for the
C6711 core and 3.3 V for its memory and peripherals.
Power Supply & Parallel Port Cable

Software
Code Generation Tools (C Compiler, Assembler & Linker)
Code Composer Debugger (256K program limitation)
Example Programs & S/W Utilities
Power-on Self Test
Flash Utility Program
Board Confidence Test
Host access via DLL
Sample Program(s)

TMS 320 C DSK 6711 Hardware Board

Once we open the CCS the main window will be look like this

PROCEDURE TO WORK ON CODE COMPOSER STUDIO :


To create the new project
Project
new (File name.pjt, eg: vectors.pjt)
To create a source file
File
new

type the code (save &give file name, eg: sum.c

To add source files to project


Project
add files to project
To add rts.lib file&hello.cmd:
Project
add files to project

sum.c

rts6700.lib

Libraryfiles: rts6700.lib
(path:c:\ti\c6000\cgtools\lib\rts6700.lib) Note: select
object&library in (*.o,*.1) in type of files
Project

add files to projects

hello.cmd

Cmd file which is common for all non real time


programs.
(path:c\ti\tutorials\dsk6711\hello.1\hello.
cmd)
Note: select linker command file (*.cmd) in type of files

Compile:
To Compile: Project
compile
To rebuild: Project
rebuild
Which will create the final.outexecutablefile (eg.vectors.out)
Procedure to load and run program:
Load the program to DSK: file
To execute project: Debug

load program
run

vectors. Out

1. LINEAR CONVOLUTION
AIM: Write a C program for linear convolution of two discrete sequences and
compute using code composer studio V2 (using simulators 64xx, 67xx, 6711)
software and TMS 320C 6711 DSK.

Program:
#include<stdio.h>
#include<math.h>
main ()
{
int x[20],h[20],y[20],N1,N2,n,m;
printf ("enter the length of the sequence x (n) :");
scanf ("%d", &N1);
printf ("enter the length of the sequence h (n) :");
scanf ("%d", &N2);
printf ("enter the sequence x (n) :");
for (n=0; n<N1; n++)
scanf ("%d", &x[n]);
printf ("enter the sequence h (n) :");
for (n=0; n<N2; n++)
scanf ("%d", &h[n]);
for (n=0; n<N1+N2-1; n++)
{
if (n>N1-1)
{
y[n]=0;
for(m=n-(N1-1);m<=(N1-1);m++)
y[n] =y[n] +x[m]*h [n-m];
}
else
{
y[n] =0;
for (m=0; m<=n; m++)
y[n] =y[n] +x[m]*h [n-m];
}
}

printf ("convolution of two sequences is y (n)


:"); for (n=0; n<N1+N2-1;n++)
printf ("%d\t", y[n]);
}
Input:
Enter the length of the sequence x (n):4
Enter the length of the sequence h (n):3
Enter the sequence x (n):1 2 3 4
Enter the sequence h (n):5 6 7
Output:
Convolution of two sequences is y (n):5

16

34

52

Result: Linear convolution of two discrete sequences is computed.

45

28

2. CIRCULAR CONVOLUTION
AIM: Write a C program for circular convolution of two discrete sequences and
compute using code composer studio V2 (using simulators 64xx, 67xx, 6711)
software and TMS 320C 6711 DSK.

Program:
#include<math.h>
#define pi 3.14
main ()
{
int x[20],h[20],y[20],N1,N2,N,n,m,k;
printf ("enter the length of the sequence x (n) :");
scanf ("%d", &N1);
printf ("enter the length of the sequence h (n) :");
scanf ("%d", &N2);
printf ("enter the %d samples of sequence x (n): N1);
for (n=0; n<N1; n++)
scanf ("%d", &x[n]);
printf ("enter the %d samples of sequence h (n): N2);
for (n=0; n<N2; n++)
scanf ("%d", &h[n]);
if (N1>N2)
{
N=N1;
for (n=N2; n<N; n++)
h[n]=0;
}
else
{
N=N2;
for(n=N1;n<N1;n++)
y[n]=0;
}
for(k=0;k<N;k++)

{
y[k]=0;
for (m=N-1; m>=0; m--)
{
if ((N+k-m)>=N)
{
y[k] =y[k] +x[m]*h [k-m];
}
else
y[k] =y[k] +x[m]*h [N+k-m];
}
}
printf ("\response is y (n) :");
for (n=0; n<N; n++)
printf ("\t%d", y[n]);
}
Input:
Enter the length of the sequence x (n):4
Enter the length of the sequence h (n):4
Enter the 4 samples of sequence x (n):2 1 2 1
Enter the 4 samples of sequence h (n):1 2 3 4
Output:
Response is y (n):

14

16

14

16

Result: Circular convolution of two discrete sequences is computed.

3. DFT OF A SEQUENCE
AIM: Write a C program for DFT of a sequence and compute using code composer studio
V2 (using simulators 64xx, 67xx, 6711) software and TMS 320C 6711 DSK.

Program:
%DISCRETE FOURIER TRANSFORM OF THE GIVEN SEQUENCE
#include<stdio.h>
#include<math.h>
#define pi 3.14
main ()
{
int x [20], N, n, k;
float Xre[20],Xim[20],Msx[20],Psx[20];
printf ("enter the length of the sequence x (n) :");
scanf ("%d", &N);
printf ("enter the %d samples of discrete sequence x (n): N);
for (n=0; n<N; n++)
scanf ("%d", &x[n]);
for(k=0;k<N;k++)
{
Xre[k]=0;
Xim[k]=0;
for(n=0;n<N;n++)
{
Xre[k]=Xre[k]+x[n]*cos(2*pi*n*k/N);
Xim[k]=Xim[k]+x[n]*sin(2*pi*n*k/N);
}
Msx[k]=sqrt(Xre[k]*Xre[k]+Xim[k]*Xim[k]);
Xim[k]=-Xim[k];
Psx[k]=atan(Xim[k]/Xre[k]);
}
printf ("discrete sequence is");
for (n=0; n<N; n++)
printf ("\nx(%d) =%d", n,x[n]);
printf ("\nDFT sequence is :");

for(k=0;k<N;k++)
printf("\nx(%d)=%f+i%f",k,Xre[k],Xim[k]);
printf("\nmagnitude is:");
for (k=0; k<N; k++)
printf ("\n%f",Msx[k]);
printf ("\nphase spectrum is");
for(k=0;k<n;k++)
printf("\n%f",Psx[k]);
}
Input:
Enter the length of the sequence x (n):4
Enter the 4 samples of discrete sequence x (n):1 2 3 4
Output:
Discrete sequence is:
x (0) =1
x (1) =2
x (2) =3
x (3) =4
DFT sequence is:
x (0) =10.000000+i0.000000
x (1) =-2.007959+i1.995211
x (2) =-1.999967+i-0.012741
x (3) =-1.976076+i-2.014237
Magnitude is:

Phase spectrum is:

0.000000

10.000000

-0.782214

2.830683

0.006371

2.000007

0.794961

2.821707

Result: DFT of a given sequence is computed.

4. IDFT OF A SEQUENCE
Aim: Write a C program for IDFT of a sequence and compute using code composer studio V2
(using simulators 64xx, 67xx, 6711) software and TMS 320C 6711 DSK.

Program:
% Inverse Discrete Foureir Transform
#include<stdio.h>
#include<math.h>
#define pi 3.1428
main()
{
int j, k, N, n;
float XKr[10],XKi[10],xni[10],xnr[10],t;
printf (" enter seq length: \n");
scanf ("%d", &N);
printf ("enter the real & imaginary terms of the sequence: \n");
for (j=0; j<N; j++)
{
scanf ("%f%f", &XKr[j], &XKi[j]);
}
for (n=0; n<N; n++)
{
xnr[n] =0; xni[n] =0; for(k=0;k<N;k++)
{
t=2*pi*k*n/N;
xnr[n]=( xnr[n]+XKr[k]*cos(t) - XKi[k]*sin(t)) ;
xni[n]=( xni[n]+XKr[k]*sin(t) + XKi[k]*cos(t)) ;
}
xnr[n]=xnr[n]/N;
xni[n]=xni[n]/N;
}
printf("IDFT seq:");

for(j=0;j<N;j++)
{
printf("%f + (%f) i\n",xnr[j],xni[j]);
}
}
Input:
Enter seq length: 4
Enter the real & imaginary terms of the sequence:
3
0
0
1
1
0
0
1

Output:
IDFT seq: 1.000000 + (0.000000) i
1.000000 + (0.000302) i
1.000603 + (0.000605) i
0.000006 + (-0.002717) i

Result: IDFT of a given sequence is computed.

5. N - POINT DISCRETE FOUREIR TRANSFORM


AIM: Write a C program for N - Point Discrete Foureir Transform of a sequence and compute
using code composer studio V2( using simulators 64xx,67xx,6711) software and TMS
320C 6711 DSK.

Program:
% N - Point Discrete Foureir Transform
#include<stdio.h>
#include<math.h>
#define pi 3.142857
main ()
{
int j, k, n, N, l;
float XKr[10],XKi[10],xni[10],xnr[10],t;
printf (" enter seq length: \n");
scanf ("%d", &l);
printf ("enter the real & imaginary terms of the sequence: \n");
for (j=0; j<l; j++)
{
scanf ("%f%f", &xnr[j], &xni[j]);
}
printf (" enter required length: \n");
scanf ("%d", &N);
if (l<N)
{
for(j=l;j<N;j++)
xnr[j]=xni[j]=0;
}
for(k=0;k<N;k++)
{
XKr[k]=0; XKi[k]=0;
for(n=0;n<N;n++)
{

t=2*pi*k*n/N;
XKr[k]=( XKr[k]+xnr[n]*cos(t) + xni[n]*sin(t)) ;
XKi[k]=( XKi[k]+ xni[n]*cos(t) - xnr[n]*sin(t)) ;
}
}
printf (" The %d Point DFT seq: N);
for(j=0;j<N;j++)
{
printf("%3.3f + (%3.3f) i\n",XKr[j],XKi[j]);
}
}
Input:
Enter seq length:
3
Enter the real & imaginary terms of the sequence:
1
0
1
0
1
0
Enter required length:
4
Out put:
The 4 Point DFT seq:3.000 + (0.000) i
-0.001 + (-0.999) i
1.000 + (-0.001) i
0.002 + (1.004) i
Result: 4 - Point Discrete Foureir Transform of a sequence is computed.

6. FIR FILTERS
AIM: Implement FIR low pass and high pass filters
// FIR Low pass Filter program in C language using CC Studio
#include<stdio.h>
#include<math.h>
main()
{
int k,N,n,x,y;
static float h[10],hd[10],w[10]; printf("enter the no of samples N");
scanf("%d",&N);
y=(N-1)/2; x=-y;
for(n=x;n<=y;n++) {
if(n!=0) {
hd[n]=(sin(n*1.57)/3.14*n);
}
else hd[n]=0.5;
}
printf("select the window: 1.rectangular 2.triangular 3.hanning 4.hamming 5.blackmann");
scanf("%d",&k);
switch(k)
{
case 1: for(n=x;n<=y;n++) w[n]=1;
break;
case 2:
for(n=x;n<=y;n++)
w[n]=1-((abs(n)*2)/(N-1));
break;
case 3:
for(n=x;n<=y;n++)
w[n]=0.5+(0.5*cos((6.28*n)/(N-1)));
break;
case 4:
for(n=x;n<=y;n++)
w[n]=0.54+(0.46*cos((6.28*n)/(N-1)));
break;
case 5:
for(n=x;n<=y;n++)
w[n]=0.42+(0.5*cos((6.28*n)/(N-1)))+(0.08*cos((12.56*n)/(N-1)));
break;
default:
printf("wrong choice is entered"); }
for(n=x;n<=y;n++) {
h[n]=hd[n]*w[n]; printf("output is %f\t",h[n]);

}
}
Result:
ent er t he no of samples N

select the window: 1.rectangular 2.triangular 3.hanning 4.hamming 5.blackmann

output is 0.001014 output is 0.318471 output is 0.500000 output is 0.318471 output is 0.001014

FIR Low Pass Filter Rectangular Window Graph:

Result:
ent er t he no of samples N

select the window: 1.rectangular 2.triangular 3.hanning 4.hamming 5.blackmann


output is 0.000000 output is 0.318471 output is 0.500000 output is 0.318471 output is 0.000000

FIR Low Pass Filter Triangular Window Graph:

Result:
ent er t he no of samples N

select the window: 1.rectangular 2.triangular 3.hanning 4.hamming 5.blackmann

output is 0.000000 output is 0.159362 output is 0.500000 output is 0.159362 output is 0.000000

FIR Low Pass Filter Hanning Window Graph:

Result:
ent er t he no of samples N

select the window: 1.rectangular 2.triangular 3.hanning 4.hamming 5.blackmann


output is 0.000081 output is 0.172091 output is 0.500000 output is 0.172091 output is 0.000081

FIR Low Pass Filter Hamming Window Graph:

Result:
ent er t he no of samples N

select the window: 1.rectangular 2.triangular 3.hanning 4.hamming 5.blackmann


output is 0.000000 output is 0.108407 output is 0.500000 output is 0.108407 output is 0.000000

FIR Low Pass Filter Blackmann Window Graph:

// FIR High pass Filter program in C language using CC Studio


#include<stdio.h>
#include<math.h>
static float h[20],hd[20],w[20];
main()
{
int k,n,N,x,y;
printf("Enter the number of samples"); scanf("%d",&N);
y=(N-1)/2; x=-y;
for(n=x;n<=y;n++) {
if(n!=0) {
hd[n]=((sin(n*3.14))-(sin(n*1.57)))/(n*3.14); }
else hd[n]=0.5; }
printf("Select the window");
printf("1.Rectangular Window 2.Triangular window 3.Hanning window 4.Hamming window
5.Blackmann window");
scanf("%d",&k); switch(k)
{
case 1:
for(n=x;n<=y;n++) w[n]=1;
break;
case 2:
for(n=x;n<=y;n++)
w[n]=1-((abs(n)*2)/(N-1));
break;
case 3:
for(n=x;n<=y;n++)
w[n]=0.5+(0.5*cos((6.28*n)/(N-1)));
break;
case 4:
for(n=x;n<=y;n++)
w[n]=0.54+(0.46*cos((6.28*n)/(N-1)));
break;
case 5:
for(n=x;n<=y;n++)
w[n]=0.42+(0.5*cos((6.28*n)/(N-1))+(0.08*cos((12.5*n)/(N-1))));
break;
default:
printf("\n Wrong choice is entered,Please Enter the correct choice\n");
break;
}
for(n=x;n<=y;n++)
{
h[n]=hd[n]*w[n];
printf("\n The Output is: %f\t",h[n]); }
}
}

74
Result:
Enter the number of samples

Select the window 1.Rectangular Window 2.Triangular window


3.Hanning window 4.Hamming window 5.Blackmann window 1
The Output is: 0.000761
The Output is: 0.317964
The Output is:
0.500000
The Output is: 0.317964
The Output is: 0.000761
FIR High Pass Filter Rectangular Window Graph:

75
Result:
Enter the number of samples

Select the window 1.Rectangular Window 2.Triangular window


3.Hanning window 4.Hamming window 5.Blackmann window 2
The Output is:
0.000000
The Output is: 0.317964
The Output is:
0.500000
The Output is: 0.317964
The Output is:
0.000000
FIR High Pass Filter Triangular Window Graph:

76
Result:
Enter the number of samples

Select the window 1.Rectangular Window 2.Triangular window 3.Hanning


window 4.Hamming window 5.Blackmann window 3
The Output is: 0.000000
The Output is: 0.159109
The Output is:
0.500000
The Output is: 0.159109
The Output is: 0.000000
FIR High Pass Filter Hanning Window Graph:

77
Result:
Enter the number of samples

Select the window 1.Rectangular Window 2.Triangular window 3.Hanning window


4.Hamming window 5.Blackmann window 4
The Output is: 0.000061
The Output is: 0.171817
The Output is:
0.500000
The Output is: 0.171817
The Output is: 0.000061
FIR High Pass Filter Hamming Window Graph:

78

Result:
Enter the number of samples

Select the window 1.Rectangular Window 2.Triangular window 3.Hanning


window 4.Hamming window 5.Blackmann window
5
The Output is:
0.000000
The Output is: 0.108238
The Output is:
0.500000
The Output is: 0.108238
The Output is:
0.000000
FIR High Pass Filter Blackmann Window Graph:

79

7.IIR FILTERS
AIM: Implement IIR low pass and high pass filters

PROGRAM:
// IIR Filter C Program
#include<stdio.h>
#include<math.h>
int i,w,wc,c,N;
float H[100];
float mul(float,int);
void main()
{
printf("\n Enter order of filter");
scanf("%d",&N);
printf("\n Enter the cut off frequency"); scanf("%d",&wc);
printf("\n Enter the choice for IIR Filter 1.LPF 2.HPF");
scanf("%d",&c);
switch(c)
{
case 1: for(w=0;w<100;w++)
{
H[w]=1/sqrt(1+mul((w/(float)wc),2*N));
printf("H[%d]=%f\n",w,H[w]);
} break; case 2:
for(w=0;w<=100;w++) {
H[w]=1/sqrt(1+mul((float)wc/w,2*N));
printf("H[%d]=%f\n",w,H[w]);
} break;
}
}
float mul(float a,int x)
{
for(i=0;i<x-1;i++) a*=a;
return(a);
}
Result:
Enter order of filter 2
Enter the cut off frequency 50
Enter the choice for IIR Filter 1.LPF 2.HPF

80
H[0]=1.000000
H[1]=1.000000 H[2]=1.000000 H[3]=1.000000 H[4]=1.000000 H[5]=1.000000 . .
H[95]=0.076509 H[96]=0.073388 H[97]=0.070423 H[98]=0.067605 H[99]=0.064926
IIR Low Pass Filter Graph:

Result:
Enter order of filter 2
Enter the cut off frequency 50
Enter the choice for IIR Filter 1.LPF 2.HPF 2
H[0]=0.000000 H[1]=0.000000 H[2]=0.000003 H[3]=0.000013 H[4]=0.000041
H[5]=0.000100 . . .
H[95]=0.997069 H[96]=0.997304 H[97]=0.997517 H[98]=0.997712 H[99]=0.997890
H[100]=0.998053
IIR High Pass Filter Graph:

81

8. TO GENERATE SUM OF SINUSOIDAL SIGNALS


Aim: Write a C program to generate sum of sinusoidal signals and compute using
code composer studio V2 (using simulators 64xx, 67xx, 6711) software and TMS 320C
6711 DSK.

Program:
%SUM OF TWO SINUSOIDALS
#include<stdio.h>
#include<math.h>
main ()
{
int w1, w2, t;
float a, b, c;
printf ("enter the w1 value:");
scanf ("%d", &w1);
printf ("enter the w2 value:");
scanf ("%d", &w2);
printf ("sum of two sinusoidal :");
for(t=-5;t<5;t++)
{
b=sin(w1*t);
c=sin (w2*t);
a=b+c;
printf ("\n%f", a);
}
}
Input:
Enter the w1 value: 5
Enter the w2 value: 5

82

Output:
Sum of two sinusoidal:
0.264704
-1.825891
-1.300576
1.088042
1.917849
0.000000
-1.917849
-1.088042
1.300576
1.825891

Result: samples of sum of sinusoidal signals are generated.