You are on page 1of 58

GURU NANAK INSTITUTIONS TECHNICAL CAMPUS

Signal Processing lab

SIGNAL PROCESSING LAB MANUAL


By
Prof.B.Krishna Kumar

1
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

1.BasicOperationsonMatrices

2. Generation of Various Signals and Sequences such as unit impulse, unit step,

square,sawtooth,triangular,sinusoidal,ramp,sinc……………………………..

3. Basic Operations on Signals (Addition, Multiplication, Folding, Scaling)

4. Program to Verify Interpolation & Decimation of A Given Sequence

5. Program to Convert CD Data To DVD Data

6. Estimation of Power Spectrum Using Bartlett and Welch Methods31

7. Estimation of Power Spectrum Using Blackman-Turkey Method

8. Estimation of Power Spectrum Using Parametric Methods (Yule-Walker& Burg)

9. Design of LPC Filter Using Levinson-Durbin Algorithm

10. To Generate Various Fundamental Discrete Time Signals

11. Estimate the PSD of a Noisy Signal Using Periodogram And

Modified Periodogram

12. Generation of DTMF (Dual Tone Multiple Frequency) Signals

13. To find out the DFT&IDFT of a Given Sequence

2
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

Introduction

What Is MATLAB?
MATLAB is a high-performance language for technical computing. It integrates computation,
visualization, and programming in an easy-to-use environment where problems and solutions are
expressed in familiar mathematical notation.
It is one of the leading scientific and technical computing softwares.
The name MATLAB stands for matrix laboratory
In industry, MATLAB is the tool of choice for high-productivity research, development, and
analysis.
As a matrix based system, it is a great tool for simulation and data analysis.

MATLAB is an indispensable Graphical User Interface(GUI) tool and can be used it for proper
understanding of concepts in several prescribed basic and advanced subjects such as
 Mathematics
 Signals and Systems
 Probability Theory and Stochastic Processes
 Control Systems
 Analog Communications
 Digital signal Processing
 VLSI Design
 Digital Communications
 Digital Image Processing
 Satellite Communications
 Wireless Communications
 Embedded Systems
 Artificial Neural Networks

3
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
It provides several optional ‘toolboxes’ such as statistical toolbox, Control systems toolbox,
Neural Networks toolbox, symbolic math tool box, Signal Processing toolbox,etc.,which are
extremely useful for specific applications. Each toolbox provides a set of functions written for a
specific application
Starting MATLAB
To start MATLAB, double-click the MATLAB shortcut icon on your Windows desktop.

MATLAB Desktop
When you start MATLAB, the MATLAB desktop appears, containing tools (graphical user
interfaces) for managing files, variables, and applications associated with MATLAB.

4
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

The Command Window


The command window is the place where you enter all the MATLAB commands at the
command prompt(>>)
The Command History Window
All the commands entered recently at the command prompt are stored in the ‘command history’
window, for future use, until you select and delete them purposefully.
The Current Directory Window
The current directory window displays the list of all the files and folders under the current
directory, which happens to be the ‘work’ subdirectory, by default, under the Matlab root
directory.
Changing the Current directory
>>path tool
A new window called ‘set path’ window opens up.It shows all the directories and subdirectories
which are visible to MATLAB
 Click on ‘Add folder’
 Click on up or down buttons until the E: drive appears. Select it by clicking once on it
 Click on ‘Make a new folder’ and type ‘slab’ in the folder window and say OK
Now the new directory is added to MATLAB search path
 Click on ‘Save’ and then ‘close’
Ensure first that the current directory is the one that is your own ,which can be done either by
typing the following command at the command prompt or using the ‘view or change the current
directory’ option
>> cd E:\slab
MATLAB Editor and Debugger
After launching MATLAB and changing the current directory use the toolbar and select File->
New->M-file to open the Matlab editor and debugger
Save the file
File-> Save

5
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
EXPERIMENT 1

Basic Operations on Matrices

Variables
>>x=3+4
Creates a variable and assigns a value 7 to it
Expressions and Statements
Matlab can be used as a simple calculator
 >>34/7
 >>log(12)
 >>y=sqrt(17)
 >>a=3+ 4*j
>>b=abs(a)
Entering Matrices
•Separate the elements of a row with blanks or commas.
•Use a semicolon, ; , to indicate the end of each row.
•Surround the entire list of elements with square brackets, [ ].
To enter a matrix, simply type in the Command Window
A = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]
MATLAB displays the matrix you just entered.
A=
16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1

Sum, Transpose, and diag

Try these commands


>>sum(A)

6
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
MATLAB replies with
ans =
34 34 34 34
>>A’
ans =
16 5 9 4
3 10 6 15
2 11 7 14
13 8 12 1
And
>>sum(A')'
produces a column vector containing the row sums
ans =
34
34
34
34
The sum of the elements on the main diagonal is easily obtained with the help
of the diag function, which picks off that diagonal.
>>diag(A)
produces
ans =
16
10
7
1
and
sum(diag(A))
produces
ans =
34

7
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
>>diag(A)

Subscripts
The element in row i and column j of A is denoted by A(i,j). For example,
A(4,2) is the number in the fourth row and second column.
The Colon Operator
The colon, :, is one of MATLAB’s most important operators. It occurs in several
different forms. The expression
1:10
is a row vector containing the integers from 1 to 10
1 2 3 4 5 6 7 8 9 10
Operations on Vectors
Let a=[5 2 1 4 3] , b=[ 8 6 7]

MATLAB Function Meaning Example

min Smallest element min (a) = 1

max Largest element max (b) = 8

length Total number of elements length (b) = 3

sum Sum of all elements sum (b) = 21

prod Product of all elements prod (a) = 120

mean Average value mean (a) = 3

std Standard deviation std (a) = 1.5811

median Median value median (b) = 7

The magic Function


MATLAB actually has a built-in function that creates magic squares of almost
any size. Not surprisingly, this function is named magic.
B = magic(4)

8
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
B=
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
Arithmetic and Relational Operators

Arithmetic
Operator Operation
+ Addition
- Subtraction
* Matrix Multiplication
.* Array Multiplication
/ Division
^ Matrix Power
.^ Array Power
' Transpose

Relational Operator Operation

== Equal
~= Not Equal
< Less Than
<= Less Than or Equal
> Greater Than
>= Greater Than or Equal

9
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
Matrix Functions

Eye Identity matrix


zeros Matrix of zeros
ones Matrix of ones
diag Diagonal matrix
rand Matrix with
random elements
triu Upper triangular
part of matrix
tril Lower triangular
part of matrix
magic Magic square matrix

size Size of matrix


length Length of vector
sum Sum of elements
inv Inverse of matrix
eig Eigen value
rank Rank of matrix
det Determinant of matrix
norm Norm of matrix
poly Characteristic polynomial

trace Trace of matrix


prod Product of elements
mean Average value

10
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
\

EXPERIMENT 2

Generation of Various Signals and Sequences (Periodic and Aperiodic), such as


Unit impulse, unit step, square, saw tooth, triangular, sinusoidal, ramp, sync.
2(a) Ramp signal
Aim:
To generate ramp signal.
Software used:
1. Operating system-Windows XP
2. Matlab R2009b
Theory:
Signals and sequences are basically the same. A signal is considered analog and is operated in a
continuous-time system. A continuous-time system is a system that operates on and generates
signals that may vary over the entire time interval, usually t [0, ∞].
A sequence, on the other hand, is considered discrete in nature, and is operated in a discrete-time
system. A discrete-time system is a system that generally receives inputs at equally-spaced
(uniform) time intervals.
The ramp function, denoted by r(t) is a signal whose amplitude increases proportionally as time
increases. The mathematical definition of a ramp signal is

Program:
t = 0 : 0.001 : 1;
y = 0.5 * t;
plot( t , y );
xlabel ('Time Index t (sec.)');
ylabel ('Amplitude');
title ('Ramp Signal Sequence');

11
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

Expected Graph:

Ramp Signal Sequence


0.5

0.45

0.4

0.35

0.3
Amplitude

0.25

0.2

0.15

0.1

0.05

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Time Index t (sec.)

Result:

12
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
2(b) Sawtooth signal
Aim:
To generate sawtooth wave signal.
Software used:
1. Operating system-Windows XP
2. Matlab R2009b
Theory:
Repeating waveform that rises from zero to maximum value linearly drops back to zero and
repeats.
Program:
fs = 10000;
t = 0 : 1/fs : 1.5;
x = sawtooth (2 * pi * 100 * t);
plot( t , x ); axis ( [ 0 0.05 -1 1 ] );
xlabel('Time Index t (sec.)');
ylabel('Amplitude');
title ('Sawtooth Wave Signal Sequence');
Expected Graph

Sawtooth Wave Signal Sequence


1

0.8

0.6

0.4

0.2
Amplitude

-0.2

-0.4

-0.6

-0.8

-1
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05
Time Index t (sec.)

Result: .

13
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
EXPERIMENT-2(c)

Aim:
To generate sync signal

Software used:
1. Operating system-Windows XP
2. Matlab R2009b
Theory:
There is a particular form that appears so frequently in communications engineering, that we
give it its own name. This function is called the "Sinc function" and is discussed below: The Sinc
function is defined in the following manner:

The value of sinc(x) is defined as 1 at x = 0, since

This fact can be proven using L'Hopital's rule:

Here we are using the stylized "L" over the thick arrow to denote L'Hopital decomposition. Since
cos(0) = 1, we can show that at x = 0, the sinc function value is equal to 1. Also, the Sinc
function approaches zero as x goes towards infinity. The envelope of sinc(x) tapers off as 1/x.

14
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
Program:
t = linspace(-5 , 5);
y = sinc(t);
plot(t , y);
xlabel('Time Index t (sec.)');
ylabel('Amplitude');
title('Sinc Signal Sequence');

Expected Graph:

Sinc Signal Sequence


1

0.8

0.6

0.4
Amplitude

0.2

-0.2

-0.4
-5 -4 -3 -2 -1 0 1 2 3 4 5
Time Index t (sec.)

Result:

15
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

EXPERIMENT-2(d)

Aim:
To generate a sinusoidal signal
Software used:
1. Operating system-Windows XP
2. Matlab R2009b
Theory:
The sine wave or sinusoid is a mathematical function that describes a smooth repetitive
oscillation. It occurs often in pure mathematics, as well as physics, signal processing, electrical
engineering and many other fields. Its most basic form as a function of time (t) is:

Where,

A, the amplitude, is the peak deviation of the function from its center position.

 ω, the angular frequency, specifies how many oscillations occur in a unit time interval, in
radians per second

 φ, the phase, specifies where in its cycle the oscillation begins at t = 0.

 When the phase is non-zero, the entire waveform appears to be shifted in time by the
amount φ/ω seconds. A negative value represents a delay, and a positive value represents
a "head-start".

16
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
Program:
N=20;
t = -N : .0001 : N;
theta = input('The phase angle is ');
x = sin (2 * pi * 50 * t + theta);
plot( t , x ); axis( [-.04 .04 -1 1] );
grid;
xlabel ('Time Index t (sec.)');
ylabel ('Amplitude');
title ('Sinusoidal Signal of Frequency 50 Hz and Desired Phase').

Expected Graph:

Result:.

17
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

EXPERIMENT-2(e)

Aim:
To generate a square wave signal
Software used:
1. Operating system-Windows XP
2. Matlab R2009b
Program:
t = 0 : 0.0001 : 0.1;
y = square ( 2 * pi * 50 * t);
plot(t , y); axis ( [ 0 0.1 -2 2 ] );
xlabel('Time Index t (sec.)');
ylabel('Amplitude');
title('Square Wave Signal Sequence');

Expected Graph:
Square Wave Signal Sequence
2

1.5

0.5
Amplitude

-0.5

-1

-1.5

-2
0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1
Time Index t (sec.)

Result:

18
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

EXPERIMENT-2(f)
Aim:
To generate a triangular wave signal
Software used:
1. Operating system-Windows XP
2. Matlab R2009b
Program:
fs = 10000;
t = 0 : 1/fs : 1.5;
x = sawtooth (2 * pi * 50 * t , 0.5);
plot(t,x); axis ( [ 0 0.1 -1 1 ] );
xlabel('Time Index t (sec.)');
ylabel('Amplitude');
title('Triangular Wave Signal Sequence');
Expected Graph:

Triangular Wave Signal Sequence


1

0.8

0.6

0.4

0.2
Amplitude

-0.2

-0.4

-0.6

-0.8

-1
0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1
Time Index t (sec.)

Result:

19
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

EXPERIMENT-2(g)

Aim:
To generate a unit impulse signal

Software used:
1. Operating system-Windows XP
2. Matlab R2009b

Program:
clc;
clear all;
m1 = input(' Please input a NEGATIVE number for “m1” ');
m2 = input(' Please input a POSITIVE number for “m2” ');
m = [m1 : m2];
x = zeros(1,m2-m1+1);
m0 = input(' Type 0 for Unit Impulse, negative/ positive no. for delayed/ advanced signal');
x(m0-m1+1) = 1;
stem( m , x ); axis( [ m1 m2 -1.5 1.5 ] );
xlabel('Time Index m (sec.)');
ylabel('Amplitude');
title('Unit Impulse Signal Sequence');

20
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

Expected Graph:

Result:

21
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
EXPERIMENT-2(h)

Aim:
To generate a unit step signal

Software used:

1. Operating system-Windows XP
2. Matlab R2009b

Program:
clc; clear all;
k1 = input('Please input a NEGATIVE number for “k1” ');
k2 = input('Please input a POSITIVE number for “k2” ');
k0 = input('Type 0 for normal Unit Step, a negative or positive no. for a shifted one ');
k = [k1 : k2];
x = zeros(1,k2-k1+1);
x( k0-k1+1 : end ) = 1;
stem( k , x );
axis( [ k1 k2 -1.5 1.5 ] );
xlabel('Time Index k (sec.)');
ylabel('Amplitude');
title('Unit Step Signal Sequence');

22
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
Expected Graph:

Result:

Viva voce Questions:


1.Define a Signal
2.What are the characteristics of a signal
3.What type of information can a signal carry? Give an example
4.What is an analog signal? Why cant it be stored in a computer
5.What is the difference between a discrete valued signal and a digital signal
6.Are deterministic signals periodic? Explain with example
7.What is the difference between energy and power of a signal?
8.Define duty cycle
9.Distinguish between CT unit impulse and DT unit impulse

23
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

EXPERIMENT-3

BASIC OPERATIONS ON SIGNALS (Addition, Multiplication, Folding, Scaling)

Aim: -
To write a MATLAB program for various basic operations on given sequences
Software used: -
MATLAB 7.5
Program: -
%% Clearing and closing commands
clc
clear all
close all
%% Declaring Input sequences
x=[1:1:8];
y=[8:-1:1];
%% Plotting the results of different operations
% Input sequence 1
subplot(3,2,1)
stem(x)
xlabel('no of samples')
ylabel('amplitude')
title('input sequence 1')
% Input sequence 2
subplot(3,2,2)
stem(y)
xlabel('no of samples')
ylabel('amplitude')
title('input sequence 2')
% Addition of sequences

24
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
m=x+y;
subplot(3,2,3)
stem(m)
xlabel('no of samples')
ylabel('amplitude')
title('addition of signals')
% Multiplication of sequences
m=x.*y;
subplot(3,2,4)
stem(m)
xlabel('no of samples')
ylabel('amplitude')
title('multipilcation of signals')
% Folding of sequences
subplot(3,2,5)
stem(-x,x)
xlabel('no of samples')
ylabel('amplitude')
title('folded sequence')
% Amplitude scaling
subplot(3,2,6)
stem(x,x*2)
xlabel('no of samples')
ylabel('amplitude')
title('amplitude Scaling')

Result: -Hence basic operations signals have been generated and plotted using MATLAB

25
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
Output:

26
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

EXPERIMENT-4

PROGRAM TO VERIFY INTERPOLATION & DECIMATION OF A GIVEN


SEQUENCE

Aim: -
To write a MATLAB program to verify INTERPOLATION and DECIMATION of a given
sequence.
Software used:
-MATLAB 7.5
Program: -
%% Clearing and Closing commands
clc
clear all
close all
%% Program for Interpolation
t=0:0.05:2;
x=cos(2*pi*t);
y=interp(x,2);
t2=interp(t,2);
subplot(2,1,1)
stem(t,x)
xlabel('Number of Namples');
ylabel('Amplitude')
title('Input Sequence')
subplot(2,1,2)
stem(t2,y)
xlabel('Number of Samples');
ylabel('Amplitude')

27
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
title('Interpolated Sequence')
%% Program for Decimation
t=0:0.05:2;
x=cos(2*pi*t);
y=decimate(x,2);
t1=decimate(t,2);
subplot(2,1,1)
stem(t,x)
xlabel('Number of Samples');
ylabel('Amplitude')
title('Input Sequence')
subplot(2,1,2)
stem(t1,y)
xlabel('Number of Samples');
ylabel('Amplitude')
title('Decimated Sequence')

Result: - Hence the INTERPOLATION and DECIMATION of a given sequence has been
verified using MATLAB

Output:

28
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

29
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

30
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

EXPERIMENT-5

PROGRAM TO CONVERT CD DATA TO DVD DATA

Aim:
To write a MATLAB program to convert CD data to DVD data
Software used:
MATLAB 7.5
Program: -
%% Clearing and closing commands
clc
clear all
close all
%% Program
[y, Fs, nbits] = wavread('type.wav');
disp('The sampling frequency is:');
Fs
disp('Number of bits per sample:');
nbits
disp('The length of the CD data is:');
length(y)
%%
p=interp(y,2);
Fs1=Fs*2;
disp('The sampling frequency is:');
Fs1
disp('Number of bits per sample:');
nbits
disp('The length of the DVD data is:');
length(p)

31
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
wavplay(y,Fs);
pause(2);
wavplay(p,Fs1);

Result:-Hence the data sampled at CD sampling rate is converted into DVD sampling rate has
been verified using MATLAB

Outputs: -
The sampling frequency is:

Fs =

11025

Number of bits per sample:

nbits =

The length of the CD data is:

ans =

4409

The sampling frequency is:

Fs1 =

22050

32
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

Number of bits per sample:

nbits =

The length of the DVD data is:

ans =

8818

33
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
EXPERIMENT-6

ESTIMATION OF POWER SPECTRUM USING BARTLETT AND WELCH METHODS

Aim:
To write a MATLAB program to estimate power spectrum using BARTLETT and
WELCH method.

Software used:
MATLAB 7.5
Program: -
%% Clearing and Closing commands
clc
clear all
close all
%% Declaring Inputs
fs=2000;
f1=200;
f2=400;
M=128;
Program for BARTLETT METHOD:
t=0:1/fs:1;
x=2*sin(2*pi*f1*t)+2*sin(2*pi*f2*t)+rand(size(t));
L=length(x);
K=L/M;
y1=[];
for i=1:M:L-M
y2=abs(fft(x(i:i+M)).^2);
y1=[y1;y2];
end
y3=sum(y1);

34
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
w1=y3/K;
w12=10*log(w1);
fs1=(fs/K)+2;
t1=((1:fs1)/fs1);
plot(t1,w12)
xlabel('Normalized Frequency')
ylabel('PSD')
title('BARTLETT METHOD of Power Spectral Estimation');
Program for WELCH METHOD:
t=0:1/fs:1;
x=2*sin(2*pi*f1*t)+2*sin(2*pi*f2*t)+rand(size(t));
L=length(x);
K=L/M;
w=hann(M+1);
m=0;
su=[];
for i=1:M/2:L-M+1
g=w'.*x(i:M+i);
w2=abs(fft(g).^2);
su=[su;w2];
end
su1=sum(su);
f=sum(w.^2);
w1=su1/f;
w12=10*log(w1);
fs1=(fs/K)+2;
t1=((1:fs1)/fs1);
plot(t1,w12)
xlabel('Normalized Frequency')
ylabel('PSD')
title('WELCH METHOD of Power Spectral Estimation');

35
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

Result: -Hence the estimation of PSD using BARTLETT and WELCH method has been verified
using MATLAB

Outputs: - Bartlett Method

36
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
Welch Method

37
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
EXPERIMENT-7

ESTIMATION OF POWER SPECTRUM USING BLACKMAN-TUKEY METHOD


Aim:
To write a MATLAB program to estimate power spectrum using Power Spectrum using
BLACKMAN-TUKEY method.
Software used: -
MATLAB 7.5
Program: -
%% Clearing and Closing commands
clc
clear all
close all
fs=2000;
f1=200;
f2=400;
t=0:1/fs:1;
x=sin(2*pi*f1*t)+sin(2*pi*f2*t)+rand(size(t));
L=length(x);
y=xcorr(x);
wi=hann(length(y));
o=wi'.*y;
i=length(y);
b=abs(fft(xcorr(o)))/L;
i1=length(b);
t1=(1:i1)/i1;
b1=10*log(b);
plot(t1,b1);
xlabel('Normalized Ffrequency');
ylabel('psd');
title('BLACKMAN TUKEY method of Power Estimation');

38
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

Result: -Hence the estimation of PSD using BLACKMAN-TUKEY method has been verified
using MATLAB.

Output: -

39
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

EXPERIMENT-8
ESTIMATION OF POWER SPECTRUM USING PARAMETRIC METHODS
(YULE-WALKER & BURG)
Aim:-
To write a MATLAB program to estimate power spectrum using Power Spectrum using
YULE-WALKER and BURG method.
Software used: -
MATLAB 7.5
Program:
%% Clearing and Closing commands
clc
clear all
close all
Program for BURG method:
a=[1 -2.2137 2.9408 -2.1697 0.9609];
randn('state',1);
x=filter(1,a,randn(256,1));
pburg(x,4);
xlabel('Normalized Frequency');
ylabel('Power Sectrum in db');
title('BURG method of Power Spectrum Estimation');
Program for YULE WALKER method:
a=[1 -2.2137 2.9408 -2.1697 0.9609];
randn('state',1);
x=filter(1,a,randn(256,1));
pyulear(x,4);
xlabel('Normalized Frequency');
ylabel('Power Spectrum in db');
title('YULE-WALKER method of Power Spectrum Estimation');

40
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
Result: -Hence the estimation of PSD using YULE-WALKER and BURG method has been
verified using MATLAB

Output: - Burg Method

Yule Walker Method

41
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
EXPERIMENT-9

DESIGN OF LPC FILTER USING LEVINSON-DURBIN ALGORITHM


Aim: -
To write a MATLAB program to Design of LPC filter using LEVINSON-DURBIN
Algorithm.
Software used: -
MATLAB 7.5
Program: -
%% Clearing and Closing commands
clc
clear all
close all
%% Program
t=0:1023;
fs=1000;
x=sin(2*pi*50/fs*t)+sin(2*pi*120/fs*t);
y=x+rand(size(t));
p=10;
[a,g]=lpc(y,p);
a;
stem(a)
xlabel('Sequence ');
ylabel('Amplitude');
title('LPC filter coefficients');

Result: -Hence the Design of LPC filter using LEVINSON-DURBIN Algorithm has been
verified using MATLAB

42
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
Output: -

43
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
EXPERIMENT-10

To generate various fundamental discrete time signals

Aim: -
To write a MATLAB program to generate various fundamental Signals.
Software used: -
MATLAB 7.5
Program:-
%% Clearing and closing commands
clc
clear all
close all
%% Plotting Various Signals
% program for unit step sequence
n=-5:1:5;
y1=[zeros(1,5) 1 ones(1,5)];
subplot(4,2,1)
stem(n,y1)
xlabel('no of samples');
ylabel('amplitude');
title('unit step sequence');
% program for impulse sequence
n=-5:1:5;
y2=[zeros(1,5) 1 zeros(1,5)];
subplot(4,2,2)
stem(n,y2)
xlabel('no of samples');
ylabel('amplitude');
title('impulse sequence')
% program for ramp sequence

44
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
m=0:1:5;
y3=m;
subplot(4,2,3)
stem(m,y3)
xlabel('no of samples')
ylabel('amplitude')
title('ramp sequence')
% program for exponentially increasing
t=0:1:5;
a1=.5;
y4=exp(a1*t);
subplot(4,2,4)
stem(t,y4)
xlabel('no of samples')
ylabel('amplitude')
title('exponential increasing sequence')
% program for exponentially decreasing
t=0:1:5;
a2=.2;
y5=exp(-a2*t);
subplot(4,2,5)
stem(t,y5)
xlabel('no of samples')
ylabel('amplitude')
title('exponential decreasing sequence')
% program for sine wave generation
t=0:0.1:2;
y6=sin(2*pi*t);
subplot(4,2,6)
stem(t,y6)
xlabel('no of samples')

45
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
ylabel('amplitude')
title('sine wave')
% program for cosine wave generation
t=0:0.1:2;
y7=cos(2*pi*t);
subplot(4,2,7)
stem(t,y7)
xlabel('no of samples')
ylabel('amplitude')
title('cosine wave')

Result: - Hence different basic signals have been generated and plotted using MATLAB
Output: -

46
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

EXPERIMENT-11

ESTIMATE THE PSD OF A NOISY SIGNAL USING PERIODOGRAM AND


MODIFIED PERIODOGRAM
Aim: -
To write a MATLAB program to find out PSD using PERIODOGRAM and MODIFIED
PERIODOGRAM.
Software used: -
MATLAB 7.5
Program: -
%% Clearing and closing commands
clc
clear all
close all
%% Declaring inputs
f1=1000;
f2=2000;
fs=4000;
%% Program for PERIODOGRAM
t=0:1/fs:1;
x=2*sin(2*pi*f1*t)+3*sin(2*pi*f2*t)+rand(size(t));
pxx1=abs(fft(x).^2);
pxx2=abs(fft(xcorr(x),length(t)));
subplot(2,1,1)
plot(t*fs,10*log10(pxx1));
xlabel('Frequency in Hertz:')
ylabel('Power in db:')
title('PSD using SQUARE MAGNITUDE METHOD')
subplot(2,1,2)
plot(t*fs,10*log10(pxx2));

47
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
xlabel('Frequency in Hertz:')
ylabel('Power in db:')
title('PSD using AUTOCORRELATION METHOD')

Program for MODIFIED PERIODOGRAM:


N=4;
n=0:1/fs:1;
x=sin(2*pi*f1*n)+sin(2*pi*f2*n)+rand(size(n));
y=abs(fft(x).^2);
subplot(2,1,1)
plot(n*fs,10*log10(y))
xlabel('Frequency in Hertz:')
ylabel('Magnitude in db:')
title('PSD using SQUARE MAGNITUDE METHOD');
w=hanning(N);
u=0;
for i=1:N;
u=u+(w(i).^2);
end
for i=1:N;
y1=[abs(fft(x).^2)*w(i).^2]/(u*N);
end
subplot(2,1,2)
plot(n*fs,10*log10(y1))
xlabel('Frequency in Hertz:')
ylabel('Magnitude in db:')
title('PSD using HANNING WINDOW');

Result: -Hence the estimation of PSD using PERIODOGRAM and MODIFIED


PERIODOGRAM has been verified using MATLAB

48
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
Outputs: - Periodogram

Modified Periodogram

49
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
EXPERIMENT-12

GENERATION OF DTMF (DUAL TONE MULTIPLE FREQUENCY) SIGNALS

Aim: -
To write a MATLAB program for generation of DTMF signals

Software used: -
MATLAB 7.5
Program: -
%% Clearing and closing commands
clc
clear all
close all
%% Program
number=['9177857260','s'];
fs=8192;
T=0.5;
x=2*pi*[697,770,852,941];
y=2*pi*[1209,1336,1477];
t=[0:1/fs:T]';
tx=[sin(x(1)*t),sin(x(2)*t),sin(x(3)*t),sin(x(4)*t)]/2;
ty=[sin(y(1)*t),sin(y(2)*t),sin(y(3)*t)]/2;
for k=1:length(number)

switch number(k)

case'1'
tone=tx(:,1)+ty(:,1);
% sound(tone);
stem(tone);

50
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
xlabel('No of Samples');
ylabel('Amplitude');
title('Dual Tone Multiple Frequency');

case'2'
tone=tx(:,1)+ty(:,2);
% sound(tone);
stem(tone);
xlabel('No of Samples');
ylabel('Amplitude');
title('Dual Tone Multiple Frequency');

case'3'
tone=tx(:,1)+ty(:,3);
% sound(tone);
stem(tone);
xlabel('No of Samples');
ylabel('Amplitude');
title('Dual Tone Multiple Frequency');

case'4'
tone=tx(:,2)+ty(:,1);
% sound(tone);
stem(tone);
xlabel('No of Samples');
ylabel('Amplitude');
title('Dual Tone Multiple Frequency');

case'5'
tone=tx(:,2)+ty(:,2);
% sound(tone);

51
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
stem(tone);
xlabel('No of Samples');
ylabel('Amplitude');
title('Dual Tone Multiple Frequency');

case'6'
tone=tx(:,2)+ty(:,3);
% sound(tone);
stem(tone);
xlabel('No of Samples');
ylabel('Amplitude');
title('Dual Tone Multiple Frequency');

case'7'
tone=tx(:,3)+ty(:,1);
% sound(tone);
stem(tone);
xlabel('No of Samples');
ylabel('Amplitude');
title('Dual Tone Multiple Frequency');

case'8'
tone=tx(:,3)+ty(:,2);
% sound(tone);
stem(tone);
xlabel('No of Samples');
ylabel('Amplitude');
title('Dual Tone Multiple Frequency');

case'9'
tone=tx(:,3)+ty(:,3);

52
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
% sound(tone);
stem(tone);
xlabel('No of Samples');
ylabel('Amplitude');
title('Dual Tone Multiple Frequency');

case'*'
tone=tx(:,4)+ty(:,1);
% sound(tone);
stem(tone);
xlabel('No of Samples');
ylabel('Amplitude');
title('Dual Tone Multiple Frequency');

case'0'
tone=tx(:,4)+ty(:,2);
% sound(tone);
stem(tone);
xlabel('No of Samples');
ylabel('Amplitude');
title('Dual Tone Multiple Frequency');

case'#'
tone=tx(:,4)+ty(:,3);
% sound(tone);
stem(tone);
xlabel('No of Samples');
ylabel('Amplitude');
title('Dual Tone Multiple Frequency');

% otherwise

53
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
% disp('invalid number');
end;
pause(0.75);
end;

Result: -Hence the above DTMF signals has been generated and plotted using MATLAB
Output:

54
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
EXPERIMENT-13

TO FIND OUT THE DFT & IDFT OF A GIVEN SEQUENCE

Aim: -
To write a MATLAB program to find out the DFT & IDFT of a given sequence.
Software used: -
MATLAB 7.5
Program: -
%% Clearing and closing commands
clc
clear all
close all
%% Program for DFT
N=8;
x=[1 2 3 4 4 3 2 1];
for k=0:1:N-1;
for n=0:1:N-1;
p=exp(-j*2*pi*n*k/N);
x2(k+1,n+1)=p;
end;
end;
y=x*x2;
disp(y);
stem(x,y);
xlabel('time period')
ylabel('amplitude');
title('DFT of the sequence');

%% Program for IDFT


N=8;

55
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab
x=[1 2 3 4 4 3 2 1];
for k=0:1:N-1;
for n=0:1:N-1;
p=exp(j*2*pi*n*k/N);
x1(k+1,n+1)=p;
end;
end;
y=(x*x1)/N;
disp(y);
stem(x,y);
xlabel('time period');
ylabel('amplitude');
title('IDFT of the sequence');

%% Program for FFT using keyword


N=8;
x=[1 2 3 4 4 3 2 1];
z=fft(x,N);
stem(x,z);
xlabel('time period');
ylabel('amplitude');
title('DFT of the sequence using keyword');

%% Program for IFFT using keyword


N=8;
x=[1 2 3 4 4 3 2 1];
z=ifft(x,N);
stem(x,z);
xlabel('time period');
ylabel('amplitude');
title('IDFT of the sequence using keyword');

56
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

Result: - Hence the DFT & IDFT of the given sequence has been found and plotted using
MATLAB
Outputs: -
FFT
Columns 1 through 4

20.0000 -5.8284 - 2.4142i 0.0000 - 0.0000i -0.1716 - 0.4142i

Columns 5 through 8

0 - 0.0000i -0.1716 + 0.4142i -0.0000 - 0.0000i -5.8284 + 2.4142i

57
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
Signal Processing lab

IFFT
Columns 1 through 4
2.5000 -0.7286 + 0.3018i 0.0000 + 0.0000i -0.0214 + 0.0518i
Columns 5 through 8
0 + 0.0000i -0.0214 - 0.0518i -0.0000 + 0.0000i -0.7286 - 0.3018i

58

You might also like