-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathregressio_lin.asv
More file actions
executable file
·112 lines (66 loc) · 2.08 KB
/
regressio_lin.asv
File metadata and controls
executable file
·112 lines (66 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
%regressione lineare
clear all;
close all;
clc;
fc=20;
tmax=2;
tmin=0;
t=linspace(tmin,tmax,fc*(tmax-tmin));
a=5;
b=3;
y=a*t+b;
%figure,plot(t,y),title('Retta da stimare')
%Stima ML
%y=H*the+w
for k=1:30
sigma_w=k;
w=sigma_w*randn(size(y));
x=y+w;
%figure,plot(t,x),title('Osservazioni con rumore')
H=zeros(length(t),2);
H=[ones(length(t),1) t'];
%covarianza del rumore è nota
Cw=sigma_w*eye(length(x)); %non conoscendo a priori le covarianze, le vc si suppongono incorrelate,
%commettendo un errore
the=(H'*Cw^-1*H)^-1*H'*Cw^-1*x';
%retta di regressione
%hold on, plot(t,the(1)+the(2)*t,'g')
%plotting della varianza della stima del parametro A
cova=(H'*Cw^-1*H)^-1;
var_a(k)=cova(1,1);
var_b(k)=cova(2,2);
end
figure,plot(10*log10(1:30),var_a,'r',10*log10(1:30),var_b,'b'),title('Varianza della stima dei parametri di una retta di regress, all''aumentare del rumore'),...
xlabel('Potenza di rumore [dB]'),ylabel('Varianza del parametro'),legend('var. intercetta','var. coef. ango')
figure,plot()
fc=20;
tmax=1;
tmin=-1;
t=linspace(tmin,tmax,fc*(tmax-tmin));
a=5;
b=3;
y=a*t+b;
%figure,plot(t,y),title('Retta da stimare')
%Stima ML
%y=H*the+w
for k=1:30
sigma_w=k;
w=sigma_w*randn(size(y));
x=y+w;
%figure,plot(t,x),title('Osservazioni con rumore')
H=zeros(length(t),2);
H=[ones(length(t),1) t'];
%covarianza del rumore è nota
Cw=sigma_w*eye(length(x)); %non conoscendo a priori le covarianze, le vc si suppongono incorrelate,
%commettendo un errore
the=(H'*Cw^-1*H)^-1*H'*Cw^-1*x';
%retta di regressione
%hold on, plot(t,the(1)+the(2)*t,'g')
%plotting della varianza della stima del parametro A
cova=(H'*Cw^-1*H)^-1;
var_a_sim(k)=cova(1,1);
var_b_sim(k)=cova(2,2);
end
figure,plot(10*log10(1:30),10*log10(var_a),'r',10*log10(1:30),10*log10(var_a_sim),'b',10*log10(1:30),10*log10(var_a./var_a_sim),'k'),title('Confronto tra accuratezza nella stima dell''intercetta per misure simmetriche e non'),...
xlabel('Potenza di rumore [dB]'),ylabel('Varianza della stima di a [dB]'),...
legend('misure non simmetriche- accuratezza','misure simmetriche- accuratezza','guadagno')