This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
DSP LAB CCET-26
EXPERIMENT-1(a)
AIM: Write a program to plot sinusoidal waveform using MATLAB software.
APPRATUS: Matlab version 7
PROGRAM:
clc;
clear all;
close all;
x=linspace(0,2*pi,100);
plot(x,sin(x))
xlabel('time');
ylabel('sin x');
title('sine wave');
axis('equal');
grid on;
OUTPUT:
DEEPAK AGGARWAL Page 1 CO10510
DSP LAB CCET-26
EXPERIMENT-1(b)
AIM: Write a program to plot spacecurve (3D) waveform using MATLAB software.
APPRATUS: Matlab version 7
PROGRAM:
clc;
clear all;
close all;
x=linspace(0,20,100);
plot3(sin(x),cos(x),x); % it is in the form x,y,z
xlabel('Sin x');
ylabel('Cos x');
zlabel('time');
title('space curve');
grid on;
OUTPUT:
DEEPAK AGGARWAL Page 2 CO10510
DSP LAB CCET-26
EXPERIMENT-1(c)
AIM: Write a program to plot spacecurve (3D) waveform using MATLAB software.
APPRATUS: Matlab version 7
PROGRAM:
clc;
close all;
r=5;
t=linspace(0,2*pi,100);
x=r*cos(t);
y=r*sin(t);
plot(x,y);
xlabel('X-axis');
ylabel('Y-axis');
title('Circle');
grid on;
OUTPUT:
DEEPAK AGGARWAL Page 3 CO10510
DSP LAB CCET-26
EXPERIMENT-1(d)
AIM: Write a program to plot the sub plotting of different functions using MATLAB software.
APPRATUS: Matlab version 7
PROGRAM:
clc;
clear all;
close all;
t=linspace(0,2*pi,100);
y1=sin(t);
y2=exp(t);
y3=cos(t);
subplot(3,1,1)
plot(t,y1);
title('Sin x');
grid on;
subplot(3,1,2)
plot(t,y2);
title('exp x');
grid on;
subplot(3,1,3)
plot(t,y3);
title('Cos x');
grid on;
DEEPAK AGGARWAL Page 4 CO10510
DSP LAB CCET-26
OUTPUT:
DEEPAK AGGARWAL Page 5 CO10510
DSP LAB CCET-26
EXPERIMENT-1(e)
AIM: Create a matrix and perform different mathematical operation on matrix using MATLAB
software.
APPRATUS: Matlab version 7
PROGRAM:
>> a=[1,2,3;4,5,6;7,8,9]
a =
1 2 3
4 5 6
7 8 9
>> a(2,3)
ans =
6
>> b=a(2:3,1:3)
b =
4 5 6
7 8 9
>> a'
ans =
1 4 7
2 5 8
3 6 9
DEEPAK AGGARWAL Page 6 CO10510
DSP LAB CCET-26
>> a*a'
ans =
14 32 50
32 77 122
50 122 194
>> a'*a
ans =
66 78 90
78 93 108
90 108 126
>> eye(3)
ans =
1 0 0
0 1 0
0 0 1
>> diag (a)
ans =
1
5
9
DEEPAK AGGARWAL Page 7 CO10510
DSP LAB CCET-26
EXPERIMENT-2 (a)
AIM: Write a program to plot unit impulse function using MATLAB software.
APPRATUS: Matlab version 7
PROGRAM:
clc;
clear all;
close all;
n=input('enter the value of n:');
t=-n:1:n;
z=[zeros(1,n),ones(1,1),zeros(1,n)]
stem(t,z);
grid on;
title('unit impulse');
xlabel('X-axis');
ylabel('Y-axis');
OUTPUT:enter the value of n:4z = 0 0 0 0 1 0 0 0 0
DEEPAK AGGARWAL Page 8 CO10510
DSP LAB CCET-26
EXPERIMENT-2 (b)
AIM: Write a program to plot unit step function using MATLAB software.
APPRATUS: Matlab version 7
PROGRAM:
clc;
close all;
n=input('enter the value of n:');
t=0:1:n-1;
y=ones(1,n);
subplot(2,1,2);
stem(t,y);
grid on;
title('unit step');
xlabel('X-axis');
ylabel('Y-axis');
OUTPUT:enter the value of n:7
DEEPAK AGGARWAL Page 9 CO10510
DSP LAB CCET-26
EXPERIMENT-2 (c)
AIM: Write a program to plot ramp function using MATLAB software.
APPRATUS: Matlab version 7
PROGRAM:
clc;
close all;
n=input('enter the length of ramp sequence:');
t=0:1:n;
stem(t,t);
grid on;
title('Ramp sequence');
xlabel('X-axis');
ylabel('Y-axis');
OUTPUT:enter the length of ramp sequence:7
DEEPAK AGGARWAL Page 10 CO10510
DSP LAB CCET-26
EXPERIMENT-3
AIM: Write a program to realize linear convolution of signal using MATLAB software.
APPRATUS: Matlab version 7
PROGRAM:
clc;
clear all;
close all;
a=input('enter the 1st sequence:');
m1=input('enter the ll of a:');
m2=input('enter the hl of a:');
m=[m1:m2];
b=input('enter the 2nd sequence:');
t1=input('enter the ll of b:');
t2=input('enter the hl of b:');
t=[t1:t2];
n1=m1+t1;
n2=m2+t2;
c=conv(a,b);
n=[n1:n2];
stem(c);
disp('resultant');c
title ('convolution');
xlabel('n (samples)');
ylabel('Amplitude');
OUTPUT:enter the 1st sequence:[1 2 3 4]
DEEPAK AGGARWAL Page 11 CO10510
DSP LAB CCET-26
enter the ll of a:-2
enter the hl of a:1
enter the 2nd sequence:[2 3 4 5]
enter the ll of b:0
enter the hl of b:3
resultant
c =
2 7 16 30 34 31 20
DEEPAK AGGARWAL Page 12 CO10510
DSP LAB CCET-26
EXPERIMENT-4
AIM: Write a program to realize Correlation of a signal using MATLAB software.
APPRATUS: Matlab version 7
PROGRAM:
clc;
clear all;
close all;
a=input('enter the 1st sequence:');
m1=input('enter the ll of a:');
m2=input('enter the hl of a:');
m=[m1:m2];
b=input('enter the 2nd sequence:');
t1=input('enter the ll of b:');
t2=input('enter the hl of b:');
t=[t1:t2];
n1=m1+t1;
n2=m2+t2;
c=xcorr(a,b);
n=[n1:n2];
stem(c);
title('correlation')
disp('resultant');c
xlabel('n (samples)');
ylabel('Amplitude');
DEEPAK AGGARWAL Page 13 CO10510
DSP LAB CCET-26
OUTPUT:enter the 1st sequence:[1 2 3 4]
enter the ll of a:-2
enter the hl of a:1
enter the 2nd sequence:[2 3 4 5]
enter the ll of b:0
enter the hl of b:3
resultant
c =
5 14 26 40 29 18 8
DEEPAK AGGARWAL Page 14 CO10510
DSP LAB CCET-26
EXPERIMENT-5
AIM: Write a program to realize FFT of a signal using MATLAB software.