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

1

Addis Ababa University


Addis Ababa Institute of Technology
Electrical and computer engineering Department

ECEG 6306 Statistical Digital Signal Processing

Homework Number one

Submitted by: Fitsum Mergia


(GSE/1096/03)
Submitted to: Dr Eneyew

Experiment-one
1.
Random number samples block with Gaussian
distribution :
=1.0 =1.0 (# First half Samples=1000)
%*****************************************************
%Question Number-1
%*****************************************************
N=2000;
%Total Sample Size
X=1+randn(1,N/2);
%First half of Sample m=1 o=1
Y=1.5+0.5*randn(1,N/2);
%Second half of sample m=1.5 o=0.5
subplot(1,2,1);
histfit(X);
title('The First Sample block plot ');
xlabel('Sample');
ylabel('Weight');
grid();
subplot(1,2,2);
histfit(Y);
title('The Second Sample block plot');
grid();
xlabel('Sample');
ylabel('Weight');

=1.5

=0.5 (# Second Half Samples=1000)

DATA STATISTICS FOR THE FIRST SAMPLE BLOCK

Data -1

(Sample Data statistics


of the first
block )

Data -2

(statistics the ideal Gaussian


distribution)

DATA STATISTICS FOR THE FIRST SAMPLE BLOCK

Data -3

(Sample Data statistics


of the Second
block )

Data -4

(statistics the ideal Gaussian


distribution)

2. Estimation of the mean and the second moment using Time-average


approximation and Least-square approximations Method recursively
Estimation of Mean

%**************************************************************************
% Question Number -Two
%( Estimatation of Mean using Time-average and Least-square method)
%**************************************************************************
clf;
%clear figure
l=0.995;
%forgetting factor for the Least-square approximation
N=2000;
%Sample Size
n=1:1:N/2;
%Sample points
X=1+randn(1,N/2);
%First half of Sample M=1 o=1
%*********************Time-Average approximation****************************
M=zeros(1,N/2);
M(1)=X(1);
for i=2:N/2
M(i)= M(i-1)+((X(i)-M(i-1))/(i+1));
end
%*********************Least-square approximation****************************
m=zeros(1,N/2);
m(1)=X(1);
for j=2:N/2
m(j)=m(j-1)+((1-l)*(X(j)-m(j-1)));
end;
%********************* plot **********************************************
plot(n,m,n,M);
legend('Least-Square approximation','Time-Average
approximaton','Location','SouthEast');
title('Estimation of Mean using *Time-average* and * Least-Square* Method Plot');
xlabel('Number of Sample points- [n] ');
ylabel('Mean Estimate- [ M(n)]');
grid();

Estimation of Second Moment:


%**************************************************************************
% Question Number -Two
%( Estimatation of Second moment using Time-average and Least-square method)
%**************************************************************************
clf;
%clear figure
l=0.995;
%forgetting factor for the Least-square appr
N=2000;
%Sample Size
n=1:1:N/2;
%Sample points
X=1+randn(1,N/2);
%First half of Sample M=1 o=1
%%%%%%%%%%%%%%%%%-----Time-Average approximation-----%%%%%%%%%%%%%%%%%%%%%%
S=zeros(1,N/2);
S(1)=X(1);
for i=2:N/2
S(i)= S(i-1)+(((X(i)^2)-(S(i-1)^2))/(i+1));
end
%%%%%%%%%%%%%%%%%%----Least-square approximation------%%%%%%%%%%%%%%%%%%%%%
s=zeros(1,N/2);
s(1)=X(1);
for j=2:N/2
s(j)=s(j-1)+((1-l)*((X(j)^2)-(s(j-1)^2)));
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%----plot-------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
plot(n,s,n,S);
legend('Least-Square approximation','Time-Average
approximaton','Location','SouthEast');
title('Estimation of Second moment using *Time-average* and * Least-Square* Method
Plot');
xlabel('Number of Sample points- [n] ');
ylabel('Second Moment Estimate- [ S(n)]');
grid();

Observation: The estimation from Least-Square and Time-average


approximation converges to the theoretical value for both Mean and second
moment estimation.

3.

Compare for the different lamda

%**************************************************************************
% Question Number -Three
%**************************************************************************
clf;
%clear figure
N=2000;
%Sample Size
n=1:1:N/2;
%Sample points
X=1+randn(1,N/2);
%First half of Sample M=1 o=1
%************************Time-Average approximation************************
M=zeros(1,N/2);
M(1)=X(1);
for i=2:N/2
M(i)= M(i-1)+((X(i)-M(i-1))/(i+1));
end
%********************Least-square approximation****************************
l=0.99;
m1=zeros(1,N/2);
m1(1)=X(1);
for j=2:N/2
m1(j)=m1(j-1)+((1-l)*(X(j)-m1(j-1)));
end;
%********************Least-square approximation****************************
k=0.98;
m2=zeros(1,N/2);
m2(1)=X(1);
for j=2:N/2
m2(j)=m2(j-1)+((1-k)*(X(j)-m2(j-1)));
end;
%*************************plot-1 *****************************************
subplot(1,2,1,'red');
plot(n,m1,n,M);
title('for lamda=0.99');
xlabel('[n] ');
ylabel('[ M(n)]');
grid();
%*************************plot-2 *****************************************
subplot(1,2,2,'red');
plot(n,m2,n,M);
title('for lamda =0.98');
xlabel('[n] ');
ylabel('[ M(n)]');
grid();

Observation: the estimate from time average approximation


converges to the ideal mean value more rapidly than the least
square approximation. Moreover the transient for the least
square approximation is wider than the time average
approximation.

8
%**************************************************************************
% Question Number -Three)
%**************************************************************************
clf;
%clear figure
N=2000;
%Sample Size
n=1:1:N/2;
%Sample points
X=1+randn(1,N/2);
%First half of Sample M=1 o=1
%%%%%%%%%%%%%%%%%-----Time-Average approximation-----%%%%%%%%%%%%%%%%%%%%%%
S=zeros(1,N/2);
S(1)=X(1);
for i=2:N/2
S(i)= S(i-1)+(((X(i)^2)-(S(i-1)^2))/(i+1));
end
%%%%%%%%%%%%%%%%%%----Least-square approximation------%%%%%%%%%%%%%%%%%%%%%
k=0.99;
%forgetting factor for the Least-square appr
s2=zeros(1,N/2);
s2(1)=X(1);
for j=2:N/2
s2(j)=s2(j-1)+((1-k)*((X(j)^2)-(s2(j-1)^2)));
end;
%%%%%%%%%%%%%%%%%%----Least-square approximation------%%%%%%%%%%%%%%%%%%%%%
t=0.98;
%forgetting factor for the Least-square appr
s3=zeros(1,N/2);
s3(1)=X(1);
for j=2:N/2
s3(j)=s3(j-1)+((1-t)*((X(j)^2)-(s3(j-1)^2)));
end;
%**************************
plot-1
*******************************
subplot(1,2,1);
plot(n,s2,n,S);
title('for lamda=0.99 ');
xlabel(' [n] ');
ylabel(' [ S(n)]');
grid();
%**************************
plot-2
*******************************
subplot(1,2,2);
plot(n,s3,n,S);
title('for lamda=0.98 ');
xlabel(' [n] ');
ylabel(' [ S(n)]');
grid();

Observation: the estimate from time average approximation


converges to the ideal second moment value more rapidly than
the least square approximation. Moreover the transient for the
least square approximation is wider than the time average
approximation.

4. The variance for the sample block


9

10

%**************************************************************************
%For the First half of the sample
For lamda=0.99
%**************************************************************************
N=2000;
%Sample Size
X=1+randn(1,N/2);
%First half of Sample m=1 o=1
Y=1.5+0.5*randn(1,N/2);
%Second half of sample m=1.5 o=0.5
%***********************Least-square approximation*************************
l=0.99;
m=zeros(1,N/2);
m(1)=X(1);
for j=2:N/2
m(j)=m(j-1)+((1-l)*(X(j)-m(j-1)));
end;
h=zeros(1,N/2);
OUT-PUT SCREEN
h(1)=(((m(1)-1)^2)/N/2);
for i=2:N/2
> 3.9062e-006
h(i)=((h(i-1)+((m(i)-1)^2))/N/2);
end
h(N/2)

%**************************************************************************
%For the First half of the sample
For lamda=0.98
%**************************************************************************
N=2000;
%Sample Size
X=1+randn(1,N/2);
%First half of Sample m=1 o=1
Y=1.5+0.5*randn(1,N/2);
%Second half of sample m=1.5 o=0.5
%***********************Least-square approximation*************************
l=0.98;
m=zeros(1,N/2);
m(1)=X(1);
for j=2:N/2
m(j)=m(j-1)+((1-l)*(X(j)-m(j-1)));
end;
h=zeros(1,N/2);
OUT-PUT SCREEN
h(1)=(((m(1)-1)^2)/N/2);
for i=2:N/2
> 6.3940e-008
h(i)=((h(i-1)+((m(i)-1)^2))/N/2);
end
h(N/2)

10

11

The theoretical value [ var = 2 (1- )/(1+ )]


=0.98

=0.99

var=0.01010101
var=5.025125x10-3

%**************************************************************************
%For the Second half of the sample
For lamda=0.99
%**************************************************************************
N=2000;
%Sample Size
X=1+randn(1,N/2);
%First half of Sample m=1 o=1
Y=1.5+0.5*randn(1,N/2);
%Second half of sample m=1.5 o=0.5
%***********************Least-square approximation*************************
l=0.99;
m=zeros(1,N/2);
m(1)=X(1);
for j=2:N/2
m(j)=m(j-1)+((1-l)*(X(j)-m(j-1)));
end;
OUT-PUT SCREEN
h=zeros(1,N/2);
h(1)=(((m(1)-1)^2)/N/2);
> 6.1146e-005
for i=2:N/2
h(i)=((h(i-1)+((m(i)-1)^2))/N/2);
end
h(N/2)

%**************************************************************************
%For the Second half of the sample
For lamda=0.98
%**************************************************************************
N=2000;
%Sample Size
X=1+randn(1,N/2);
%First half of Sample m=1 o=1
Y=1.5+0.5*randn(1,N/2);
%Second half of sample m=1.5 o=0.5
%***********************Least-square approximation*************************
l=0.98;
m=zeros(1,N/2);
m(1)=X(1);
for j=2:N/2
m(j)=m(j-1)+((1-l)*(X(j)-m(j-1)));
end;
h=zeros(1,N/2);
h(1)=(((m(1)-1)^2)/N/2);
11
for i=2:N/2
h(i)=((h(i-1)+((m(i)-1)^2))/N/2);
end
h(N/2)

12

OUT-PUT SCREEN
> 5.2793e-005

The theoretical value [ var = 2 (1- )/(1+ )]

=0.98

var=2.5252525 x 10-3

=0.99

var=1.25628125x10-3

Experiment-two
1. Generate 300 samples
%**************************************************************************
%Experiement-two
%**************************************************************************
N=300;
%total number of samples
n1=0:74;
n2=75:224;
n3=225:300;
s1=20+(0.8.*n1);
s2=80-(0.2.*(n2-75));
s3=50+(0.2.*(n3-225));
x1=s1+(5*randn(1,75));
%the first sample data with S1
x2=s2+(5*randn(1,150));
%the Second sample data with S2
x3=s3+(5*randn(1,76));
%the third Sample data with S3
plot(n1,x1,n2,x2,n3,x3,n1,s1,n2,s2,n3,s3);
grid();
xlabel('[n]');
ylabel('[Sample values]');
title('Sample Data plot [ Xn=Sn+Vn ]');

12

13

2.

13

14

14

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