Professional Documents
Culture Documents
EX.NO:1.
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
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
t = -2:1:2
y=[zeros(1,n),ones(1,1),zeros(1,n)]
Stop
t=0:1:n1-1
y=ones(1,n1)
Stop
t=0:1:n2
y=t
Stop
EXPONENTIAL RESPONSE:
t=0:1:n3
y=exp(0.5*t)
Stop
SINE WAVE:
t=0:0.01:pi
y=sin(2*pi*t)
Stop
COSINE WAVE:
t=0:0.01:pi
y=cos(2*pi*t)
Stop
10
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
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.
12
% 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
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
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
15
Generate the signal for the given frequency Get the sampling frequency Sample the generated signal with the sampling frequency
Plot the original, sampled
FLOW CHART
16
Start
Stop
THEORY:
17
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
18
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');
19
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.
20
EX.NO:2 B. AIM:
DOWN SAMPLING
To perform the down sampling of the signal using MATLAB. SOFTWARE REQUIRED: MATLAB 7.0 ALGORITHM:
Generate the signal for the given frequency Get the sampling frequency Sample the generated signal with the sampling frequency
Plot the original, sampled
21
FLOW CHART
Start
Stop
22
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
23
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');
24
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:
25
Thus the down sampling of the signal using MATLAB was performed. c
26