DSP Lab1
DSP Lab1
DSP Lab1
-1
AIM: 1. Graphical representation of discrete time signals and operation 2.Time domain analysis of discrete time systems. THEORY: Digital signal processing is concerned with the processing of a discrete-time signal, called the input signal, to develop another discrete-time signal,called the output signal, with more desirable properties. A discrete-time signal is represented as a sequence of numbers , called samples. A sample value of a typical discrete-time signal or sequence {x[n]} is denoted as x[n] with the argument n being an integer in the range inf and inf. Graphical representation of discrete time signal is shown
Signal Energy
y
Signal Power
y
MATLAB PROGRAMS
QUEST 1. Write Program to generate the unit sample sequence and display it.
t=-5:5 y=1.*(t==0)+0.*(t<0)+0.*(t>0) stem(t,y) xlabel('time') ylabel('y(t)')
ANS.
1 0.9 0.8 0.7 0.6 y (t) 0.5 0.4 0.3 0.2 0.1 0 -5
-4
-3
-2
-1
0 tim e
QUSEST 2. Modify Program to generate a delayed unit sample sequence with a delay of 11 samples. ANS.
t=-5:30 y=1.*((t-11)==0)+0.*((t-11)<0)+0.*((t-11)>0) stem(t,y) xlabel('time') ylabel('y(t)')
1 0.9 0.8 0.7 0.6 y (t) 0.5 0.4 0.3 0.2 0.1 0 -5
10 tim e
15
20
25
QUEST 3. Write Program to generate the unit sample sequence u[n] and display it ANS.
t=-10:10 y1=1.*(t==0) y2=1.*(t>0)+0.*(t<0) y=y1+y2; stem(t,y) xlabel('time-->')
ylabel('y(t)')
1 0.9 0.8 0.7 0.6 y (t) 0.5 0.4 0.3 0.2 0.1 0 -10
-8
-6
-4
-2
0 tim e-->
10
QUEST 4. Modify Program to generate a delayed unit step sequence with an advance of 7 samples.
t=-10:10 n=t+7; y1=1.*(n==0) y2=0.*(n>0)+0.*(n<0) y=y1+y2; stem(t,y) xlabel('time-->') ylabel('y(t)')
1 0.9 0.8 0.7 0.6 y (t) 0.5 0.4 0.3 0.2 0.1 0 -10
-8
-6
-4
-2
0 tim e-->
10
QUEST 5. Write Program to generate the complex-valued exponential sequence with (1/12)+(pi/6)*I and A=2. ANS.
t=-10:10 a=2 b=(1/12)+(pi/6)*i y=a.*(b.^t) stem(t,y) xlabel('Time') ylabel('y(t)')
600 500 400 300 y (t) 200 100 0 -100 -200 -10
-8
-6
-4
-2
0 Tim e
10
QUEST 6. Write Program to generate the sinusoidal sequence with f = 0.1 Hz, phase = 0; A = 1.5 ANS.
t=-10:10 f=.1 a=1.5 y=a*(sin(2*pi*f.*t)) stem(t,y) xlabel('time') ylabel('sin fntn')
1.5
0.5 s in fnt n
-0.5
-1
-1.5 -10
-8
-6
-4
-2
0 tim e
10
QUEST 7. Compute the average power of the generated sinusoidal sequence. ANS.
t=-10:10 f=0.1 a=1.5 x=a*( sin(2*pi* f.*t)) stem(t,x) sum=0 for i=1:10 y=(abs(a*( sin(2*pi* f.*i))).^2) sum=sum+y end power=sum/10
sum = 11.2500 power = 1.1250 QUEST 8. Modify the above program to generate a sinusoidal sequence of length 50, frequency 0.08, amplitude 2.5, and phase shift 90 degrees and display it. What is the period of this
sequence? ANS.
n=-25:1:25 f=0.08 a=2.5 p=pi/2 x=a*( sin(2*pi* f.*n+p)) stem(n,x) xlabel('time') ylabel('sin fn') timeperiod=1/f
timeperiod = 12.5000
2.5 2 1.5 1 0.5 s in fn 0 -0.5 -1 -1.5 -2 -2.5 -25
-20
-15
-10
-5
0 tim e
10
15
20
25
QUEST 9. Replace the stem command with the stairs command and run the above program again. What is the difference between the new plot and those generated above? ANS.
n=-25:25 f=0.08 a=2.5
timeperiod =
12.5000
-20
-15
-10
-5
0 tim e
10
15
20
25
QUEST 10. Write a MATLAB program to generate and display five sample sequences of a random sinusoidal signal of length 31 {X[n]} = {A cos( on + )}, where the amplitude A and the phase are statistically independent random variables with uniform probability distribution in the range 0 A 4 for the amplitude and in the range 0 2 for the phase. ANS.
n= 0:31 f=1/31 a=4*rand(5) w=2*pi*rand(5)
for i=1:5 for r=1:5 x=a(r,r).*cos(2*pi* f.*n+ w(r,r)) stem(n,x) hold all end end xlabel('time') ylabel('sin fn')
4 3 2 1 s in fn 0 -1 -2 -3 -4
10
15 tim e
20
25
30
35
QUEST 11. Write a program to implements the signal smoothing algorithm to smooth a sequence x[n] = 2n*(.9)n for n=0:50 which is corrupted by Gaussian distributed noise with mean 0.5 and variance .5.
n=1:50 s= (2.*n).*(.9.^n) u= .5 g=.5^.5
50
100
150
200
250 tim e
300
350
400
450
500
QUEST 12. Write a program to generate the amplitude modulated signal y[n] for various values
of the frequencies of the carrier signal xH[n] and the modulating signal xL[n], and for various values of the modulation index m.
n=0:.1:20 a=5 m=1*rand(5) wl=2*pi*rand(5) wh=2000*pi*rand(5) for i=1:5 for j=1:5 for k=1:5 x1=cos(wl(r,r).*n) x2=cos(wh(r,r).*n) x3=m(r,r) end end end y=a*(1+x3.*x1).*x2 plot(n,y)
10
-2
-4
-6
-8
-10
10
12
14
16
18
20
QUEST 13. Write your own a matlab function named DT_conv that perform DT convolution of
two sequence which takes sequences as argument and return the convolved sequence.
function y =dt_conv(x,h) x=[3 11 7 0 -1 4 2 0]; h=[0 0 2 3 0 -5 2 1 ]; m=length(x); n=length(h); w=m+n-1; y=zeros(1,w) for i=1:w for j=1:n if( (i+1-j )>0 && (i+1-j) <= n ) y(1,i)=y(1,i)+(x(j).*h(i+1-j)) end end end
QUEST 14. Use above function DT_conv to convolve sequence . x[n]=[3,11,7,0,-1,4,2]; nx = [-3:3], h[n] = [2,3,0,-5,2,1]; nh = [-1:4] . Verify the result with inbuilt function conv. Also give graphical representation of all the sequences under consideration
x=[3 11 7 0 -1 4 2 0]; h=[0 0 2 3 0 -5 2 1 ]; y=dt_conv(x,h); y1=conv(x,h); subplot(2,1,1); stem(y) subplot(2,1,2); stem(y1)
Result: All the programs were successfully implemented using MATLAB. Learning Outcomes: y y y y y y I learnt working on discreet time signals and plotting them on MATLAB. I learnt creating and working with functions. I learnt use of stair function in MATLAB. I learnt about unit step and unit impulse function and their corresponding responses viz. unit step response and impulse response. I learnt plotting sine function and finding energy of these signals. I learnt using rand function.