Skip to content

Commit c4a5918

Browse files
authored
Add files via upload
1 parent cebe3ee commit c4a5918

21 files changed

+587
-0
lines changed

CRLB.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
clc
2+
clear all
3+
close all
4+
%% y(t) = m + n(t) t= 1,....,N
5+
est_m = zeros(1,1000);
6+
var_est_m = zeros(1,10);
7+
i = 1;
8+
N = 1000;
9+
CRLB = zeros(1,10);
10+
for v = 1:1:10
11+
for mc = 1:1000
12+
m = 5; %%choose m = 5
13+
n = v * randn(1,N);
14+
y = m + n;
15+
y = y';
16+
%plot(y)
17+
%% Creating a Maximum Likelihood Estimator
18+
est_m(mc) = (1/(N-1))*sum(y);
19+
end
20+
exp_est_m = sum(est_m)/mc;
21+
%%calculating the variance of
22+
var_est_m(i) = (sum((est_m - exp_est_m).^2))/mc;
23+
CRLB(i) = var(y)/N;
24+
i = i+1;
25+
26+
end
27+
plot(1:1:10,var_est_m);
28+
title('plot of var(mˆML), for N=1000 constant and sigma^2 changing')
29+
ylabel('var(mˆML)')
30+
xlabel('sigma^2')
31+
hold on
32+
plot(1:1:10,CRLB);

CRLB_vs_variance_plot.m

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
clc
2+
clear all
3+
close all
4+
%% y(t) = m + n(t) t= 1,....,N
5+
est_m = zeros(1,1000);
6+
var_est_m = zeros(1,10);
7+
i = 1;
8+
N = 1000;
9+
CRLB = zeros(1,10);
10+
for v = 1:1:10
11+
for mc = 1:1000
12+
m = 5; %%choose m = 5
13+
n = v .* randn(1,N);
14+
y = m + n;
15+
y = y';
16+
%plot(y)
17+
%% Creating a Maximum Likelihood Estimator
18+
est_m(mc) = (1/(N))*sum(y);
19+
end
20+
%% expectation of the Maximum Likelihood Estimator
21+
exp_est_m = sum(est_m)/mc;
22+
%%calculating the variance of
23+
var_est_m(i) = (sum((est_m - exp_est_m).^2))/mc;
24+
CRLB(i) = v/N;
25+
i = i+1;
26+
27+
end
28+
plot((1:1:10).^2,var_est_m);
29+
title('Comparing the CRLB to the variance')
30+
ylabel('var(mˆML)')
31+
xlabel('sigma^2')
32+
hold on
33+
plot((1:1:10).^2,CRLB,'r-');
34+
legend('var(mˆML)','CRLB');

Central_Limit_Theorem.m

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
clc
2+
clear all
3+
close all
4+
%%Central Limit Theorem
5+
S = zeros(1,1000); %%declaring vector S
6+
for j = 1:1000
7+
N = 10; %%value of N
8+
a = -1;
9+
b = 1;
10+
ni = a+(b-a)*rand(1,N); %%generating ni for size N
11+
S(j) = sum(ni); %%summing ni and storing in S
12+
end
13+
subplot(3,1,1)
14+
hist(S);
15+
title('Approximate pdf of Sj for size N = 10');
16+
ylabel('Frequency')
17+
xlabel('values of Sj')
18+
19+
%% Repeated for N = 1000
20+
for j = 1:1000
21+
N = 1000; %%value of N
22+
a = -1;
23+
b = 1;
24+
ni = a+(b-a)*rand(1,N); %%generating ni for size N
25+
S(j) = sum(ni); %%summing ni and storing in S
26+
end
27+
subplot(3,1,2)
28+
hist(S);
29+
title('Approximate pdf of Sj for size N = 10000');
30+
ylabel('Frequency')
31+
xlabel('values of Sj')
32+
33+
%% Repeated for size N = 100000
34+
for j = 1:1000
35+
N = 100000; %%value of N
36+
a = -1;
37+
b = 1;
38+
ni = a+(b-a)*rand(1,N); %%generating ni for size N
39+
S(j) = sum(ni); %%summing ni and storing in S
40+
end
41+
subplot(3,1,3)
42+
hist(S);
43+
title('Approximate pdf of Sj for size N = 100000');
44+
ylabel('Frequency')
45+
xlabel('values of Sj')

Least_square_criterion.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
clc
2+
clear all
3+
close all
4+
%% y (t) = a1 sin(2?f0t) + a2 sin(2?f1t) + n(t), t= 1,....,N
5+
a1 = 1;
6+
a2 = 1;
7+
f0 = 0.25;
8+
f1 = 0.4;
9+
standard_deviation = 1;
10+
m = 5; %%choose m = 5
11+
N = 10000;
12+
t = 1:1:N;
13+
n = standard_deviation .* randn(1,N);
14+
y = (a1.*sin(2*pi*f0.*t)) + (a2.*sin(2*pi*f1.*t)) + n;
15+
y = y';
16+
J = (y - (a1.*sin(2*pi*f0.*t')) - (a2.*sin(2*pi*f1.*t')));
17+
J = J.^2;
18+
J1 = sum(J);
19+
disp(J1);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
clc
2+
close all
3+
%% y (t) = a1 sin(2?f0t) + a2 sin(2?f1t) + n(t), t= 1,....,N
4+
%% plotting the Least square criterion as a function of fo with fixed variance
5+
a1 = 1;
6+
a2 = 1;
7+
i = 1;
8+
J1 = zeros(length(0:0.01:0.5),1);
9+
for f0 = 0:0.01:0.5
10+
J = (y - (a1.*sin(2*pi*f0.*t')) - (a2.*sin(2*pi*f1.*t'))).^2;
11+
J = sum(J);
12+
J1(i) = J;
13+
i = i+1;
14+
end
15+
plot(0:0.01:0.5,J1);
16+
title('Plot of J as a function of fo for a1 = 1 and a2 = 1')
17+
ylabel('magnitude of J')
18+
xlabel('values of fo')
19+
[f0_value,J_value] = ginput(1); %picking the minimum coordinates
20+
disp('minimum coordinate of J as picked by manually by ginput() is')
21+
disp(['value for f0 = ' num2str(f0_value)])
22+
disp(['at J = ' num2str(J_value)])
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
%% a1 and a2 must be set to one in Least_square_criterion.m
2+
%% a1=a2=1 and variance constant, this code plot J(fo,f1) vs fo, f1 in a 3D plot
3+
clc
4+
close all
5+
%% y (t) = a1 sin(2?f0t) + a2 sin(2?f1t) + n(t), t= 1,....,N
6+
i = 1;
7+
k = 1;
8+
J1 = zeros(length(0:0.01:0.5),length(0:0.01:0.5));
9+
for f1 = 0:0.01:0.5
10+
for f0 = 0:0.01:0.5
11+
J = (y - (a1.*sin(2*pi*f0.*t')) - (a2.*sin(2*pi*f1.*t'))).^2;
12+
J1(i,k) = sum(J);
13+
k = k+1;
14+
end
15+
i = i+1;
16+
k=1;
17+
end
18+
surf(0:0.01:0.5,0:0.01:0.5,J1);
19+
title('Plot of J(fo,f1) vs fo, fi')
20+
xlabel('values of fo')
21+
ylabel('values of f1')
22+
zlabel('Amplitude of J(fo,f1)')
23+
%[f0_value,f1_value,J_value] = ginput(1) %picking the minimum coordinates
24+
%plot3(0:0.01:0.5,0:0.01:0.5,J1);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
clc
2+
close all
3+
%% y (t) = a1 sin(2?f0t) + a2 sin(2?f1t) + n(t), t= 1,....,N
4+
%% plotting J vs variance with fixed fo
5+
f0 = 0.25;
6+
a1 = 1;
7+
a2 = 1;
8+
N = 10000;
9+
t = 1:1:N;
10+
i=1;
11+
var_ = zeros(length(0.1:0.1:1),1);
12+
J1 = zeros(length(0.1:0.1:1),1);
13+
for s_d = 0.1:0.1:1
14+
n1 = s_d .* n;
15+
y = (a1.*sin(2*pi*f0.*t)) + (a2.*sin(2*pi*f1.*t)) + n1;
16+
var_(i) = var(y);
17+
y = y';
18+
J = (y - (a1.*sin(2*pi*f0.*t')) - (a2.*sin(2*pi*f1.*t'))).^2;
19+
J1(i) = sum(J);
20+
i = i + 1;
21+
end
22+
plot(var_,J1)
23+
title('Plot of J vs variance with fo and f1constant and a1 = a2 = 1')
24+
ylabel('Amplitude of J')
25+
xlabel('Value of variance')
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
clc
2+
close all
3+
%% y (t) = a1 sin(2?f0t) + a2 sin(2?f1t) + n(t), t= 1,....,N
4+
f0 = 0.25;
5+
f1 = 0.4;
6+
m = 5; %%choose m = 5
7+
N = 10000;
8+
t = 1:1:N;
9+
i=1;
10+
var_ = zeros(length(1:0.2:10),1);
11+
J1 = zeros(length(1:0.2:10),1);
12+
for s_d = 1:0.2:10
13+
n1 = s_d .* n;
14+
y = (a1.*sin(2*pi*f0.*t)) + (a2.*sin(2*pi*f1.*t)) + n1;
15+
var_(i) = var(y);
16+
y = y';
17+
J = (y - (a1.*sin(2*pi*f0.*t')) - (a2.*sin(2*pi*f1.*t'))).^2;
18+
J1(i) = sum(J);
19+
i = i + 1;
20+
end
21+
plot(var_,J1)

LinearEstimation.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
clc
2+
clear all
3+
close all
4+
%% y(t) = m + n(t) t= 1,....,N
5+
v1 = zeros(5,5);
6+
for j = 0:4
7+
for i = 1:5
8+
m = 5; %%choose m = 5
9+
N = 1000;
10+
var = 1+(j*10); %%value for variance
11+
v2 = 1+j;
12+
n = var * randn(1,N);
13+
y = m + n;
14+
y = y';
15+
%plot(y)
16+
%% Creating a Maximum Likelihood Estimator
17+
est_m = (1/N)*sum(y);
18+
v1(v2,i) = est_m;
19+
end
20+
end

LinearEstimation_0.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
clear all
2+
close all
3+
clc
4+
%% y(t) = m + n(t), t = 1.....N
5+
m = 5;
6+
N= 1000;
7+
t = 1:1:N
8+
y = zeros(N,5);
9+
n = zeros(N,1);
10+
std_d = 1;
11+
i = 1; %%counter for filling y for different values of variance
12+
for std_d = 0.1:0.2:1
13+
n = std_d * randn(N,1);
14+
y(:,i) = m + n;
15+
subplot(5,1,i);
16+
stem(t(1:100),y(1:100,i));
17+
title(['Plot of y for variance = ' num2str(var(y(:,i)))])
18+
xlabel('time(1:100)')
19+
ylabel('Amplitude')
20+
i = i+1;
21+
end
22+
23+

LinearEstimation_1.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
clear all
2+
close all
3+
clc
4+
%% y(t) = m + n(t), t = 1.....N
5+
m = 5;
6+
y = [];
7+
n = [];
8+
est_m = [];
9+
std_d = 1;
10+
i = 1; %%counter for filling y for different values of variance
11+
for N = [10, 100, 1000, 10000, 100000]
12+
n = std_d * randn(N,1);
13+
y = m + n;
14+
est_m(i) = sum(y)/N;
15+
disp(['Estimated value for N = ' num2str(N) ' is ' num2str(est_m(i))])
16+
i = i+1;
17+
end
18+
19+

LinearEstimation_1_1.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
clear all
2+
close all
3+
clc
4+
%% realization of the performance of the estimator for various value of variance
5+
%% y(t) = m + n(t), t = 1.....N
6+
m = 5;
7+
y = [];
8+
n = [];
9+
est_m = [];
10+
N = 1000;
11+
i = 1; %%counter for filling y for different values of variance
12+
for std_d = [2, 4, 6, 8, 10]
13+
n = std_d * randn(N,1);
14+
y = m + n;
15+
est_m(i) = sum(y)/N;
16+
disp(['Estimated value for variance = ' num2str(var(y)) ' is ' num2str(est_m(i))])
17+
i = i+1;
18+
end
19+
20+

LinearEstimation_3.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
clc
2+
clear all
3+
close all
4+
%% Realizing the bias of the estimator for different values of N
5+
%% y(t) = m + n(t) t= 1,....,N
6+
est_m = zeros(1,1000);
7+
b = zeros(1,10);
8+
i = 1;
9+
for N = 10:10000:100000
10+
for mc = 1:1000
11+
m = 5; %%choose m = 5
12+
n = randn(1,N);
13+
y = m + n;
14+
y = y';
15+
%plot(y)
16+
%% Creating a Maximum Likelihood Estimator
17+
est_m(mc) = (1/N)*sum(y);
18+
end
19+
exp_est_m = sum(est_m)/mc;
20+
%%calculating the bias
21+
b(i) = exp_est_m - m;
22+
b(i) = abs(b(i));
23+
i = i+1;
24+
end
25+
plot(10:10000:100000,b);
26+
title('plot for the bias for different values of N')
27+
xlabel('values of N')
28+
ylabel('value of bias')

LinearEstimator_4_0.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
clc
2+
clear all
3+
close all
4+
%% y(t) = m + n(t) t= 1,....,N
5+
est_m = zeros(1,1000);
6+
b = zeros(1,100);
7+
i = 1;
8+
for N = 10
9+
for mc = 1:10
10+
m = 100; %%choose m = 5
11+
n = randn(1,N);
12+
y = m + n;
13+
y = y';
14+
%plot(y)
15+
%% Creating a Maximum Likelihood Estimator
16+
est_m(mc) = (1/(N-1))*sum(y);
17+
end
18+
exp_est_m = sum(est_m)/mc;
19+
%%calculating the bias
20+
b(i) = exp_est_m - m;
21+
b(i) = abs(b(i));
22+
i = i+1;
23+
end
24+
plot(10:1000:100000,b);

0 commit comments

Comments
 (0)