Вы находитесь на странице: 1из 25

EXPERIMENT 1

AIM - Construct a sinc function by picking its samples at the Nyquist rate and plot its
spectrum. Increase and decrease the width of the sinc function and observe the
spectrum. Increase and decrease the sampling rate and observe the spectrum.
PROGRAM CODE
clc;
clear all;
close all;
n=1:100;
y1= sinc((n-50)*0.1);
y_1= fft(y1);
figure;
subplot(2,2,1);
plot(n,fftshift(abs(y_1)));
grid;
title('Fourier transform vs n with sample frequency 10f');
ylabel('Fourier transform');
xlabel('n');
y2= sinc((n-50)*2);
y_2= fft(y2);
subplot(2,2,2);
plot(n,fftshift(abs(y_2)));
grid;
title('Fourier transform vs n with sample frequency f/2');
ylabel('Fourier transform');
xlabel('n');
y3= sinc((n-50)*0.2);
y_3= fft(y3);
subplot(2,2,3);
plot(n,fftshift(abs(y_3)));
grid;
title('Fourier transform vs n with sample frequency 5f');
ylabel('Fourier transform');
xlabel('n');
y4= sinc((n-50)*0.5);
y_4= fft(y4);
subplot(2,2,4);
plot(n,fftshift(abs(y_4)));
grid;
title('Fourier transform vs n with sample frequency 2f');
ylabel('Fourier transform');
xlabel('n');

figure;
subplot(2,2,1);
plot(ifft(y_1));
grid;
title('sinc reconstructed from sampled values(sample frequency 10f)');
xlabel('t');
ylabel('sinc');
subplot(2,2,2);
plot(ifft(y_2));
grid;
title('sinc reconstructed from sampled values(sample frequency f/2)');
xlabel('t');
ylabel('sinc');
subplot(2,2,3);
plot(ifft(y_3));
grid;
title('sinc reconstructed from sampled values(sample frequency 5f)');
xlabel('t');
ylabel('sinc');
subplot(2,2,4);
plot(ifft(y_4));
grid;
title('sinc reconstructed from sampled values(sample frequency 2f)');
xlabel('t');
ylabel('sinc');

OUTPUTS

EXPERIMENT 2
AIM To verify the following properties of Discrete Fourier Transform
1. Convolution
2. Time Shifting
3. Frequency Shifting
PROGRAM CODE
clc;
clear all;
close all;
N=64;
J=10;
K=20;
L=20;
M=10;
X1=[zeros(1,J),ones(1,N-J-K),zeros(1,K)]; % generating 1st rectangular
pulse
X2=[zeros(1,L),ones(1,N-L-M),zeros(1,M)]; % generating 2nd pulse
% property of convolution
DFTX1=fft(X1,128);
DFTX2=fft(X2,128);
for n=1:128
DFTY(n)=DFTX1(n)*DFTX2(n);
end;
Y=abs(ifft(DFTY));
Y_conv=conv(X1,X2);
figure;
subplot(2,2,1);
stem(X1);
grid;
title('X1');
xlabel('n');
ylabel('X1');
subplot(2,2,2);
stem(X2);
grid;
title('X2');
xlabel('n');
ylabel('X2');
subplot(2,2,3);
stem(Y);

grid;
title('Signal using frequency domain multiplication');
xlabel('n');
ylabel('Y');
subplot(2,2,4);
stem(Y_conv);
grid;
title('Signal after convolution');
xlabel('n');
ylabel('Y_conv');
% time shifting
P=128;
G=8;
for n=1:128
DFTY1(n)= DFTX1(n)*exp(G*j*(2*pi/P)*n);
End
Y1=abs(ifft(DFTY1));
figure;
subplot(2,1,1);
stem(X1);
grid;
title('X1');
xlabel('n');
ylabel('X1');
subplot(2,1,2);
stem(Y1);
grid;
title('X1 shifted');
xlabel('n');
ylabel('IFFT of DFTY1');
% frequency shifting
H=64;
for n=1:64
X3(n)=X1(n).*exp(H*j*(2*pi/P)*n);
end
for nn=1:P
XX(nn)=2*pi*nn/P;
end
DFTX3= fft(X3,128);

figure;
subplot(2,1,1);
plot(XX,abs(fft(X1,128)));
grid;
title('Fourier transform of X1');
xlabel('n');
ylabel('Fourier transform of X1');
subplot(2,1,2);
plot(XX,abs(DFTX3));
grid;
title('Fourier transform of X3');
xlabel('n');
ylabel('Fourier transform of X3');

OUTPUTS

Convolution Property

Time Shifting Property

Frequency Shifting Property

EXPERIMENT 3
AIM 1.To plot and verify the pdf of uniform and Gaussian random variable.
2. To plot and verify the pdf of speech samples.
3. Compute the mean and variance of the above random variable.
PROGRAM CODE
clc;
clear all;
close all;
N= 4500000;
M=40;
X= randn(1,N);
xmin= min(X);
xmax= max(X);
d= (xmax-xmin)/M;
fx= hist(X,M)/(N*d);
for x=1:1:M
xxs(x)= xmin+(x-1)*d;
end
for i=1:1:M
fx1(i)=(exp((-1/2)*(xxs(i).*xxs(i))))/sqrt(2*pi);
end
figure;
plot(xxs,fx,'-ro',xxs,fx1,'-.b');
grid;
xlabel('x');
ylabel('Probability Density Function');
title('Probability Density Function');
fxleg= legend('Practical','Theoretical');

OUTPUT

>> mean(fx)
ans =
0.0978
>> mean(fx1)
ans =
0.0978
>> var(fx)
ans =
0.0184
>> var(fx1)
ans =
0.0185
>>

EXPERIMENT 4
AIM 1. Compute the mean and variance of the above random variable.
2. Verify the properties of the expectation operator.
3. Generate uniform and Gaussian random numbers with desired mean and
variance.

PROGRAM CODE
1.
clc;
clear all;
close all;
N=50000;
a= 2;
X=randn(1,N);
for x=1:1:N
b(x)= 4;
end
Y= a*X+ b;
meanx= 0.5;
meany= b(1);
meany_1= mean(Y);
vary= a*a;
vary_1= var(Y);

OUTPUT
>> meany

meany =

>> meany_1

meany_1 =

4.0061

>> vary

vary =

>> vary_1

vary_1 =

3.9777

2.
clear all;
close all;
clc;
N= 50000;
a= 2;
X= rand(1,N);
for x=1:1:N
b(x)= 4;
end
Y= a*X+ b;
meany= mean(Y);
sum=0;
for i=1:1:N
sum= sum+ Y(i);
end
meany_1=sum/N;

OUTPUT
>> meany
meany =
5.0007
>> meany_1
meany_1 =
5.0007
>>

3.
clc;
clear all;
close all;
N=50000;
a= 2;
X=rand(1,N);
for x=1:1:N
b(x)= 4;
end
Y= a*X+ b;
meanx= 0.5;
meany= (a*0.5)+ b(1);
meany_1= mean(Y);
vary= (a*a)/12;
vary_1= var(Y);

OUTPUT
>> meany
meany =
5
>> meany_1
meany_1 =
5.0016
>> vary
vary =
0.3333
>> vary_1
vary_1 =
0.3325
>>

EXPERIMENT 5
AIM 1. To plot the pdf of sum of two random variables and verify the result
2. To verify that the sum of two Gaussian random variable is also Gaussian
3. To verify the central limit theorem
PROGRAM CODE
1.
clc;
clear all;
close all;
N= 500000;
M=50;
X=rand(1,N);
Y= rand(1,N);
Z= X+Y;
zmin= min(Z);
zmax= max(Z);
xmin= min(X);
xmax= max(X);
ymin= min(Y);
ymax= max(Y);
dz=(zmax-zmin)/M;
dx=(xmax-xmin)/M;
dy=(ymax-ymin)/M;
fz=hist(Z,M)/(N*dz);
for i=1:1:M
xxs(i)= zmin+(i-1)*dz;
end
for i=1:1:1000
n(i)= (i-1)*(2/1000);
end
for i1=1:1:500
fxy(i1)= n(i1);
end

for i2= 500:1:1000


fxy(i2)= 2-(n(i2));
end
% plot(fx,n);
figure;
plot(xxs,fz,'-ro',n,fxy,'-.b');
grid;
fxleg= legend('fz','fx*fy');
xlabel('n');
ylabel('fz');
1.4
fz
fx*fy
1.2

0.8

0.6

0.4

0.2

2.
clc;

0.2

0.4

0.6

0.8

1.2

1.4

1.6

1.8

clear all;
close all;
N= 500000;
M=50;
p=2;
q=4;
X=randn(1,N);
Y= randn(1,N);
Z= p*X+q*Y;
zmin= min(Z);
zmax= max(Z);
xmin= min(X);
xmax= max(X);
ymin= min(Y);
ymax= max(Y);
dz=(zmax-zmin)/M;
dx=(xmax-xmin)/M;
dy=(ymax-ymin)/M;
fz=hist(Z,M)/(N*dz);
for i=1:1:M
xxs(i)= zmin+(i-1)*dz;
end
varx= var(X);
vary= var(Y);
varz_t= (varx)*(varx)*p*p+(vary)*(vary)*q*q;
meanx= mean(X);
meany= mean(Y);
meanz_t= meanx*p+meany*q;
figure;
plot(xxs,fz,'-ro');
grid;
xlabel('x');
ylabel('fz');
title('Sum of two Gaussian Random Variables');

Sum of two Gaussian Random Variables


0.09

0.08

0.07

0.06

fz

0.05

0.04

0.03

0.02

0.01

0
-25

>> mean(Z)
ans =
0.0073
>> meanz_t
meanz_t =
0.0073
>> var(Z)
ans =
19.9786
>> varz_t
varz_t =

-20

-15

-10

-5

0
x

10

15

20

25

19.9846
>>
3.
clc;
clear all;
close all;
N= 50000;
M=50;
X1=
X2=
X3=
X4=

rand(1,N);
rand(1,N);
rand(1,N);
rand(1,N);

meanx1=
meanx2=
meanx3=
meanx4=

mean(X1);
mean(X2);
mean(X3);
mean(X4);

for i1=1:1:N
X11(1,i1)=X1(1,i1)X21(1,i1)=X2(1,i1)X31(1,i1)=X3(1,i1)X41(1,i1)=X4(1,i1)end

meanx1;
meanx2;
meanx3;
meanx4;

Z=(X11+X21+X31+X41)/2;
zmin= min(Z);
zmax= max(Z);
dz=(zmax-zmin)/M;
fz=hist(Z,M)/(N*dz);
for i=1:1:M
xxs(i)= zmin+(i-1)*dz;
end
figure;
plot(xxs,fz,'-ro');
grid;
xlabel('x');
ylabel('fz');
title('Central limit Theorem');

EXPERIMENT 6
QUESTION NO.1: To check if the given process is wide-sense stationary or not, Y(n) = An,
where A: U [0,1]
MATLAB CODE:clear all;
close all;
clc;
A = rand(1,1000);
Y = zeros(1000,5);
for k = 1:1:5
for n = 1:1:1000
Y(n,k) = (k.*A(n)).';
end
end
mean_y1 = sum(Y,1);
mean_y = mean_y1./1000
R = zeros(5,5);
for n = 1:1:5
for k = 1:1:5
R(n,k) = mean(Y(:,n).*Y(:,k));
end
end
Ryy = R

Output:
mean_y =

0.5006 1.0011 1.5017 2.0022 2.5028

Ryy = 0.3362 0.6724 1.0086 1.3448

1.6810

0.6724 1.3448 2.0172 2.6896 3.3620


1.0086 2.0172 3.0258 4.0344 5.0430
1.3448 2.6896 4.0344 5.3792 6.7240
1.6810 3.3620 5.0430 6.7240 8.4050

As can be observed neither the mean is constant nor the diagonal elements in the correlation
matrix hence we conclude that this is not a wide sense stationary process.
QUESTION NO.2: To check if the given process is wide-sense stationary or not, Z(n) =
cos(2fn + ), where :U[-, ]
MATLAB CODE:clear all;
close all;
clc;
a = 10;
A1 = rand(1,1000);
A = (2*pi*A1)-pi;
Z = zeros(1000,a);
for k = 1:1:a
for n = 1:1:1000
Z(n,k) = (cos((k*(1/5))+A(n))).';
end
end
mean_z1 = sum(Z,1);
mean_z = mean_z1./1000
R = zeros(a,a);
for n = 1:1:a
for k = 1:1:a
R(n,k) = mean(Z(:,n).*Z(:,k));
end
end
Rzz = R

Output:
mean_y =
0.0106 0.0088 0.0066 0.0042 0.0016 -0.0010 -0.0036 -0.0061 -0.0083 -0.0102

Z=
0.4992
0.4896
0.4604
0.4129

0.4896
0.4999
0.4903
0.4612

0.4604
0.4903
0.5006
0.4910

0.4129
0.4612
0.4910
0.5012

0.3490
0.4136
0.4618
0.4915

0.2711
0.3496
0.4141
0.4622

0.1824
0.2716
0.3500
0.4144

0.0865
0.1828
0.2719
0.3502

-0.0129
0.0868
0.1830
0.2719

-0.1118
-0.0128
0.0868
0.1829

0.3490
0.2711
0.1824
0.0865
-0.0129
-0.1118

0.4136
0.3496
0.2716
0.1828
0.0868
-0.0128

0.4618
0.4141
0.3500
0.2719
0.1830
0.0868

0.4915
0.4622
0.4144
0.3502
0.2719
0.1829

0.5017
0.4918
0.4623
0.4145
0.3500
0.2717

0.4918
0.5018
0.4918
0.4622
0.4142
0.3496

0.4623
0.4918
0.5017
0.4915
0.4618
0.4137

0.4145
0.4622
0.4915
0.5013
0.4910
0.4612

0.3500
0.4142
0.4618
0.4910
0.5007
0.4904

0.2717
0.3496
0.4137
0.4612
0.4904
0.5000

As the mean is constant and the diagonal elements in the correlation matrix are also constant
within experimental error limits hence the process is wide sense stationary.
QUESTION NO.3: To check if the given process is wide-sense stationary or not, P(n) =
Acos(2fn), where A:U[-0.5, 0.5]
MATLAB CODE:clear all;
close all;
clc;
a = 10;
A1 = rand(1,1000);
A = (1*A1)-0.5;
P = zeros(1000,a);
for k = 1:1:a
for n = 1:1:1000
P(n,k) = (A(n)*(cos(2*pi*(1/5)*k))).';
end
end
mean_p1 = sum(P,1);
mean_p = mean_p1./1000
R = zeros(a,a);
for n = 1:1:a
for k = 1:1:a
R(n,k) = mean(P(:,n).*P(:,k));
end
end
Rpp = R
Output:
mean_p=
-0.0017

Rpp =

0.0045 0.0045 -0.0017 -0.0055 -0.0017 0.0045 0.0045 -0.0017 -0.0055

0.0080
-0.0209
-0.0209
0.0080
0.0259
0.0080
-0.0209
-0.0209
0.0080
0.0259

-0.0209
0.0548
0.0548
-0.0209
-0.0678
-0.0209
0.0548
0.0548
-0.0209
-0.0678

-0.0209
0.0548
0.0548
-0.0209
-0.0678
-0.0209
0.0548
0.0548
-0.0209
-0.0678

0.0080
-0.0209
-0.0209
0.0080
0.0259
0.0080
-0.0209
-0.0209
0.0080
0.0259

0.0259
-0.0678
-0.0678
0.0259
0.0838
0.0259
-0.0678
-0.0678
0.0259
0.0838

0.0080
-0.0209
-0.0209
0.0080
0.0259
0.0080
-0.0209
-0.0209
0.0080
0.0259

-0.0209
0.0548
0.0548
-0.0209
-0.0678
-0.0209
0.0548
0.0548
-0.0209
-0.0678

-0.0209
0.0548
0.0548
-0.0209
-0.0678
-0.0209
0.0548
0.0548
-0.0209
-0.0678

0.0080
-0.0209
-0.0209
0.0080
0.0259
0.0080
-0.0209
-0.0209
0.0080
0.0259

0.0259
-0.0678
-0.0678
0.0259
0.0838
0.0259
-0.0678
-0.0678
0.0259
0.0838

As the mean values arent constant but repeat after time period T = 5 and the diagonal elements follow the
same pattern i.e. repeat after interval of 5 (as we took f = (1/5)) hence this process is not wide sense
stationary but it is cyclo-stationary with a time period of 5.

Вам также может понравиться