You are on page 1of 42

SIGNAL PROCESSING LAB 1.

GENERATIONOF BASIC SIGNALS ( unit impulse, exponential, unit step, ramp )

M Tech (PTPG), SSP, I SEM

AIM : To generate the Basic Signals like unit impulse, step, ramp, and exponential. SOFTWARE REQUIRED : MAT LAB 7.0 PROGRAM DESCRIPTION : In this program basic signals like unit impulse, unit step, ramp, and exponential signals are to be generated based on the following definitions. 1. Unit impulse signal: This signal is having unit amplitude only at origin and else where the amplitude zero. It is denoted by (t). 2. Unit step signal: This signal is having unit amplitude for all the positive values of time axis and else where the amplitude zero. It is denoted by u (t). The sequence is denoted by u[n]. 3. Ramp signal: This signal is having amplitude values linearly increasing same as the time axis values from origin to all the positive values and else where the amplitude zero. It is denoted by r(t). The sequence is denoted by r[n]. 4. Exponential signal: This signal is having the amplitudes exponentially increasing with time. This is a plot of eat. Where e denotes exponential function, a is an integer and t is the time scale. PROGRAM : %Generation of various signals: impulse, exponential, step, ramp.
clc; clear all; clear all; %impulse sequence t=-2:1:2; y1=[zeros(1,2) 1 zeros(1,2)]; subplot (2,2,1); stem(t,y1); grid title ('Impulse Response'); xlabel ('no. of samples :n-->'); ylabel ('--> Amplitude'); %Exponential Sequence n=input('enter the length of Exponential Sequence'); t=0:1:n; a=input('Enter "a" value'); y2=exp(a*t); subplot(2,2,2);

SIGNAL PROCESSING LAB


stem(t,y2); grid title ('Exponential Sequence'); xlabel ('no. of samples :n-->'); ylabel ('--> Amplitude');

M Tech (PTPG), SSP, I SEM

%Step Sequence s=input ('enter the length of step sequence'); t=-s:1:s; y3=[zeros(1,s) ones(1,1) ones(1,s)]; subplot(2,2,3); stem(t,y3); grid title ('Step Sequence'); xlabel ('no. of samples :n-->'); ylabel ('--> Amplitude'); %Ramp Sequence x=input ('enter the length of Ramp sequence'); t=0:x; subplot(2,2,4); stem(t,t); grid title ('Ramp Response'); xlabel ('no. of samples :n-->'); ylabel ('--> Amplitude');

OUPUTS:
enter Enter enter enter the "a" the the length of Exponential Sequence: 5 value :2 length of step sequence: 5 length of Ramp sequence: 6

SIGNAL PROCESSING LAB GRAPHS :


Impulse Response 1 --> Amplitude --> Amplitude 3

M Tech (PTPG), SSP, I SEM

4 x 10 Exponential Sequence

0.5

0 -2

-1 0 1 no. of samples :n--> Step Sequence

2 4 no. of samples :n--> Ramp Response

1 --> Amplitude 0 no. of samples :n--> 5 --> Amplitude

0.5

0 -5

2 4 no. of samples :n-->

INFERENCE : In the generation of the basic signals we have defined the signals along time and amplitude axes for unit impulse, step, ramp and exponential signals and plotted the graphs. For different values the graphs are plotted. RESULT : The basic signals like unit impulse , unit step, ramp and exponential signals are generated and the waveforms are plotted.

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

2. GENERATION OF BASIC SIGNALS ( Sinusoidal signal ) AIM : To Generate sinusoidal signal of frequency f Hz and phase phi SOFTWARE REQUIRED : MAT LAB 7.0 PROGRAM DESCRIPTION : A sinusoidal signal is a continuous signal whose amplitude varies between two fixed values on the positive and negative amplitude axes. This is a plotted as a function of frequency, time and phase for different values. This signal is represented as y(t)=A sin ( 2ft+ ). Where A is amplitude, f is the frequency, t is time and is phase. PROGRAM : % Generation of sinusoidal signal of f Hz and phase phi
clc; clear all; close all; A=input('Enter the amplitude of the sinusoidal signal= '); f = input('Enter the frequency of the sinusoid sequence f = phi = input('Enter the phase of the sinusoid sequence phi = fs = input('Enter the sampling frequency fs = '); T = input('Enter the duration of the sequence T = '); dt = 1/fs; t = 0:dt:T; y = A*sin(2*pi*f*t + phi); plot(t,y); title('Sinusoidal signal','fontsize',12); xlabel('t -->'); ylabel('Amplitude -->');

'); ');

OUTPUTS:
Enter Enter Enter Enter Enter the the the the the amplitude of the sinusoidal signal= 3 frequency of the sinusoid sequence f = phase of the sinusoid sequence phi = sampling frequency fs = 1000 duration of the sequence T = 2 4 10

SIGNAL PROCESSING LAB GRAPHS : Sinusoidal signal


3

M Tech (PTPG), SSP, I SEM

1 Amplitude -->

-1

-2

-3

0.2

0.4

0.6

0.8

1 t -->

1.2

1.4

1.6

1.8

INFERENCE : The frequency f indicates the no. of cycles in one second i.e., in this program 4 cycles in one second as f = 4. Similarly duration indicates the total signal which is to be displayed, here duration is 2, means from 0 to 2 sec. the signal is plotted. RESULT : For a particular frequency f Hz and phase phi, the sinusoidal signal is generated and plotted.

SIGNAL PROCESSING LAB 3. BASIC OPERATIONS ON SIGNALS ( Shifting, Folding, Multiplication and Addition)

M Tech (PTPG), SSP, I SEM

AIM : To perform different operations like shifting, addition, folding, multiplication and shifting of basic signals. SOFTWARE REQUIRED : MAT LAB 7.0 PROGRAM DESCRIPTION : In this program the basic operations like shifting, addition, folding, multiplication and shifting is operated on basic signals like impulse, step, ramp, exponential. PROGRAM : % Basic operations on impulse signal: shifting operation
clc; clear all; clear all; %impulse sequence t=-3:1:3; y1=[zeros(1,3) 1 zeros(1,3)]; subplot (3,1,1); stem(t,y1); grid; title ('Impulse Response'); xlabel ('time -->'); ylabel ('--> Amplitude'); %impulse sequence shifted right by one location t=-3:1:3; y2=[zeros(1,4) 1 zeros(1,2)]; subplot (3,1,2); stem(t,y2); grid; title ('Impulse Response shifted right by one location'); xlabel ('time-->'); ylabel ('Amplitude-->'); %impulse sequence shifted left by two location t=-3:1:3; y3=[zeros(1,1) 1 zeros(1,5)]; subplot (3,1,3); stem(t,y3); grid; title ('Impulse Response shifted left by two locations'); xlabel ('time-->'); ylabel ('Amplitude-->');

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

GRAPHS:
Impulse Response --> Amplitude 1 0.5 0 -3

-2

0 1 2 time --> Impulse Response shifted right by one location

-1

Amplitude-->

1 0.5 0 -3 -2 0 1 2 time--> Impulse Response shifted left by two locations -1 3

1 Amplitude--> 0.5 0 -3

-2

-1

0 time-->

%Basic operations on step signal: folding operation


clc; clear all; clear all; %Step Sequence s=input ('enter the length of step sequence'); t=-s:1:s; y1=[zeros(1,s) ones(1,1) ones(1,s)]; subplot(1,2,1); stem(t,y1); grid title ('Step Sequence'); xlabel ('time -->'); ylabel ('--> Amplitude'); %Step Sequence after folding y2=[ones(1,s) ones(1,1) zeros(1,s)]; subplot(1,2,2); stem(t,y2); grid title ('Step Sequence after folding'); xlabel ('time -->'); ylabel ('--> Amplitude');

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

OUPUTS:
enter the length of step sequence: 5

GRAPHS:
Step Sequence 1 0.9 0.8 0.7 --> Amplitude --> Amplitude 0.6 0.5 0.4 0.3 0.2 0.1 0 -5 1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 -5 Step Sequence after folding

0 time -->

0 time -->

%Basic operations on signals: folding operation on ramp signal


clc; clear all; clear all;

%Ramp Sequence x=input('enter the length of the ramp sequence:') t=0:x subplot(2,1,1) stem(t,t) grid title ('Ramp Response'); xlabel ('time -->'); ylabel ('--> Amplitude'); %Ramp Sequence after folding t=-x:0

SIGNAL PROCESSING LAB


y=-t subplot(2,1,2) stem(t,y) grid title ('Ramp Response after folding'); xlabel ('time -->'); ylabel ('--> Amplitude');

M Tech (PTPG), SSP, I SEM

OUTPUTS:

enter the length of the ramp sequence:5

x= 5 t= 0 1 2 t = -5 -4 -3 y= 5 4 3 GRAPHS:

3 4 5 -2 -1 0 2 1 0

Ramp Response 6 --> Amplitude

0.5

1.5

2.5 3 time --> R amp Response after folding

3.5

4.5

6 --> Amplitude

0 -5

-4.5

-4

-3.5

-3

-2.5 time -->

-2

-1.5

-1

-0.5

%Basic operations on signals: folding operation on exponential signal


clc; clear all; clear all; %Exponential Sequence n=input('enter the length of Exponential Sequence:'); t=0:1:n; a=input('Enter "a" value:'); y=exp(a*t);

SIGNAL PROCESSING LAB


subplot(2,1,1); stem(t,y); grid title ('Exponential Sequence'); xlabel ('time -->'); ylabel ('--> Amplitude'); %Exponential Sequence after folding subplot(2,1,2) stem(-t,y) grid title ('Exponential Sequence'); xlabel ('time -->'); ylabel ('--> Amplitude');

M Tech (PTPG), SSP, I SEM

OUTPUTS:
enter the length of Exponential Sequence: 5 Enter "a" value: 0.8

GRAPHS:
Exponential Sequence 60 --> Amplitude

40

20

0.5

1.5

2.5 3 tim --> e Exponential Sequence

3.5

4.5

60 --> Amplitude

40

20

0 -5

-4.5

-4

-3.5

-3

-2.5 tim --> e

-2

-1.5

-1

-0.5

INFERENCE : In this program the shifting operation is performed n impulase signal, folding operation is performed on step, ramp, and exponential signals. RESULT : Different operations like shifting, addition, folding, multiplication and shifting of basic signals like impulse, step, ramp, and exponential is performed and the graphs are plotted.

10

SIGNAL PROCESSING LAB 4. FINDING THE FFT OF DIFFERENT SIGNALS

M Tech (PTPG), SSP, I SEM

AIM : To find the FFT of different signals like impulse, step, ramp and exponential. SOFTWARE REQUIRED : MAT LAB 7.0 PROGRAM DESCRIPTION : In this program using the command FFT for impulse, step, ramp and exponential sequences the FFT is generated. In the process of finding the FFT the length of the FFT is taken as N. The FFT consists of two parts: MAGNITUDE PLOT and PHASE PLOT. The magnitude plot is the absolute value of magnitude versus the samples and the phase plot is the phase angle versus the samples. PROGRAM : % FFT of the impulse sequence : magnitude and phase response
clc; clear all; close all; %impulse sequence t=-2:1:2; y=[zeros(1,2) 1 zeros(1,2)]; subplot (3,1,1); stem(t,y); grid; input('y='); disp(y); title ('Impulse Response'); xlabel ('time -->'); ylabel ('--> Amplitude'); xn=y; N=input('enter the length of the FFT sequence: '); xk=fft(xn,N); magxk=abs(xk); angxk=angle(xk); k=0:N-1; subplot(3,1,2); stem(k,magxk); grid; xlabel('k'); ylabel('|x(k)|'); subplot(3,1,3); stem(k,angxk); disp(xk); grid; xlabel('k'); ylabel('arg(x(k))');

OUTPUTS: y= 0 0 1 0 0

enter the length of the FFT sequence: 10

11

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

1.0000 1.0000 GRAPHS:


--> A p d m litu e

0.3090 - 0.9511i 0.3090 - 0.9511i

-0.8090 - 0.5878i -0.8090 - 0.5878i

-0.8090 + 0.5878i 0.3090 + 0.9511i -0.8090 + 0.5878i 0.3090 + 0.9511i

I pl e epne m s R os u s 1 0 . 5 0 2 1

-. 1 5

-. 0 5

0 t eim->

0 . 5

1 . 5

|x(k)|

0 . 5 0 0 5

4 k

a (x(k)) rg

4 k

% FFT of the step sequence : magnitude and phase response


clc; clear all; close all; %Step Sequence s=input ('enter the length of step sequence'); t=-s:1:s; y=[zeros(1,s) ones(1,1) ones(1,s)]; subplot(3,1,1); stem(t,y); grid input('y='); disp(y); title ('Step Sequence'); xlabel ('time -->'); ylabel ('--> Amplitude'); xn=y; N=input('enter the length of the FFT sequence: '); xk=fft(xn,N); magxk=abs(xk); angxk=angle(xk); k=0:N-1; subplot(3,1,2); stem(k,magxk); grid

12

SIGNAL PROCESSING LAB


xlabel('k'); ylabel('|x(k)|'); subplot(3,1,3); stem(k,angxk); disp(xk); grid xlabel('k'); ylabel('arg(x(k))');

M Tech (PTPG), SSP, I SEM

OUTPUTS:
enter the length of step sequence: 5

y=

1 0 -1.0000 0

enter the length of the FFT sequence: 10 5.0000 -1.0000 + 3.0777i 0 -1.0000 + 0.7265i -1.0000 - 0.7265i 0 -1.0000 - 3.0777i GRAPHS:
--> Amplitude S pS q e c te e u n e 1 0 .5 0 -5 5 |x(k)|

-4

-3

-2

-1

0 tim --> e

0 0 5 arg(x(k))

4 k

-5

4 k

% FFT of the Ramp sequence: magnitude and phase response


clc; clear all; close all; %Ramp Sequence s=input ('enter the length of Ramp sequence: '); t=0:s; y=t subplot(3,1,1);

13

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

stem(t,y); grid input('y='); disp(y); title ('ramp Sequence'); xlabel ('time -->'); ylabel ('--> Amplitude'); xn=y; N=input('enter the legth of the FFT sequence: '); xk=fft(xn,N); magxk=abs(xk); angxk=angle(xk); k=0:N-1; subplot(3,1,2); stem(k,magxk); grid xlabel('k'); ylabel('|x(k)|'); subplot(3,1,3); stem(k,angxk); disp(xk); grid xlabel('k'); ylabel('arg(x(k))');

OUTPUTS:
enter the length of Ramp sequence: 5

y=

5 -3.2639 - 1.8164i 2.5000 + 0.8123i 2.5000 - 3.4410i -7.7361 + 7.6942i

enter the length of the FFT sequence: 10 15.0000 -7.7361 - 7.6942i 2.5000 + 3.4410i -3.0000 2.5000 - 0.8123i -3.2639 + 1.8164i
-> A p d m litu e

GRAPHS:
rm e e e ap q n Su c 5

0 0 2 0

0 . 5

1 . 5

2 . 5 tmi e> -

3 . 5

4 . 5

|x k) ( |

1 0 0 0 5

4 k

a g x k) r ( ( )

4 k

14

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

% FFT of the Exponential Sequence : magnitude and phase response


clc; clear all; close all; %exponential sequence n=input('enter the length of exponential sequence: '); t=0:1:n; a=input('enter "a" value: '); y=exp(a*t); input('y=') disp(y); subplot(3,1,1); stem(t,y); grid; title('exponential response'); xlabel('time'); ylabel('amplitude'); disp(y); xn=y; N=input('enter the length of the FFT sequence: '); xk=fft(xn,N); magxk=abs(xk); angxk=angle(xk); k=0:N-1; subplot(3,1,2); stem(k,magxk); grid; xlabel('k'); ylabel('|x(k)|'); subplot(3,1,3); stem(k,angxk); grid; disp(xk); xlabel('k'); ylabel('arg(x(k))');

OUTPUTS:
enter the length of exponential sequence: 5 enter "a" value: 0.8

y=

1.0000

2.2255

4.9530 11.0232 24.5325 54.5982

enter the length of the FFT sequence: 10

98.3324 -73.5207 -30.9223i 50.9418 +24.7831i -41.7941 -16.0579i 38.8873 + 7.3387i -37.3613 38.8873 - 7.3387i -41.7941 +16.0579i 50.9418 -24.7831i -73.5207 +30.9223i GRAPHS :

15

SIGNAL PROCESSING LAB


exponential response 100 amplitude 50 0

M Tech (PTPG), SSP, I SEM

0.5

1.5

2.5 time

3.5

4.5

100 |x(k)| 50 0

4 k

5 arg(x(k))

-5

4 k

INFERENCE : The FFT for impulse, step, ramp and exponential sequences is generated using the FFT command. The magnitude plot is the absolute value of magnitude versus the samples and the phase plot is the phase angle versus the samples is plotted for different signals for different values. This program is very simple and requires defining the signal and finding FFT and plotting. RESULT : The FFT of different signals like impulse, step, ramp and exponential is found and the magnitude and phase plots of the same is plotted.

16

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

5. PROGRAM TO VERIFY DECIMATION AND INTERPOLATION AIM : To verify Decimation and Interpolation of a given Sequences SOFTWARE REQUIRED : MAT LAB 7.0 PROGRAM DESCRIPTION : The sampling rate alteration that is employed to generate a new sequence with a sampling rate higher or lower than that of a given sequence. Thus, if x[n] is a sequence with a sampling rate of FT Hz and it is used to generate another sequence y[n] with a desired sampling rate of FT' Hz, then the sampling rate alteration ratio is given by FT' / FT = R. If R > 1, the process is called interpolation and results in a sequence with a higher sampling rate. If R < 1, the sampling rate is decreased by a process called decimation and it results in a sequence with a lower sampling rate. The decimation and interpolation can be carried out by using the pre-defined commands decimate and interp respectively. PROGRAMS: % DECIMATION
clc; clear all; close all; disp('Let us take a sinusoidal sequence which has to be decimated: '); fm=input('Enter the signal frequency fm: '); fs=input('Enter the sampling frequnecy fs: '); T=input('Enter the duration of the signal in seconds T: '); dt=1/fs; t=dt:dt:T; M=length(t); m=cos(2*pi*fm*t); r=input('Enter the factor by which the sampling frequency has to be reduced r: '); md=decimate(m,r); figure(1); subplot(3,1,1); plot(t,m); grid; xlabel('t-->'); ylabel('Amplitude-->'); title('Sinusoidal signal before sampling'); subplot(3,1,2); stem(m); grid; xlabel('n-->'); ylabel('Amplitudes of m -->'); title('Sinusoidal signal after sampling before decimation'); subplot(3,1,3);

17

SIGNAL PROCESSING LAB


stem(md); grid; title('Sinusoidal after decimation'); xlabel('n/r-->'); ylabel('Amplitude of md-->');

M Tech (PTPG), SSP, I SEM

Output:
Enter Enter Enter Enter the the the the signal frequency fm: 2 sampling frequnecy fs: 100 duration of the signal in seconds T: 1 factor by which the sampling frequency has to be reduced r: 2

GRAPHS:
A p d o m - > litu e o m- > p d - > m litu e f A- p d s f dm A - m litu e S sd sn bo s pg i u i ai aer a ln no l gl f e m i 1 0 1 0 0 . 1 0 . 5 t> S sd sna r apgeeem n i ui ai afe m bo d i a no l gl t s ln fr c to i i 0 . 2 0 . 3 0 . 4 0 . 6 0 . 7 0 . 8 0 . 9 1

1 0 1 0 1 0 2 0 3 0 5 0 n > S sda r em n i ui afe c a n o l t di to i 4 0 6 0 7 0 8 0 9 0 1 0 0

1 0 1 0 5 1 0 1 5 2 0 2 5 n/r> 3 0 3 5 4 0 4 5 5 0

% INTERPOLATION
clc; clear all; close all; disp('Let us take a sinusoidal sequence which has to be interpolated: '); fm=input('Enter the signal frequency fm: '); fs=input('Enetr the sampling frequnecy fs: '); T=input('Enter the duration of the signal in seconds T: '); dt=1/fs; t=dt:dt:T; M=length(t); m=cos(2*pi*fm*t); r=input('Enter the factor by which the sampling frequency has to be increased r: '); md=interp(m,r); figure(1); subplot(3,1,1); plot(t,m); grid; xlabel('t-->'); ylabel('Amplitude-->'); title('Sinusoidal signal before sampling');

18

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

subplot(3,1,2); stem(m); grid; xlabel('n-->'); ylabel('Amplitudes of m -->'); title('Sinusoidal signal after sampling before interpolation'); subplot(3,1,3); stem(md); grid; title('Sinusoidal after interpolation'); xlabel('n x r-->'); ylabel('Amplitude of md-->');

Outputs:
Enter Enetr Enter Enter the the the the signal frequency fm: 2 sampling frequnecy fs: 100 duration of the signal in seconds T: 1 factor by which the sampling frequency has to be increased r: 2

GRAPHS:
Amplitude of md--> Amplitudes of m --> Amplitude--> S u o a s n l b fo sa p g in s id l ig a e re m lin 1 0 -1 0 0 .1 0 .5 0 .6 0 .7 t--> S u id l sig a a r s m lin b fo in rp la n in so a n l fte a p g e re te o tio 0 .2 0 .3 0 .4 0 .8 0 .9 1

1 0 -1 0 1 0 2 0 3 0 5 0 6 0 n --> S u id l a r in rp la n in so a fte te o tio 4 0 7 0 8 0 9 0 10 0

2 0 -2 0 2 0 4 0 6 0 8 0 10 0 nx r--> 10 2 10 4 10 6 10 8 20 0

INFERENCE : The only constraint about the program is that the factors of decimation or interpolation should be an integers. If we want to change the sampling frequency by a factor which is not an integer it can be done by using the command resample by which we can change the sampling rate by a factor I / D. For this we have to interpolate by an integer factor I and then decimate by an integer factor D RESULT : The Decimation and Interpolation of given sequences is verified and graphs are plotted.

19

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

6. PROGRAM TO CONVERT CD DATA INTO DVD DATA AIM : To convert the CD data into DVD data. SOFTWARE REQUIRED : MAT LAB 7.0 PROGRAM DESCRIPTION : In this program the CD data is converted into DVD data by using the command resample. Here the CD data is of the sampling frequency 44.1 kHz and the DVD data is of the sampling frequency 96.0 kHz. This is also one kind of sampling rate conversion by a factor. In this program first we generate the CD signal and from that we generate the decimated version by downsampling it and upsampling results in DVD data in a sampled version. Then plot the CD data and DVD data signals. PROGRAM :
clc; clear all; close all; fm=input('enter the signal frequency fm:'); fs=input('enter the sampling frequency fs:'); T=input('enter the duration of the signal in seconds:'); dt=1/fs; t=0:pi/100:pi m=sin(2*pi*fm*t); subplot(411); plot(m); xlabel('time-->'); ylabel('amplitude-->'); subplot(412); stem(m); xlabel('time-->'); ylabel('amplitude-->'); y=resample(m,96,44); subplot(413) stem(y); xlabel('time-->'); ylabel('amplitude-->'); subplot(414) plot(y); xlabel('time-->'); ylabel('amplitude-->');

OUTPUTS: enter the signal frequency fm:2 enter the sampling frequency fs:100 enter the duration of the signal in seconds:1

20

SIGNAL PROCESSING LAB GRAPHS :


amplitude--> 1 0 -1 0 20 40 60 time--> 80

M Tech (PTPG), SSP, I SEM

100

120

amplitude-->

1 0 -1 0 20 40 60 time--> 80 100 120

amplitude-->

2 0 -2 0 50 100 time--> 150 200 250

amplitude-->

2 0 -2 0 50 100 time--> 150 200 250

INFERENCE : This program is similar to resampling of the signal by a factor of 96000/41000. Since CD data is of the frequency 44.1 kHz and DVD data is of 96 kHz. We have to use the resample command only to carryout this experiment. Another way of doing this is to Interpolate the given signal by a factor of 96000 and then decimate by 44100. RESULT : Hence the CD data is converted into DVD data and the graphs are plotted.

21

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

7. GENERATION OF DUAL TONE MULTIPLE FREQUENCY (DTMF) SIGNALS AIM: To generation of dual tone multiple frequency ( DTMF ) signals. SOFTWARE REQUIRED: MAT LAB 7.0 PROGRAM DESCRIPTION: In this program the Dual tone multiple frequency signal which is used in telephone systems is generated. A DTMF signal consists of a sum of two tones, with frequencies taken from two mutually exclusive groups of preassigned frequencies. Each pair of such tones represents a unique number or a symbol. Decoding of a DTMF signal thus involves identifying the two tones in that signal and determining their corresponding number or symbol. PROGRAM:
clc; clear all; close all; number=input('enter a phone number with no spaces:','s'); fs=8192; T=0.5; x=2*pi*[697 770 852 941]; y=2*pi*[1209 1336 1477 1602]; 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),sin(y(4)*t)]/2; for k=1:length(number) switch number(k) case'1' tone=tx(:,1)+ty(:,1); sound(tone); plot(tone); case'2' tone=tx(:,1)+ty(:,2); sound(tone); plot(tone); case'3' tone=tx(:,1)+ty(:,3); sound(tone); plot(tone); case'A' tone=tx(:,1)+ty(:,4); sound(tone); plot(tone); case'4' tone=tx(:,2)+ty(:,1); sound(tone);

22

SIGNAL PROCESSING LAB


plot(tone); case'5' tone=tx(:,2)+ty(:,2); sound(tone); plot(tone); case'6' tone=tx(:,2)+ty(:,3); sound(tone); plot(tone); case'B' tone=tx(:,2)+ty(:,4); sound(tone); plot(tone); case'7' tone=tx(:,3)+ty(:,1); sound(tone); plot(tone); case'8' tone=tx(:,3)+ty(:,2); sound(tone); plot(tone); case'9' tone=tx(:,3)+ty(:,3); sound(tone); plot(tone); case'C' tone=tx(:,3)+ty(:,4); sound(tone); plot(tone); case'#' tone=tx(:,4)+ty(:,1); sound(tone); plot(tone); case'0' tone=tx(:,4)+ty(:,2); sound(tone); plot(tone); case'*' tone=tx(:,4)+ty(:,3); sound(tone); plot(tone); case'D' tone=tx(:,4)+ty(:,4); sound(tone); plot(tone); otherwise disp('invalid number');

M Tech (PTPG), SSP, I SEM

end; pause(0.75); end;

23

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

OUTPUT:
enter a phone number with no spaces: 963

GRAPHS:
1 0 . 8 0 . 6 0 . 4 0 . 2 0 0 . 2 0 . 4 0 . 6 0 . 8 1 0

5 0 0

1 0 0 0

1 5 0 0

2 0 0 0

2 5 0 0

3 0 0 0

3 5 0 0

4 0 0 0

4 5 0 0

1 0 . 8 0 . 6 0 . 4 0 . 2 0 0 . 2 0 . 4 0 . 6 0 . 8 1 0

5 0 0

1 0 0 0

1 5 0 0

2 0 0 0

2 5 0 0

3 0 0 0

3 5 0 0

4 0 0 0

4 5 0 0

1 0 . 8 0 . 6 0 . 4 0 . 2 0 0 . 2 0 . 4 0 . 6 0 . 8 1 0

5 0 0

1 0 0 0

1 5 0 0

2 0 0 0

2 5 0 0

3 0 0 0

3 5 0 0

4 0 0 0

4 5 0 0

24

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

INFERENCE: In this program the two frequencies which are going to produce the dual tone when we press any button, that is why it is called Dual Tone Multiple Frequency (DTMF). The only constraint is if the number we pressed is not there in the list then it will generate the output as invalid number. But here the frequencies are fixed. If we want to generate different tone we have to change the frequencies every time. RESULT: Hence Dual Tone Multiple Frequency (DTMF) signals are generated and the output is verified.

25

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

8. THE AUTOCORRELATION OF THE GIVEN SEQUENCE AIM : To find the autocorrelation of the given sequence SOFTWARE REQUIRED : MAT LAB 7.0 PROGRAM DESCRIPTION : In this program, the autocorrelation of sequence x[n] is computed by folding the sequence with respect to real axis and then taking the convolution of the folded sequence with the original sequence. It is generally denoted by

rxx ( l ) =
PROGRAM :

x(n)x(n-l)

where

l =..-2,-1,0,1,2,..

n = -

clc; clear all; close all; a=input('Enter the first sequence: '); subplot(211); stem(a); grid; xlabel('time samples-->'); ylabel('amplitudes-->'); title('given sequence'); n1=length(a); n2=n1-1; n3=n1+n2; b=[zeros(1,n2) a zeros(1,n2)]; for i=1:n3 j=n3 c=[zeros(1,i-1) a zeros(1,j-i)]; d=transpose(c); e(i)=b*d; disp('The auto correlation is: ');e subplot(212) stem(e); grid; xlabel('time samples-->'); ylabel('amplitudes-->'); title('The auto correlation of the given sequence'); end;

OUTPUTS:
Enter the first sequence: [2 3 4 5] The auto correlation is: e = 10 23 38 54 38 23 10

26

SIGNAL PROCESSING LAB GRAPHS :


given sequence 6 amplitudes-->

M Tech (PTPG), SSP, I SEM

1.5

2.5 3 time samples--> The auto correlation of the given sequence

3.5

60 amplitudes-->

40

20

4 time samples-->

INFERENCE : In this program first we have to append the zeros before and after the sequence which is equal to length of the sequence minus one. Then we can find the autocorrelation of that sequence by shifting the sequence every time by multiplying with the same sequence. Hence it results in the autocorrelation of the sequence. RESULT : Hence the autocorrelation of the given sequence is calculated and plotted.

27

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

9. POWER SPECTRAL DENSITY USING SQUARE MAGNITUDE AND AUTOCORRELATION AIM : To compute the Power Spectral Density of given signals using square magnitude and autocorrelation SOFTWARE REQUIRED : MAT LAB 7.0 PROGRAM DESCRIPTION : The stationary random processes do not have finite energy and hence do not processes a Fourier Transform. Such signals have finite average power and hence are characterized by a Power Density Spectrum or Power Spectral Density (PSD). In this program we have used the property of PSD that it can be calculated from its autocorrelation function by taking the time average. In the Square magnitude method after taking the FFT by taking the absolute value we get the PSD. PROGRAM :
clc; clear all; close all; f1=input('Enter the frequency of first sequence in Hz: '); f2=input('Enter the frequency of the second sequence in Hz: '); fs=input('Enter the sampling frequency in Hz: '); t=0:1/fs:1 x=2*sin(2*pi*f1*t)+3*sin(2*pi*f2*t)+rand(size(t)); px1=abs(fft(x).^2) px2=abs(fft(xcorr(x),length(t))); subplot(211) plot(t*fs,10*log10(px1));%square magnitude grid; xlabel('Freq.in Hz-->'); ylabel('Magnitude in dB-->'); title('PSD using square magnitude method'); subplot(212) plot(t*fs,10*log10(px2));%autocorrelation grid; xlabel('Freq.in Hz-->'); ylabel('Magnitude in dB-->'); title('PSD using auto correlation method');

OUTPUTS:
Enter the frequency of first sequence in Hz: 200 Enter the frequency of the second sequence in Hz: 400 Enter the sampling frequency in Hz: 1000

28

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

GRAPHS :
PSD using square magnitude method 100 Magnitude in dB-->

50

-50

100

200

400 500 600 700 Freq.in Hz--> PSD using auto correlation method

300

800

900

1000

60 Magnitude in dB-->

50

40

30

100

200

300

400 500 600 Freq.in Hz-->

700

800

900

1000

INFERENCE : The only constraint is to take the two frequencies must be two time lesser than the sampling frequencies. RESULT : Hence the PSD is computed using the square magnitude and Autocorrealtion and graph is plotted.

10. POWER SPECTRAL DENSITY USING PERIODOGRAM 29

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

AIM : To compute the Power Spectral Density of given signals using Periodoram SOFTWARE REQUIRED : MAT LAB 7.0 PROGRAM DESCRIPTION : The stationary random processes do not have finite energy and hence do not processes a Fourier Transform. Such signals have finite average power and hence are characterized by a Power Density Spectrum or Power Spectral Density (PSD). The property of PSD that it can be calculated from its autocorrelation function by taking the time average. In the Square magnitude method after taking the FFT by taking the absolute value we get the PSD. Here we used the command periodogram to estimate the PSD of the given signal of 200 Hz frequency. PROGRAM :
clc; clear all; close all; Fs=1000; t=0:1/Fs:0.3 x=cos(2*pi*t*200)+0.1*randn(size(t)); periodogram(x,[ ],'twosided',512,Fs);

GRAPHS:
Periodogram Power Spectral Density Estimate -10

-20

Power/frequency (dB/Hz)

-30

-40

-50

-60

-70

100

200

300

400 500 600 Frequency (Hz)

700

800

900

INFERENCE : In the computation of the PSD here we are using the command periodogram so it very simple to generate the PSD of the given signal and the output is verified and can be compared with the other PSD generation methods. RESULT : Hence the PSD is computed using the periodogram and graph is plotted.

30

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

11. POWER SPECTRAL DENSITY ESTIMATION USING PERIODOGRAM AND MODIFEIED PERIODOGRAM AIM : To compute the Power Spectral Density of given signals using Periodoram and Modified periodogram SOFTWARE REQUIRED : MAT LAB 7.0 PROGRAM DESCRIPTION : The stationary random processes do not have finite energy and hence do not processes a Fourier Transform. Such signals have finite average power and hence are characterized by a Power Density Spectrum or Power Spectral Density (PSD). The property of PSD that it can be calculated from its autocorrelation function by taking the time average. In the Square magnitude method after taking the FFT by taking the absolute value we get the PSD. The same can be calculated using periododram and modified periodogram methods. PROGRAM :
%% clearing screen clc; close all; clear all; %% psd calculation using fft t = 0:1023; x = sin(2*pi*50/1000*t)+sin(2*pi*120/1000*t); y = x+randn(size(t)); N=length(y); f1=1000*(0:N/2-1)/N; p=abs(fft(y).^2)/N; subplot(221); plot(f1,10*log10(p(1:512))); grid; xlabel('frequency-->'); ylabel('Power in dB-->'); title(' PSD estimation using fft') %% psd calculation using periodogram [Pxx,w]=periodogram(y); subplot(222); plot(1000*w/(2*pi),10*log10(Pxx)); grid; xlabel('frequency-->'); ylabel('Power in dB-->'); title('PSD using periodogram'); %% psd calculation using modified periodogram w=hanning(N); [Pxx,w]=periodogram(y,w); subplot(223); plot(1000*w/(2*pi),10*log10(Pxx)); grid; xlabel('frequency-->'); ylabel('Power in dB-->'); title('Modified periodogram'); %% psd calculation using auto correlation and fft

31

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

z=xcorr(y); m=length(z); g1=abs(fft(z)); n2=1000*(0:(m/2)-1)/m; subplot(224); plot(n2,10*log10(g1(1:1023))); grid; xlabel('frequency-->'); ylabel('Power in dB-->'); title('PSD estimate by auto correlation and fft')

GRAPHS :
PSD estimation using fft 40 Power in dB--> Power in dB--> 20 0 -20 -40 20 PSD using periodogram

-20

200 400 frequency--> Modified periodogram

600

20 Power in dB--> Power in dB--> 0 200 400 frequency--> 600 0 -20 -40 -60

200 400 600 frequency--> PSD estimate by auto correlation and fft 60 40 20 0 -20

-40

200 400 frequency-->

600

INFERENCE : In the computation of the PSD here we are using the command periodogram and modified periodogram is estimated by using the hanning window. So it very simple to generate the PSD of the given signal and the output is verified and it is compared with the other PSD generation methods. RESULT : Hence the PSD is estimated and compared with different methods.

32

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

12. POWER SPECTRAL DENSITY ESTIMATION USING BARLETT METHOD AIM : To estimate the Power Spectral Density using Barlett method SOFTWARE REQUIRED : MAT LAB 7.0 PROGRAM DESCRIPTION : The PSD can be calculated from the autocorrelation function of a signal by taking its the Fourier transform, called the periodogram. In general the variance of the estimate Pxx ( f ) does not decay to zero as N tends to infinity. Thus

The periodogram is not a consistent estimate of the true power density spectrum
i.e., it does not converge to the true power density spectrum. Thus the estimated spectrum suffers from the smoothing effects and the leakage embodied in the Barlett window. The smoothing and leakage ultimately limit our ability to resolve closely spaced spectra. The methods Barlett along with Blackman Tukey and Welch are classical methods and make no assumption about how the data were generated and hence called nonparametric methods. In this method for reducing the variance in the periodogram involves three steps: 1. First the N-point sequence is subdivided into K nonoverlapping segments, where segment has length M. 2. For each segment we compute the periodogram. 3. Finally, we average the periodograms for the K segments to obtain the Barlett power spectrum estimate. Thus Barlett method is called as Averaging Periodograms. PROGRAM:
clc; close all; clear all; t=0:1023 x=sin(2*pi*50/1000*t)+sin(2*pi*120/1000*t); y=x+randn(size(t)); N=length(y); k=4; M=N/k; x1=y(1:M); x2=y(M+1:2*M); x3=y(2*M+1:3*M); x4=y(3*M+1:4*M); px41=(1/M)*((abs(fft(x1))).^2); px42=(1/M)*((abs(fft(x2))).^2); px43=(1/M)*((abs(fft(x3))).^2); px44=(1/M)*((abs(fft(x4))).^2); px5=(px41+px42+px43+px44)/k; n1=1000*(0:M/2)/M; plot(n1,px5(1:M/2+1)); grid; xlabel('Normalized frequency in Hz -->'); ylabel('-->Power Spectrum in dB'); title('PSD ESTIMATION USING BARLETT METHOD');

33

SIGNAL PROCESSING LAB GRAPH:

M Tech (PTPG), SSP, I SEM

PSD ESTIMATION USING BARLETT METHOD 60

50

-->Power Spectrum in dB

40

30

20

10

50

100

150 200 250 300 350 Normalized frequency in Hz -->

400

450

500

INFERENCE : Estimation of Power Spectral Density using Barlett method is observed from the graph. RESULT : Hence the PSD is estimated using Barlett method.

34

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

13. POWER SPECTRAL DENSITY ESTIMATION USING WELCH METHOD AIM : To estimate the Power Spectral Density using Welch method SOFTWARE REQUIRED : MAT LAB 7.0 PROGRAM DESCRIPTION : The PSD can be calculated from the autocorrelation function of a signal by taking its the Fourier transform, called the periodogram. In general the variance of the estimate Pxx ( f ) does not decay to zero as N tends to infinity. Thus

The periodogram is not a consistent estimate of the true power density spectrum
i.e., it does not converge to the true power density spectrum. Thus the estimated spectrum suffers from the smoothing effects and the leakage embodied in the Barlett window. The smoothing and leakage ultimately limit our ability to resolve closely spaced spectra. The methods Barlett along with Blackman Tukey and Welch are classical methods and make no assumption about how the data were generated and hence called nonparametric methods. Welch made two modifications to the Barlett method. 1. First, he allowed the data sequence to overlap. 2. The second modification made by Welch to the Barlett method is to window the data segments prior to computing the periogram. Thus Welch method is called as Modified Periodogram. PROGRAM:
clc; close all; clear all; fs=1024; f1=200; f2=400; M=128; t=0:1/fs:1; x=sin(2*pi*f1*t)+sin(2*pi*f2*t)+rand(size(t)); L=length(x); K=L/M; wi=hann(M+1); m=0; su=[]; for i=1:M/2:L-M+1 y=wi'.*x(i:M+i); w2=abs(fft(y).^2); su=[su;w2]; end; su1=sum(su); su2=sum(wi.^2); w1=su1/su2; w12=10*log(w1); fs1=(fs/K)+2; t1=((1:fs1)/fs1);

35

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

plot(t1,w12); grid; xlabel('Normalized frequency -->'); ylabel('-->Power Spectrum in dB'); title('Welch method of Power Spectrum Estimation');

GRAPH:
Welch method of Power Spectrum Estimation 60

50

-->Power Spectrum in dB

40

30

20

10

-10

0.1

0.2

0.3

0.4 0.5 0.6 0.7 Normalized frequency -->

0.8

0.9

INFERENCE : Estimation of Power Spectral Density using Welch method is observed from the graph. RESULT : Hence the PSD is estimated using Welch method.

36

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

14. PSD ESTIMATION USING BLACKMAN AND TUKEY METHOD AIM : To estimate the Power Spectral Density using Blackman and Tukey method. SOFTWARE REQUIRED : MAT LAB 7.0 PROGRAM DESCRIPTION : The PSD can be calculated from the autocorrelation function of a signal by taking its the Fourier transform, called the periodogram. In general the variance of the estimate Pxx ( f ) does not decay to zero as N tends to infinity. Thus

The periodogram is not a consistent estimate of the true power density spectrum
i.e., it does not converge to the true power density spectrum. Thus the estimated spectrum suffers from the smoothing effects and the leakage embodied in the Barlett window. The smoothing and leakage ultimately limit our ability to resolve closely spaced spectra. The methods Barlett along with Blackman Tukey and Welch are classical methods and make no assumption about how the data were generated and hence called nonparametric methods. Blackman and Tukey proposed and analyzed the method in which the sample autocorrelation sequence is windowed first and then Fourier transformed to yield the estimate of the power spectrum. PROGRAM:
clc; close all; clear all; fs=1024; 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)); y1=wi'.*y; i=length(y); b=abs(fft(xcorr(y1)))/L; i1=length(b); t1=(1:i1)/i1; b1=10*log(b); plot(t1,b1); grid; xlabel('Normalized frequency -->'); ylabel('-->Power Spectrum in dB'); title('Blackman and Tukey method of Power Spectrum Estimation');

37

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

GRAPH:
Blackman and Tukey method of Power Spectrum Estimation 200

150 -->Power Spectrum in dB

100

50

-50

0.1

0.2

0.3

0.4 0.5 0.6 0.7 Normalized frequency -->

0.8

0.9

INFERENCE : Estimation of Power Spectral Density using Blackman and Tukey method is observed from the graph. RESULT : Hence the PSD is estimated using Blackman and Tukey method.

38

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

15. POWER SPECTRUM ESTIMATION USING YULE-WALKER METHOD AIM : To estimate the Power Spectral Density using Yule-Walker method. SOFTWARE REQUIRED : MAT LAB 7.0 PROGRAM DESCRIPTION : The Power Spectral Density can be calculated by Barlett along with Blackman Tukey and Welch are the classical methods and make no assumption about how the data were generated and hence called nonparametric methods. The nonparametric power spectrum estimation methods require the availability of long data records in order to obtain the necessary frequency resolution required in many applications. The limitations of nonparametric methods: 1. The inherent assumption that the auto correlation estimate is zero for m >= N. 2. Another inherent assumption is that in the periodogram estimate the data are periodic with period N. Neither one of these assumptions is realistic. The modeling approach eliminates the need for window functions and the assumption that the auto correlation is zero for |m| >= N. As a consequence, Parametric ( model-based ) power spectrum estimation methods avoid the problem of leakage and provide better resolution than do the FFT based, nonparametric methods. The Yule-Walker and Burg methods are called Parametric methods of Power Spectrum Estimation. Yule-Walker method: The Yule-walker method estimates simply the auto correlation from the data and use the estimates to solve for the AR model parameters.The result is a stable AR model. PROGRAM:
clc; close all; clear all; a=[1 -2.2137 2.9408 -2.1697 0.9609]; % AR filter coefficients randn('state',1); x=filter(1,a,randn(256,1)); % AR system output pyulear(x,4); % Fourth-order estimate xlabel('Normalized frequency -->'); ylabel('-->Power Spectrum in dB'); title('Yule-Walker method of Power Spectrum Estimation');

39

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

GRAPH:
Yule-Walker method of Power Spectrum Estimation 30

20

-->Power Spectrum in dB

10

-10

-20

-30

0.1

0.2

0.3

0.4 0.5 0.6 0.7 Normalized frequency -->

0.8

0.9

INFERENCE : Estimation of Power Spectral Density using Yule-Walker method is observed from the graph. RESULT : Hence the PSD is estimated using Yule-Walker method.

16. POWER SPECTRUM ESTIMATION USING BURG METHOD 40

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

AIM : To estimate the Power Spectral Density using Burg method. SOFTWARE REQUIRED : MAT LAB 7.0 PROGRAM DESCRIPTION : The Power Spectral Density can be calculated by Barlett along with Blackman Tukey and Welch are the classical methods and make no assumption about how the data were generated and hence called nonparametric methods. The nonparametric power spectrum estimation methods require the availability of long data records in order to obtain the necessary frequency resolution required in many applications. The limitations of nonparametric methods: 1. The inherent assumption that the auto correlation estimate is zero for m >= N. 2. Another inherent assumption is that in the periodogram estimate the data are periodic with period N. Neither one of these assumptions is realistic. The modeling approach eliminates the need for window functions and the assumption that the auto correlation is zero for |m| >= N. As a consequence, Parametric ( model-based ) power spectrum estimation methods avoid the problem of leakage and provide better resolution than do the FFT based, nonparametric methods. The Yule-Walker and Burg methods are called Parametric methods of Power Spectrum Estimation. Burg method: The method devised by Burg for estimating the AR parameters can be viewed as an order recursive least squares lattice method, based on the minimization of the forward and backward errors in linear predictors, with the constraint that the AR parameters satisfy the Levinson-Durbin recursion. PROGRAM:
clc; close all; clear all; a=[1 -2.2137 2.9408 -2.1697 0.9609]; % AR filter coefficients randn('state',1); x=filter(1,a,randn(256,1)); % AR system output pburg(x,4); % Fourth-order estimate xlabel('Normalized frequency -->'); ylabel('-->Power Spectrum in dB'); title('Burg method of Power Spectrum Estimation');

GRAPH: 41

SIGNAL PROCESSING LAB

M Tech (PTPG), SSP, I SEM

Burg method of Power Spectrum Estimation 30

20

-->Power Spectrum in dB

10

-10

-20

-30

0.1

0.2

0.3

0.4 0.5 0.6 0.7 Normalized frequency -->

0.8

0.9

INFERENCE : Estimation of Power Spectral Density using Burg method is observed from the graph. RESULT : Hence the PSD is estimated using Burg method.

42

You might also like