You are on page 1of 26

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY KANNAMPALAYAM(PO), COIMBATORE - 641 402.

DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING

DIGITAL SIGNAL PROCESSING LABORATORY

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

EX.NO:1.

GENERATION OF INPUT SIGNALS (UNIT STEP,UNIT RAMP,UNIT IMPULSE,


EXPONTENTIAL,SINE WAVE, COSINE WAVE)

AIM: To write an MATLAB program to generate various signals. SOFTWARE REQUIRED: MATLAB 7.0 ALGORITHM: UNIT IMPULSE RESPONSE: Start the program Enter the value of n Generates Zeros and ones for the corresponding values of n to get the impulse response Plot the output UNIT STEP RESPONSE: Start the program Enter the value of n
Generates Zeros and ones for the corresponding values of n to get the

unit step response Plot the output EXPONENTIAL RESPONSE: Start the program Enter the value of n
Generates Zeros and ones for the corresponding values of n to get the

exponential response

DIGITAL SIGNAL PROCESSING LAB

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

Plot the output UNIT RAMP RESPONSE: Start the program Enter the value of n
Generates Zeros and ones for the corresponding values of n to get the

unit ramp response Plot the output SINE WAVE: Start the program Enter the value of n
Generates Zeros and ones for the corresponding values of n to get the

Sine wave Plot the output COSINE WAVE: Start the program Enter the value of n
Generates Zeros and ones for the corresponding values of n to get the

Cosine wave Plot the output

DIGITAL SIGNAL PROCESSING LAB

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

FLOW CHART UNIT IMPULSE RESPONSE

DIGITAL SIGNAL PROCESSING LAB

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

Start Get the value of n

t = -2:1:2

y=[zeros(1,n),ones(1,1),zeros(1,n)]

Plot the o/p sequence

Stop

UNIT STEP RESPONSE

DIGITAL SIGNAL PROCESSING LAB

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

Start Get the value of n

t=0:1:n1-1

y=ones(1,n1)

Plot the o/p Sequence

Stop

UNIT RAMP RESPONSE

DIGITAL SIGNAL PROCESSING LAB

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

Start Get the value of n

t=0:1:n2

y=t

Plot the o/p Sequence

Stop

EXPONENTIAL RESPONSE:

DIGITAL SIGNAL PROCESSING LAB

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

Start Get the value of n

t=0:1:n3

y=exp(0.5*t)

Plot the o/p Sequence

Stop

DIGITAL SIGNAL PROCESSING LAB

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

SINE WAVE:

Start Get the value of n

t=0:0.01:pi

y=sin(2*pi*t)

Plot the o/p Sequence

Stop

DIGITAL SIGNAL PROCESSING LAB

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

COSINE WAVE:

Start Get the value of n

t=0:0.01:pi

y=cos(2*pi*t)

Plot the o/p Sequence

Stop

DIGITAL SIGNAL PROCESSING LAB

10

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

THEORY: (i) UNIT IMPULSE SEQUENCE: The Unit impulse sequence is a signal that is zero everywhere except at n = 0 where its value is unity. This signal sometimes referred to as unit impulse. MATHEMATICAL EQUATION: (n) = 1 for n = 0 = 0 for n 0 (ii)UNIT STEP SEQUENCE: The Unit step sequence is a signal that is zero everywhere except at n 0 where its value is unity . In otherwise integral of the impulse function is also a singularity function and called the unit step function. MATHEMATICAL EQUATION: u(n) = 1 for n 0 = 0 for n< 0 (iii) UNIT RAMP IMPULSE: The Unit Ramp Impulse is a signal that is zero everywhere except at for n 0 where its value is n . MATHEMATICAL EQUATION: ur(n) = n for n 0 = 0 for n< 0 (iv) EXPONENTIAL SEQUENCE: The Exponential sequence is a signal that exponential decreases for a < 1 and it exponential increases when a > 1.
DIGITAL SIGNAL PROCESSING LAB

11

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

MATHEMATICAL EQUATION : x(n) = an for all n (v) SINUSOIDAL SIGNAL: The sinusoidal signal is a signal which satisfies the condition x (t+T) = x(t) where T is he fundamental period. The period of the continuous-time sinusoidal signal can take any value, integral fraction or irrational. For different values of frequencies the continuous-time sinusoidal signal are themselves different. MATHEMATICAL EQUATION : x(n) = Asin(n +) (vi) COSINE SIGNAL: The two signals (sine and cosine) are the same shape but the cosine signal is phase shifted by 90 degrees (a quarter cycle). If you were to plot the two, the sine signal starts (t=0) at zero amplitude and the cosine starts at the max. amplitude.

PROGRAM: clc; clear all;


DIGITAL SIGNAL PROCESSING LAB

12

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

% UNIT IMPULSE SIGNAL% n=input('enter the unit impulse signal length:'); t=-n:1:n; y=[zeros(1,n),ones(1,1),zeros(1,n)]; subplot(2,3,1); stem(t,y); xlabel('n-->'); ylabel('Amplitude-->'); title('UNIT IMPULSE SIGNAL'); % UNIT STEP SIGNAL% n1=input('enter the unit step signal length:'); t=0:1:n1-1; y=ones(1,n1); subplot(2,3,2); stem(t,y); xlabel('n-->'); ylabel('Amplitude-->'); title('UNIT STEP SIGNAL'); % UNIT RAMP SIGNAL% n2=input('enter the unit ramp signal length:'); t=0:1:n2; y=t; subplot(2,3,3); stem(t,y); xlabel('n-->'); ylabel('Amplitude-->'); title('UNIT RAMP SIGNAL');

% EXPONENTIAL WAVE % n3=input('enter the Exponential wave length:'); t=0:1:n3; y=exp(0.5*t); subplot(2,3,4);
DIGITAL SIGNAL PROCESSING LAB

13

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

stem(t,y); xlabel('n-->'); ylabel('Amplitude-->'); title('EXPONENTIAL WAVE'); % SINE WAVE % t=0:0.01:2*pi; x=sin(2*pi*t); subplot(2,3,5); plot(t,x); xlabel('n-->'); ylabel('Amplitude-->'); title('SINE WAVE'); % COSINE WAVE % t=0:0.01:pi; x=sin(2*pi*t); subplot(2,3,6); plot(t,x); xlabel('n-->'); ylabel('Amplitude-->'); title('COSINE WAVE')

OUTPUT: enter the unit impulse signal length:5 enter the unit step signal length:6
DIGITAL SIGNAL PROCESSING LAB

14

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

enter the unit ramp signal length:6 enter the Exponential wave length:7

RESULT: Thus the Basic Waveforms are generated by using Mat lab. EX.NO:2 A. AIM: To perform the up sampling of the signal using MATLAB. UP SAMPLING

DIGITAL SIGNAL PROCESSING LAB

15

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

SOFTWARE REQUIRED: MATLAB 7.0 ALGORITHM:

Start the program


Get the input frequency

Generate the signal for the given frequency Get the sampling frequency Sample the generated signal with the sampling frequency
Plot the original, sampled

Stop the program

FLOW CHART

DIGITAL SIGNAL PROCESSING LAB

16

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

Start

Enter the frequency

Enter the n value

Find the amplitude

Display the sampled sequence

Stop

THEORY:

DIGITAL SIGNAL PROCESSING LAB

17

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

Sampling is the process of converting a Continuous Time signal x(t) into a Discrete Time signal x(n), by taking samples of the Continuous Time signal at discrete time instants. Thus if x(t) is the input, the output samples is x(nT) =x(n) ,where T is called the sampling interval. The time interval T between successive samples is called sampling period or sample interval and its reciprocal 1/T =Fs, is called sampling rate (samples per second ) or the sampling frequency(Hz). There exists a linear relationship between t and n as t = nT =n/Fs. As a consequence, there exists a relationship between the frequency variable F (or ) for analog signals and the frequency variable f (or ) for discrete time signal. f= F/Fs
-----------------

-(2.1)

Since the highest frequency in a Discrete Time signal is = or f=1/2, it follows that ,with a sampling rate Fs, the corresponding highest values of F and are Fmax = Fs /2 =1/2T max = Fs = /T where max = maximum continuous time signal frequency. Sampling frequency should be selected higher than the twice of maximum frequency present in the signal Fs 2Fmax .
------------------(2.2)

If not high frequency component present in the signal interfere with the low frequency components and this effect is known as aliasing. Because of aliasing, the original Continuous Time signal cannot be recovered due to loss

DIGITAL SIGNAL PROCESSING LAB

18

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

of information. There is no information loss if Continuous Time signal can be recovered from the samples. PROGRAM: clc; clear all; N=input('Enter the sequence length N:'); L=input('Enter the upsampling factor L:'); f1=0.01; f2=0.2; t=0:1:N-1; x=sin(2*pi*f1*t)+sin(2*pi*f2*t); x1=[zeros(1,L*N)]; t1=1:1:L*N; j=1:L:L*N; x1(j)=x; subplot(3,1,1); plot(t,x); xlabel('time-->'); ylabel('Amplitude-->'); title('analog signal'); subplot(3,1,2); stem(t,x); xlabel('n-->'); ylabel('Amplitude-->'); title('sampled signal'); subplot(3,1,3); stem(t1-1,x1); xlabel('n-->'); ylabel('Amplitude-->'); title('upsampled signal');

DIGITAL SIGNAL PROCESSING LAB

19

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

OUTPUT: Enter the sequence length N:10 Enter the upsampling factor L:3

RESULT: Thus the up sampling of the signal using MATLAB was performed.

DIGITAL SIGNAL PROCESSING LAB

20

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

EX.NO:2 B. AIM:

DOWN SAMPLING

To perform the down sampling of the signal using MATLAB. SOFTWARE REQUIRED: MATLAB 7.0 ALGORITHM:

Start the program


Get the input frequency

Generate the signal for the given frequency Get the sampling frequency Sample the generated signal with the sampling frequency
Plot the original, sampled

Stop the program

DIGITAL SIGNAL PROCESSING LAB

21

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

FLOW CHART

Start

Enter the frequency

Enter the n value

Find the amplitude

Display the sampled sequence

Stop

DIGITAL SIGNAL PROCESSING LAB

22

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

THEORY: Sampling is the process of converting a Continuous Time signal x(t) into a Discrete Time signal x(n), by taking samples of the Continuous Time signal at discrete time instants. Thus if x(t) is the input, the output samples is x(nT) =x(n) ,where T is called the sampling interval. The time interval T between successive samples is called sampling period or sample interval and its reciprocal 1/T =Fs, is called sampling rate (samples per second ) or the sampling frequency(Hz). There exists a linear relationship between t and n as t = nT =n/Fs. As a consequence, there exists a relationship between the frequency variable F (or ) for analog signals and the frequency variable f (or ) for discrete time signal. f= F/Fs
-----------------

-(2.1)

Since the highest frequency in a Discrete Time signal is = or f=1/2, it follows that ,with a sampling rate Fs, the corresponding highest values of F and are Fmax = Fs /2 =1/2T max = Fs = /T where max = maximum continuous time signal frequency. Sampling frequency should be selected higher than the twice of maximum frequency present in the signal Fs 2Fmax .
------------------(2.2)

If not high frequency component present in the signal interfere with the low frequency components and this effect is known as aliasing. Because of

DIGITAL SIGNAL PROCESSING LAB

23

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

aliasing, the original Continuous Time signal cannot be recovered due to loss of information. There is no information loss if Continuous Time signal can be recovered from the samples. PROGRAM: clc; clear all; N=input('Enter the sequence length N:'); M=input('Enter the downsampling factor M:'); f1=0.05; f2=0.2; t=0:1:N-1; x=sin(2*pi*f1*t)+sin(2*pi*f2*t); x1=x(1:M:N); t1=1:1:N/M; subplot(3,1,1); plot(t,x); xlabel('time-->'); ylabel('Amplitude-->'); title('analog signal'); subplot(3,1,2); stem(t,x); xlabel('n-->'); ylabel('Amplitude-->'); title('sampled signal'); subplot(3,1,3); stem(t1-1,x1); xlabel('n-->'); ylabel('Amplitude-->'); title('downsampled signal');

DIGITAL SIGNAL PROCESSING LAB

24

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

OUTPUT: Enter the sequence length N: 50 Enter the down sampling factor M: 2
a n a lo g s ig n a l 2 1 A m p litu d e --> 0 -1 -2 0

1 0

1 5

2 0

2 5 3 0 tim e --> s a m p le d s ig n a l

3 5

4 0

4 5

5 0

2 1 A m p litu d e --> 0 -1 -2 0

1 0

1 5

2 0

2 5 3 0 3 5 n --> d o w n s a m p le d s ig n a l

4 0

4 5

5 0

2 1 A m p litu d e --> 0 -1 -2 0

1 0 n -->

1 5

2 0

2 5

RESULT:

DIGITAL SIGNAL PROCESSING LAB

25

KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY

Thus the down sampling of the signal using MATLAB was performed. c

DIGITAL SIGNAL PROCESSING LAB

26

You might also like