Professional Documents
Culture Documents
Date:-
Program:-1(A)
%<------RAMP SIGNAL----->
t=-0:0.001:5;
x=t;
subplot(3,2,2);
plot(t,x);
%<------SINE SIGNAL----->
x=0:0.005:20;
subplot(3,2,3);
plot(x,sin(x));
title('sine signal is:');
ylabel('amplitude');
xlabel('time index');
%<------COSINE SIGNAL---->
x=0:0.001:20;
subplot(3,2,4);
plot(x,cos(x));
title('cosine signal is:');
ylabel('amplitude');
xlabel('time index');
%<-----TRIANGLE PULSE----->
x=-0.5:0.001:0.5;
y = tripuls(x)
subplot(3,2,5)
plot(x,y)
title('triangle signal is:');
ylabel('amplitude');
xlabel('time index');
COMMAND WINDOW:
Columns 1 through 9
0 0.0020 0.0040 0.0060 0.0080 0.0100 0.0120 0.0140
0.0160
Columns 10 through 18
0.0180 0.0200 0.0220 0.0240 0.0260 0.0280 0.0300 0.0320
0.0340
Columns 19 through 27
0.0360 0.0380 0.0400 0.0420 0.0440 0.0460 0.0480 0.0500
0.0520
Columns 28 through 36
0.0540 0.0560 0.0580 0.0600 0.0620 0.0640 0.0660 0.0680
0.0700
FIGURE:-
Program:-1(B)
Date:-
%<-----Sine signal----->
x=0:0.001:10;
subplot(4,2,1);
plot(x,sin(x))
title('Sine signal:');
ylabel('amplitude');
xlabel('time index');
%<-----Cosine Signal----->
x=0:0.001:10;
subplot(4,2,5);
plot(x,cos(x))
title('Cosine signal:');
ylabel('amplitude');
xlabel('time index');
subplot(4,2,8);
plot(x,cos(x+5));
title('Shifted cosine signal:');
ylabel('amplitude');
xlabel('time index');
figure(2);
%<-----Step Signal----->
t=-5:0.001:5;
x=(t>=0)
subplot(4,2,1);
plot(t,x);
title('Step signal:');
ylabel('amplitude');
xlabel('time index');
xlabel('time index');
%<-----Ramp Signal----->
t=-5:0.001:5;
x=t
subplot(4,2,3);
plot(t,x);
title('Ramp signal:');
ylabel('amplitude');
xlabel('time index');
COMMAND WINDOW:
x=
Columns 1 through 9
-5.0000 -4.9900 -4.9800 -4.9700 -4.9600 -4.9500 -4.9400 -4.9300
-4.9200
Columns 10 through 18
-4.9100 -4.9000 -4.8900 -4.8800 -4.8700 -4.8600 -4.8500 -4.8400
-4.8300
Columns 19 through 27
-4.8200 -4.8100 -4.8000 -4.7900 -4.7800 -4.7700 -4.7600 -4.7500
-4.7400
Columns 28 through 36
-4.7300 -4.7200 -4.7100 -4.7000 -4.6900 -4.6800 -4.6700 -4.6600
-4.6500
FIGURE:
10
11
Experiment NO:-7
Date:-
Program:-2
AIM:- Write a MATLAB code for ENERGY & POWER Signal calculations
MATLAB CODE:%<--------Energy Calculations of Aperiodic siganl(Ramp)------->
%<------Ramp Signal------>
figure(1);
t=-1:0.01:1;
x=t;
subplot(3,1,1);
plot(t,x);
grid;
xlabel('t');
ylabel('x(t)');
12
13
%Energy of X1
grid on;
hold on
% red lines marking 0 & 1
plot([0 0], [-.2 1.2],'g', [1 1], [-.2 1.2],'g');
hold off
axis([-2 2 -.2 1.2]);
title('Squared sines');
xlabel('t');
14
ylabel('x_1^2(t)');
subplot(2,1,2);
stem(n,x2.^2); %Energy of X2
grid on;
hold on;
% red lines marking 1 & 20
plot([1 1], [-.2 1.2],'r', [20 20], [-.2 1.2],'r');
hold off;
axis([-40 40 -.2 1.2]);
xlabel('n');
ylabel('x_2^2(n)');
15
COMMAND WINDOW:
Power, one period:
P2 =0.5000
FIGURE:-
16
17
Experiment NO:-8
Date:-
Program:-3
AIM:- Write a MATLAB code for Auto Co-Relation & Cross Co-Relation
MATLAB CODE:%----------------------------------------clc;
close all;
clear all;
%-------------------------------a=[1 0 2]
b=[1 1 2]
c=xcorr(a,b)
d=xcorr(a,a)
e=xcorr(b,b)
%<-----------Sine Signal----------->
x=0:0.1:25;
subplot(3,2,1);
w=sin(x);
plot(x,w);grid;
title('sine signal is:');
18
ylabel('amplitude');
xlabel('time index');
%<------COSINE SIGNAL---->
subplot(3,2,2);
v=cos(x);
plot(x,v);grid
title('cosine signal is:');
ylabel('amplitude');
xlabel('time index');
%<-----Co-relations of signals----->
subplot(3,2,3);
p=xcorr(w,v)
plot(p);grid;
subplot(3,2,4);
q=xcorr(w,w)
plot(q);grid;
subplot(3,2,5);
r=xcorr(v,v)
plot(r);grid;
19
COMMAND WINDOW:
a= 1 0 2
b=
d=
e=
p=
Columns 1 through 9
-0.0000 0.0990 0.2941 0.5806 0.9519 1.3998
3.0954
1.9142 2.4836
Columns 10 through 18
3.7358 4.3899 5.0426 5.6780 6.2802 6.8334 7.3221 7.7314
8.0475
Columns 19 through 27
8.2572 8.3491 8.3131 8.1409 7.8259 7.3638 6.7524
5.0837
5.9916
20
Columns 28 through 36
q=
Columns 1 through 9
0.0000 -0.0132 -0.0493 -0.1175 -0.2265 -0.3838 -0.5964 -0.8698
-1.2083
Columns 10 through 18
-1.6150 -2.0912 -2.6370 -3.2506 -3.9287 -4.6665 -5.4574 -6.2934
-7.1651
Columns 19 through 27
-8.0616 -8.9709 -9.8800 -10.7748 -11.6407 -12.4625 -13.2248
-13.9121 -14.5089
r=
Columns 1 through 9
0.9912 1.9593 2.8848 3.7488 4.5335 5.2223 5.7998 6.2526
6.5690
Columns 10 through 18
6.7396 6.7572 6.6168 6.3162 5.8554 5.2372 4.4669 3.5524
2.5038
Columns 19 through 27
1.3338 0.0571 -1.3095 -2.7476 -4.2369 -5.7561 -7.2828 -8.7939
-10.2657
21
FIGURE:
22
Experiment NO:-9
Date:-
Program:-4
23
k=0:39;
k=k';
figure(1);
subplot(2,1,1)
stem(k,Dnmag);grid
title('Amplitude spectrum');
ylabel('Dn');
xlabel('w');
subplot(2,1,2)
stem(k,Dnangle);grid
title('Phase spectrum');
ylabel('Angle');
xlabel('w');
c0=Dnmag(1)
% c0=Dnmag(1)=ao
24
k=0:9; % k= 0:length(Amplitudes)-1
k=k';
figure(2);
subplot(2,1,1)
stem(k,Amplitudes);grid;
title('Amplitude spectrum');
ylabel('Cn');
xlabel('w');
subplot(2,1,2)
stem(k,Angles);grid;
title('Phase spectrum');
ylabel('Angle');
xlabel('w');
COMMAND WINDOW:
Dn =
0.5043
0.0297 - 0.1184i
0.0078 - 0.0615i
0.0035 - 0.0410i
0.0020 - 0.0304i
0.0013 - 0.0238i
0.0009 - 0.0194i
0.0007 - 0.0161i
0.0006 - 0.0136i
0.0005 - 0.0116i
0.0004 - 0.0099i
25
0.0003 - 0.0085i
0.0003 - 0.0072i
0.0003 - 0.0061i
0.0002 - 0.0050i
0.0002 - 0.0041i
0.0002 - 0.0032i
0.0002 - 0.0024i
0.0002 - 0.0016i
0.0002 - 0.0008i
0.0002
0.0002 + 0.0008i
0.0002 + 0.0016i
0.0002 + 0.0024i
0.0002 + 0.0032i
0.0002 + 0.0041i
0.0002 + 0.0050i
0.0003 + 0.0061i
0.0003 + 0.0072i
0.0003 + 0.0085i
0.0004 + 0.0099i
0.0005 + 0.0116i
0.0006 + 0.0136i
0.0007 + 0.0161i
0.0009 + 0.0194i
0.0013 + 0.0238i
0.0020 + 0.0304i
0.0035 + 0.0410i
0.0078 + 0.0615i
0.0297 + 0.1184i
c0 =
0.5043
26
Amplitudes =
0.5043
0.2441
0.1241
0.0822
0.0608
0.0478
0.0388
0.0323
0.0272
0.0232
Angles =
0
-75.9040
-82.7544
-85.0529
-86.1739
-86.8169
-87.2159
-87.4704
-87.6286
-87.7151
27
FIGURE:
28
29
Experiment NO:-10
Date:-
Program:-5
AIM:- Write a MATLAB code for finding Fourier Transform of e(-2t) *u(t)
MATLAB CODE:% Fourier transform of e^(-2t)*u(t)
%----------------------------------------clc;
close all;
clear all;
%-------------------------------Ts=1/12;
T0=3;
N0=T0/Ts;
t=0:Ts:Ts*(N0-1);
t=t';
g=Ts*exp(-2*t);
g(1)=Ts*0.5;
G=fft(g)
[Gp,Gm]=cart2pol(real(G),imag(G))
k=0:N0-1;
%k=k';
w=2*pi*k/T0;
30
subplot(2,1,1);
stem(w(1:32),Gm(1:32));
title('Amplitude Spectrum');
ylabel('|G(w)|');
xlabel('w');
subplot(2,1,2);
stem(w(1:32),Gp(1:32))
title('Phase spectrum');
ylabel('Angle');
xlabel('w');
COMMAND WINDOW:
G=
0.4998
0.2389 - 0.2479i
0.0937 - 0.1915i
0.0470 - 0.1405i
0.0280 - 0.1078i
0.0186 - 0.0858i
0.0134 - 0.0700i
0.0103 - 0.0581i
0.0082 - 0.0487i
0.0068 - 0.0410i
0.0058 - 0.0345i
0.0050 - 0.0288i
0.0045 - 0.0238i
0.0041 - 0.0192i
0.0038 - 0.0150i
31
0.0036 - 0.0111i
0.0035 - 0.0073i
0.0034 - 0.0036i
0.0034
0.0034 + 0.0036i
0.0035 + 0.0073i
0.0036 + 0.0111i
0.0038 + 0.0150i
0.0041 + 0.0192i
0.0045 + 0.0238i
0.0050 + 0.0288i
0.0058 + 0.0345i
0.0068 + 0.0410i
0.0082 + 0.0487i
0.0103 + 0.0581i
0.0134 + 0.0700i
0.0186 + 0.0858i
0.0280 + 0.1078i
0.0470 + 0.1405i
0.0937 + 0.1915i
0.2389 + 0.2479i
Gp =
0
-0.8038
-1.1160
-1.2483
-1.3169
-1.3568
-1.3812
-1.3962
-1.4044
-1.4073
-1.4053
32
-1.3979
-1.3840
-1.3607
-1.3224
-1.2561
-1.1270
-0.8186
0
0.8186
1.1270
1.2561
1.3224
1.3607
1.3840
1.3979
1.4053
1.4073
1.4044
1.3962
1.3812
1.3568
1.3169
1.2483
1.1160
0.8038
Gm =
0.4998
0.3443
0.2132
0.1482
0.1114
0.0878
0.0713
33
0.0590
0.0494
0.0415
0.0349
0.0292
0.0242
0.0197
0.0155
0.0116
0.0081
0.0049
0.0034
0.0049
0.0081
0.0116
0.0155
0.0197
0.0242
0.0292
0.0349
0.0415
0.0494
0.0590
0.0713
0.0878
0.1114
0.1482
0.2132
0.3443
34
FIGURE:
35