matlab experiments
Post on 28-Dec-2015
48 Views
Preview:
DESCRIPTION
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.
APPRATUS: Matlab version 7
PROGRAM:
clc;
clear all;
close all;
a=input('enter the sequence:');
b=input('enter the lenth of fft:');
X=fft(a,b);
stem(X);
X
title('FFT');
xlabel('n (samples)');
ylabel('Amplitude');
OUTPUT:enter the sequence:[0 1 2 3 4 5 6 7]
enter the lenth of fft:8
X =
Columns 1 through 6
DEEPAK AGGARWAL Page 15 CO10510
DSP LAB CCET-26
28.0000 -4.0000 + 9.6569i -4.0000 + 4.0000i -4.0000 + 1.6569i -4.0000 -4.0000 - 1.6569i
Columns 7 through 8
-4.0000 - 4.0000i -4.0000 - 9.6569i
DEEPAK AGGARWAL Page 16 CO10510
DSP LAB CCET-26
EXPERIMENT-6(a)
AIM: Write a program for design of butterworth low pass filter using MATLAB software.
APPRATUS: Matlab version 7
PROGRAM:
clc;
close all;
clear all;
format long
rp=input('Enter the passband ripple: ');
rs=input('Enter the stopband ripple: ');
wp=input('Enter the passband freq: ');
ws=input('Enter the stopband freq: ');
fs=input('Enter the sampling freq: ');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
[z,p,k]=butter(n,wn);
[b,a]=zp2tf(z,p,k);
[b,a]=butter(n,wn,'s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('Gain in db-->');
xlabel('(a) Normalized frequency-->');
subplot(2,1,2);
DEEPAK AGGARWAL Page 17 CO10510
DSP LAB CCET-26
plot(om/pi,an);
xlabel('(b) Normalised frequency-->');
ylabel('Phase in radians-->');
OUTPUT:Enter the passband ripple: 0.15
Enter the stopband ripple: 60
Enter the passband freq: 1500
Enter the stopband freq: 3000
Enter the sampling freq: 7000
DEEPAK AGGARWAL Page 18 CO10510
DSP LAB CCET-26
EXPERIMENT-6(b)
AIM: Write a program for design of butterworth high pass filter using MATLAB software.
APPRATUS: Matlab version 7
PROGRAM:
clc;
close all;
clear all;
format long
rp=input('Enter the passband ripple: ');
rs=input('Enter the stopband ripple: ');
wp=input('Enter the passband freq: ');
ws=input('Enter the stopband freq: ');
fs=input('Enter the sampling freq: ');
w1=2*wp/fs; w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
[b,a]=butter(n,wn,'high','s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('Gain in db-->');
xlabel('(a) Normalized frequency-->');
subplot(2,1,2);
plot(om/pi,an);
xlabel('(b) Normalised frequency-->');
ylabel('Phase in radians-->');
DEEPAK AGGARWAL Page 19 CO10510
DSP LAB CCET-26
OUTPUT:Enter the passband ripple: 0.2
Enter the stopband ripple: 40
Enter the passband freq: 2000
Enter the stopband freq: 3500
Enter the sampling freq: 8000
>>
DEEPAK AGGARWAL Page 20 CO10510
DSP LAB CCET-26
EXPERIMENT-7(a)
AIM: Write a program for design of Chebyshev low pass filter using MATLAB software.
APPRATUS: Matlab version 7
PROGRAM:
%low pass chebyshev
clc;
close all;
clear all;
format long
rp=input('Enter the passband ripple: ');
rs=input('Enter the stopband ripple: ');
wp=input('Enter the passband freq: ');
ws=input('Enter the stopband freq: ');
fs=input('Enter the sampling freq: ');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb1ord(w1,w2,rp,rs,'s');
[b,a]=cheby1(n,rp,wn,'s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel('Gain in db-->');
xlabel('(a) Normalized frequency-->');
subplot(2,1,2);plot(om/pi,an);
xlabel('(b) Normalised frequency-->');
ylabel('Phase in radians-->');
DEEPAK AGGARWAL Page 21 CO10510
DSP LAB CCET-26
OUTPUT:Enter the passband ripple: 0.23
Enter the stopband ripple: 47
Enter the passband freq: 1300
Enter the stopband freq: 1550
Enter the sampling freq: 7800
>>
DEEPAK AGGARWAL Page 22 CO10510
DSP LAB CCET-26
EXPERIMENT-7(b)
AIM: Write a program for design of Chebyshev high pass filter using MATLAB software.
APPRATUS: Matlab version 7
PROGRAM:
%high pass chebyshev
clc;
close all;
clear all;
format long
rp=input('Enter the passband ripple... ');
rs=input('Enter the stopband ripple... ');
wp=input('Enter the passband freq... ');
ws=input('Enter the stopband freq...');
fs=input('Enter the sampling freq...');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]= cheb1ord(w1,w2,rp,rs,'s');
[b,a]=cheby1(n,rp,wn,'high','s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('Gain in db-->');
xlabel('(a) Normalized frequency-->');
subplot(2,1,2);
plot(om/pi,an);
DEEPAK AGGARWAL Page 23 CO10510
DSP LAB CCET-26
xlabel('(b) Normalised frequency-->');
ylabel('Phase in radians-->');
OUTPUT:Enter the passband ripple... 0.29
Enter the stopband ripple... 29
Enter the passband freq... 900
Enter the stopband freq...1300
Enter the sampling freq...7500
>>
DEEPAK AGGARWAL Page 24 CO10510
DSP LAB CCET-26
EXPERIMENT-8
AIM: Write a program for design of FIR low pass & high pass filter using MATLAB software.
APPRATUS: Matlab version 7
PROGRAM:
clc;
close all;
clear all;
format long
rp=input('Enter the passband ripple: ');
rs=input('Enter the stopband ripple: ');
fp=input('Enter the passband freq: ');
fs=input('Enter the stopband freq: ');
f=input('Enter the sampling freq: ');
wp=2*fp/f;ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if (rem(n,2)~=0)
n1=n;
n=n-1;
end
y=boxcar(n1);
%LOW PASS FILTER
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,1);plot(o/pi,m);ylabel('Gain in db-->');xlabel('(a) Normalized frequency-->');
DEEPAK AGGARWAL Page 25 CO10510
DSP LAB CCET-26
title('Low pass');
%HIGH PASS FILTER
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,2);plot(o/pi,m);ylabel('Gain in db-->');xlabel('(b) Normalized frequency-->');
title('High pass');
OUTPUT:Enter the passband ripple: 0.05
Enter the stopband ripple: 0.04
Enter the passband freq: 1500
Enter the stopband freq: 2000
Enter the sampling freq: 9000
>>
DEEPAK AGGARWAL Page 26 CO10510
top related