flipkart ads

Matlab Practicals for Digital Signal Processing

Program for the generation of unit impulse signal [n] -3N3 .

clc;
clear all;
close all;
display('Obtaining UNIT IMPULSE signal')
display('Generalized for any value of n')
n = input('enter the value of n = ')
A = linspace(-n,n,(2*n+1))
for i=1:(2*n+1)
    if i==(n+1)
        a(i)=1;
    else
        a(i)=0;
    end
end
    stem(A,a)
    xlabel('value of n')
    title('IMPULSE SIGNAL d(n)')


Q.2 Program for the generation of unit step signal, d[n] = u[n]-u[n-k]

clc;
clear all;
close all;
display('Obtaining UNIT SAMPLE signal using UNIT STEP signals')
display('Generalized for any value of n')
n = input('enter the value of n = ')
A = linspace(-n,n,(2*n+1))
for i=1:(2*n+1)
    if i>=(n+1)
        a(i)=1;
    else
        a(i)=0;
    end
end
for i=1:(2*n+1)
    if i>=(n+1)+1
        b(i)=1;
    else
        b(i)=0;
    end
end
subplot(2,2,1);
stem(A,a);
xlabel('value of n');
title('UNIT STEP SIGNAL U(n)');
subplot(2,2,2);
stem(A,b);
xlabel('value of n');
title('UNIT DELAYED STEP SIGNAL U(n-1)');
subplot(2,2,3);
stem(A,(a-b));
xlabel('value of n');
title('UNIT SAMPLE SIGNAL d(n)');


Q.3  Program for the generation of unit ramp signal r[n] -3N3 .
clc;
clear all;
close all;
display('Obtaining RAMP signal ')
display('Generalized for any value of n')
n = input('enter the value of n = ')
A = linspace(-n,n,(2*n+1))
for i=1:(2*n+1)
    if i>=(n+1)
        a(i)=i-(n+1);
    else
        a(i)=0;
    end
end
stem(A,a);
xlabel('value of n');
title('UNIT RAMP SIGNAL r(n)');


Q.4  Program for the generation of exponentially signal x[n] -3N3 .

clc;
clear all;
close all;
display('Obtaining EXPONENTIAL signal ka^n')
display('Generalized for any value of n')
n = input('enter the value of n = ')
k = input('enter the value of k = ')
a = input('enter the value of a = ')
A = linspace(-n,n,(2*n+1))
for i=1:(2*n+1)
    if i>=0
        b(i)=k.*(a.^(i));
    else
        b(i)=0;
    end
end
stem(A,b);
xlabel('value of n');
title('EXPONENTIAL SIGNAL x(n)');



Q.5  Program for the generation of unit cosine & sine signal x[n] -3N3 .
clc;
clear all;
close all;
display('Obtaining SINE AND COSINE signals ')
display('Generalized for any value of n')
n = input('enter the value of n = ')
t = -n:0.04:n;
x = sin(2*pi*t);
y = cos(2*pi*t);
subplot(2,1,1)
stem(t,x);
xlabel('value of n');
title('SINE SIGNAL x(n)');
subplot(2,1,2)
stem(t,y);
xlabel('value of n');
title('COSINE SIGNAL x(n)');



Q.6  Program for the generation of exponential signal x[n] -3N3 .

clc;
clear all;
close all;
display('Obtaining EXPONENTIAL signal ka^n')
display('Generalized for any value of n')
n = input('enter the value of n = ')
k = input('enter the value of k = ')
a = input('enter the value of a = ')
A = linspace(-n,n,(2*n+1))
for i = 1:(2*n+1)
    if i>=(n+1)
        b(i)=k.*(a.^(i));
    else if i<=(n+1)
            b(i)=k.*(a.^(i));
        else
        b(i)=0;
    end
    end
end
stem(A,b);
xlabel('value of n');
title('EXPONENTIAL SIGNAL x(n)');



Q.7 Write the a Matlab function to perform on two DT sequence x1[n] & x2[n]
       a. Addition    b. Multiplication    c. Shifting    d. Folding    e. even/odd

clc;
clear all;
close all;
i = input('enter the value of n = ')
j = input('enter the value of j = ')
 n = -i:1:i
u1 = (n>=0)
d1 = (n==0)
u2 = (n+j>=0)
u3 = (n-j>=0)
e1 = cos(2*pi*n)
e2 = cos(2*pi*(-n))
'addition x1=u1+d1'
x1 = u1+d1
'multiplication x1=u1*d1'
x2 = u1.*d1
'shifting x1=u2-u3'
x3 = u2-u3
'folding x1=-u1'
x4 = (-n>=0)
'shifting x1=u1+d1'
x3 = u2-u3
subplot(3,3,1)
stem(n,u1)
title(' u1 ')
subplot(3,3,2)
stem(n,d1)
title(' d1 ')
subplot(3,3,3)
stem(n,u2)
title(' u2 ')
subplot(3,3,4)
stem(u3)
title('u3')
subplot(3,3,5)
stem(n,x1)
title('addition x1 = u1+d1 ')
subplot(3,3,6)
stem(n,x2)
title('multiplication x1 = u1*d1 ')
subplot(3,3,7)
stem(n,x3)
title('shifting x1 = u2-u3 ')
subplot(3,3,8)
stem(n,x4)
title('folding x1 = -u1 ')
if e1==e2
display('function is even')
else
     display('function is odd')
end


Q.8 Plot each signal x[n] compare with the original signal. -10≥n≥10
a. x[n] = u[n+4] – u[n-4] + 2[n+6] – [n-3]                 y[n] = x[-n-4]
clc;
clear all;
close all;
 n = -10:1:10
u1 = (n+4>=0);
u2 = (n-4>=0);
d1 = 2*(n+6==0);
d2 = (n-3==0);
 m = (-n-4);
 x = u1-u2+d1-d2;
subplot(1,2,1);
stem(n,x);
subplot(1,2,2);
stem(m,x);



b. x[n] = u[n+4] – u[n-4] + 2[n+6] – [n-3]                 y[n] = x[2n+4]

clc;
clear all;
close all;
n=-10:1:10
u1 = (n+4>=0);
u2 = (n-4>=0);
d1 = 2*(n+6==0);
d2 = (n-3==0);
 m = (2*n)+4;
 x = u1-u2+d1-d2;
subplot(1,2,1);
stem(n,x);
subplot(1,2,2);
stem(m,x);






4 comments:

flipkart products