Sync from remote server: 2025-10-12 18:56:41
This commit is contained in:
407
ATD/elab2D_TLH.m
Executable file
407
ATD/elab2D_TLH.m
Executable file
@@ -0,0 +1,407 @@
|
||||
function [Y_TLH,Z_TLH,Ylocal_TLH,Zlocal_TLH,AlfaX_TLH,AlfaY_TLH,TempDef_TLH,...
|
||||
speed_TLH,speed_local_TLH,acceleration_TLH,acceleration_local_TLH,ARRAYdate_TLH,...
|
||||
ErrTiltLinkH] = elab2D_TLH(IDcentralina,DTcatena,rTLH,accTLH,ACCdefRis_TLH,...
|
||||
TempDef_TLH,SpeTLH,PsTLH,tolleranzaAcc,DatiElabTiltLinkH,Ndevst,Wdevst,...
|
||||
ARRAYdate_TLH,NuovoZeroTLH,NdatiMedia,Ndatidespike,ErrTiltLinkH,margine,...
|
||||
elab_option,Tmax,Tmin,datainiTLH,FileName)
|
||||
|
||||
%% Inizializzazione
|
||||
fileID = fopen(FileName,'a');
|
||||
fmt = '%s \r';
|
||||
text = 'elab2D_TLH function started';
|
||||
fprintf(fileID,fmt,text);
|
||||
|
||||
if NuovoZeroTLH == 1
|
||||
if NdatiMedia > Ndatidespike
|
||||
Ndati = NdatiMedia;
|
||||
else
|
||||
Ndati = Ndatidespike;
|
||||
end
|
||||
ini = round(Ndati/2)+1;
|
||||
if rem(Ndati,2) == 0
|
||||
ini = ini+1;
|
||||
end
|
||||
clear NDati
|
||||
ini = ini + margine;
|
||||
if ini < 6
|
||||
ini = 6;
|
||||
end
|
||||
if Ndevst ~= 0 % Allora prendo tutti i dati e solo in seguito considero i nuovi, a valle della funzione filtro
|
||||
ini = 1;
|
||||
end
|
||||
accTLH = accTLH(ini:end,:);
|
||||
ACCdefRis_TLH = ACCdefRis_TLH(ini:end,:);
|
||||
TempDef_TLH = TempDef_TLH(ini:end,:);
|
||||
DatiElabTiltLinkH = DatiElabTiltLinkH(ini:end,:);
|
||||
ARRAYdate_TLH = ARRAYdate_TLH(ini:end,1);
|
||||
ErrTiltLinkH = ErrTiltLinkH(ini:end,:);
|
||||
end
|
||||
|
||||
%% Definisco i dati
|
||||
Nnodi = rTLH;
|
||||
% Spacchetto
|
||||
[r,~] = size(accTLH); % Numero di dati
|
||||
[Ndati,~] = size(ARRAYdate_TLH);
|
||||
ax = zeros(r,Nnodi);
|
||||
ay = zeros(r,Nnodi);
|
||||
for i=1:Nnodi
|
||||
ax(:,i) = accTLH(:,(i-1)*3+1); % ax
|
||||
ay(:,i) = accTLH(:,(i-1)*3+2); % ay
|
||||
end
|
||||
ax = ax'; % riga nodi, colonna date
|
||||
ay = ay'; % riga nodi, colonna date
|
||||
|
||||
%% Costruzione delle matrici
|
||||
|
||||
% Dati locali
|
||||
asseY_TLH = zeros(Nnodi,Ndati); % Raccoglie i dati planari locali nella direzione di sviluppo della catena
|
||||
asseZ_TLH = zeros(Nnodi,Ndati); % Raccoglie i dati planari locali nella direzione di sviluppo della catena, basso->alto
|
||||
|
||||
% Dati cumulati
|
||||
Y_TLH = zeros(Nnodi,Ndati); % Raccoglie i dati cumulati nella direzione di sviluppo della catena
|
||||
Z_TLH = zeros(Nnodi,Ndati); % Raccoglie i dati cumulati nella direzione di sviluppo della catena, basso->alto
|
||||
|
||||
% Angoli
|
||||
AlfaX_TLH = zeros(Nnodi,Ndati);
|
||||
AlfaY_TLH = zeros(Nnodi,Ndati);
|
||||
|
||||
% parametri per il calcolo
|
||||
SpeTLH = SpeTLH(2:end,1); % valori segmenti di pertinenza
|
||||
PsTLH = PsTLH(2:end,1); % valori posizioni punti di calcolo
|
||||
|
||||
% Inizio del ciclo di elaborazione
|
||||
text = 'Elaboration of Tilt Link H started';
|
||||
fprintf(fileID,fmt,text);
|
||||
|
||||
for jj = 1:Ndati
|
||||
for ii = 1:Nnodi
|
||||
[Y_TLH,Z_TLH,asseY_TLH,asseZ_TLH,AlfaX_TLH,AlfaY_TLH] = CalcoloBiax_TLH(...
|
||||
SpeTLH,PsTLH,ii,jj,ax,ay,asseY_TLH,asseZ_TLH,Y_TLH,Z_TLH,...
|
||||
elab_option,AlfaX_TLH,AlfaY_TLH);
|
||||
end
|
||||
end
|
||||
dY_TLH = diff(asseY_TLH,1,2);
|
||||
dZ_TLH = diff(asseZ_TLH,1,2);
|
||||
|
||||
%% Controllo della risultante delle accelerazioni
|
||||
clear r
|
||||
clear rr
|
||||
clear c
|
||||
clear cc
|
||||
ACCdefRis_TLH = ACCdefRis_TLH'; % Nodi in riga, date in colonna
|
||||
[r,c] = size(ACCdefRis_TLH);
|
||||
[rr,cc] = size(Y_TLH);
|
||||
|
||||
% controllo che le matrici con le risultanti delle accelerazioni e
|
||||
% le matrici con i dati di spostamento abbiano le stesse dimensioni
|
||||
if r~=rr || c~=cc
|
||||
text = 'Warning! Displacement data and g vector have not the same size!';
|
||||
else
|
||||
text = 'There are not warning for Tilt Link H';
|
||||
end
|
||||
fprintf(fileID,fmt,text);
|
||||
clear i
|
||||
clear j
|
||||
cont = 1; % contatore
|
||||
cont2 = 1; % contatore
|
||||
cont3 = 1; % contatore
|
||||
TempDef_TLH = TempDef_TLH';
|
||||
text1 = 'There are not correction of Tilt Link H based on acceleration vector filter';
|
||||
text2 = 'There are not correction of Tilt Link H based on uncalibrated Acceleration vector';
|
||||
text3 = 'There are not correction of Tilt Link H based on temperature filter';
|
||||
for j = 2:c % data
|
||||
for i = 1:r % nodo
|
||||
% se il valore assoluto della differenza è maggiore della
|
||||
% tolleranza, pongo gli spostamenti giornalieri pari a 0
|
||||
if abs(ACCdefRis_TLH(i,j)-ACCdefRis_TLH(i,j-1)) > tolleranzaAcc
|
||||
dY_TLH(i,j-1) = 0;
|
||||
dZ_TLH(i,j-1) = 0;
|
||||
text1 = ['' num2str(cont) ' correction executed for Tilt Link H - Acceleration vector filter!'];
|
||||
cont = cont+1;
|
||||
end
|
||||
if ACCdefRis_TLH(i,j) < 0.9 || ACCdefRis_TLH(i,j) > 1.1 % Il nodo è fuori taratura!
|
||||
dY_TLH(i,j-1) = 0;
|
||||
dZ_TLH(i,j-1) = 0;
|
||||
TempDef_TLH(i,j) = TempDef_TLH(i,j-1);
|
||||
text2 = ['' num2str(cont3) ' correction executed for Tilt Link H - uncalibrated Acceleration vector!'];
|
||||
cont3 = cont3+1;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
FileTemperature = ['' IDcentralina '-' DTcatena '-TLH-Therm.csv'];
|
||||
if isfile(FileTemperature) == 1
|
||||
DatiRaw = csvread(FileTemperature);
|
||||
[rDR,cDR] = size(DatiRaw);
|
||||
DatiRaw(:,1) = DatiRaw(:,1) + 730000;
|
||||
else
|
||||
rDR = 1;
|
||||
cDR = 1;
|
||||
end
|
||||
for b = 1:c % Data
|
||||
for a = 1:r % Nodo
|
||||
% NON considero i dati al di sopra dei 80 °C o al di sotto dei -30 °C!
|
||||
if TempDef_TLH(a,b) > Tmax || TempDef_TLH(a,b) < Tmin
|
||||
cont2 = cont2+1;
|
||||
if b == 1
|
||||
if isfile(FileTemperature) == 1
|
||||
RawDate = find(DatiRaw(:,1)<=datenum(datainiTLH));
|
||||
if isempty(RawDate) == 1
|
||||
cc = 2;
|
||||
while cc <= c
|
||||
if TempDef_TLH(a,cc) > Tmax || TempDef_TLH(a,cc) < Tmin
|
||||
cc = cc+1;
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
TempDef_TLH(a,b) = TempDef_TLH(a,cc);
|
||||
else
|
||||
if isnan(DatiRaw(RawDate(end),a+1)) == 0
|
||||
TempDef_TLH(a,b) = DatiRaw(RawDate(end),a+1);
|
||||
ErrTiltLinkH(b,a) = 0.5;
|
||||
wardat = 'Temperature data of Tilt Link H nodes corrected using Raw Data of reference Csv file.';
|
||||
fprintf(fileID,fmt,wardat);
|
||||
else
|
||||
cc = 2;
|
||||
while cc <= c
|
||||
if TempDef_TLH(a,cc) > Tmax || TempDef_TLH(a,cc) < Tmin
|
||||
cc = cc+1;
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
TempDef_TLH(a,b) = TempDef_TLH(a,cc);
|
||||
end
|
||||
end
|
||||
else
|
||||
cc = 2;
|
||||
while cc <= c
|
||||
if TempDef_TLH(a,cc) > Tmax || TempDef_TLH(a,cc) < Tmin
|
||||
cc = cc+1;
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
TempDef_TLH(a,b) = TempDef_TLH(a,cc);
|
||||
end
|
||||
else
|
||||
TempDef_TLH(a,b) = TempDef_TLH(a,b-1);
|
||||
dY_TLH(a,b-1) = 0;
|
||||
dZ_TLH(a,b-1) = 0;
|
||||
ErrTiltLinkH(b,a) = 0.5;
|
||||
end
|
||||
text3 = ['' num2str(cont2) ' correction executed for Tilt Link H - Temperature filter!'];
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if rDR~=1 && cDR~=1 && isempty(DatiRaw) == 0
|
||||
RawDate1 = find(DatiRaw(:,1)<=ARRAYdate_TLH(1));
|
||||
if isempty(RawDate1) == 1
|
||||
RawDate2 = 1;
|
||||
elseif RawDate1(end) == rDR
|
||||
RawDate2 = find(ARRAYdate_TLH(:,1)>DatiRaw(end,1));
|
||||
else
|
||||
RawDate2 = find(ARRAYdate_TLH(:,1)>DatiRaw(RawDate1(end)+1,1));
|
||||
end
|
||||
else
|
||||
RawDate1 = [];
|
||||
RawDate2 = 1;
|
||||
end
|
||||
if isempty(RawDate1) == 0 && isempty(RawDate2) == 0
|
||||
Dati = [DatiRaw(1:RawDate1(end),:); ARRAYdate_TLH(RawDate2(1):end) TempDef_TLH(:,RawDate2(1):end)'];
|
||||
elseif isempty(RawDate1) == 1 && isempty(RawDate2) == 0
|
||||
Dati = [ARRAYdate_TLH TempDef_TLH'];
|
||||
else
|
||||
Dati = DatiRaw;
|
||||
end
|
||||
% Elimino appoggio più vecchio di un mese
|
||||
RawDate3 = find(Dati(:,1)<now-30);
|
||||
if isempty(RawDate3) == 0
|
||||
[rDati,~] = size(Dati);
|
||||
if RawDate3(end) == rDati
|
||||
else
|
||||
Dati = Dati(RawDate3(end)+1:end,:);
|
||||
end
|
||||
end
|
||||
if isfile(FileTemperature) == 1
|
||||
delete(FileTemperature);
|
||||
end
|
||||
Dati(:,1) = Dati(:,1) - 730000;
|
||||
csvwrite(FileTemperature,Dati);
|
||||
|
||||
TempDef_TLH = TempDef_TLH';
|
||||
|
||||
fprintf(fileID,fmt,text1);
|
||||
fprintf(fileID,fmt,text2);
|
||||
fprintf(fileID,fmt,text3);
|
||||
|
||||
%% Filtro
|
||||
fprintf(fileID,fmt,'filtro_TLH function started');
|
||||
[dY_TLH,dZ_TLH,text] = filtro_TLH(dY_TLH,dZ_TLH,Ndevst,Wdevst);
|
||||
fprintf(fileID,fmt,'filtro_TLH function closed');
|
||||
|
||||
fprintf(fileID,fmt,text);
|
||||
if NuovoZeroTLH == 1 && Ndevst ~= 0
|
||||
if NdatiMedia > Ndatidespike
|
||||
NdatiF = NdatiMedia;
|
||||
else
|
||||
NdatiF = Ndatidespike;
|
||||
end
|
||||
ini = round(NdatiF/2)+1;
|
||||
if rem(NdatiF,2) == 0
|
||||
ini = ini+1;
|
||||
end
|
||||
clear NDatiF
|
||||
iniST = round(Wdevst/2);
|
||||
if rem(Wdevst,2) == 0
|
||||
iniST = iniST+1;
|
||||
end
|
||||
iniST = iniST + margine;
|
||||
if iniST > ini
|
||||
ini = iniST;
|
||||
end
|
||||
if ini < 6
|
||||
ini = 6;
|
||||
end
|
||||
dY_TLH = dY_TLH(:,ini:end);
|
||||
dZ_TLH = dZ_TLH(:,ini:end);
|
||||
TempDef_TLH = TempDef_TLH(ini:end,:);
|
||||
DatiElabTiltLinkH = DatiElabTiltLinkH(ini:end,:);
|
||||
ARRAYdate_TLH = ARRAYdate_TLH(ini:end,1);
|
||||
ErrTiltLinkH = ErrTiltLinkH(ini:end,:);
|
||||
end
|
||||
|
||||
%% Finalizzo i calcoli
|
||||
[rx,cx] = size(dZ_TLH);
|
||||
% totale del singolo nodo data per data
|
||||
sommaY_TLH = zeros(rx,cx+1);
|
||||
sommaZ_TLH = zeros(rx,cx+1);
|
||||
% cumulata del singolo nodo data per data in posizione assoluta
|
||||
% il primo valore è quello di posizione assoluta iniziale
|
||||
Y_TLH = zeros(rx,cx+1);
|
||||
Z_TLH = zeros(rx,cx+1);
|
||||
% cumulata del singolo nodo data per data in posizione relativa
|
||||
% il primo valore è quello di posizione assoluta iniziale
|
||||
Ylocal_TLH = zeros(Nnodi,Ndati);
|
||||
Zlocal_TLH = zeros(Nnodi,Ndati);
|
||||
speed_TLH = zeros(Nnodi,Ndati);
|
||||
speed_local_TLH = zeros(Nnodi,Ndati);
|
||||
acceleration_TLH = zeros(Nnodi,Ndati);
|
||||
acceleration_local_TLH = zeros(Nnodi,Ndati);
|
||||
|
||||
if NuovoZeroTLH == 1
|
||||
[rE,cE] = size(DatiElabTiltLinkH);
|
||||
cont = 3;
|
||||
n = 1;
|
||||
while cont<=cE
|
||||
sommaY_TLH(n,1) = cell2mat(DatiElabTiltLinkH(1,cont))';
|
||||
Ylocal_TLH(n,1) = sommaY_TLH(n,1);
|
||||
sommaZ_TLH(n,1) = cell2mat(DatiElabTiltLinkH(1,cont+1))';
|
||||
Zlocal_TLH(n,1) = sommaZ_TLH(n,1);
|
||||
Y_TLH(n,1) = cell2mat(DatiElabTiltLinkH(1,cont+2))';
|
||||
Z_TLH(n,1) = cell2mat(DatiElabTiltLinkH(1,cont+3))';
|
||||
speed_local_TLH(n,1:rE) = cell2mat(DatiElabTiltLinkH(:,cont+7))';
|
||||
speed_TLH(n,1:rE) = cell2mat(DatiElabTiltLinkH(:,cont+8))';
|
||||
acceleration_local_TLH(n,1:rE) = cell2mat(DatiElabTiltLinkH(:,cont+9))';
|
||||
acceleration_TLH(n,1:rE) = cell2mat(DatiElabTiltLinkH(:,cont+10))';
|
||||
cont = cont+13;
|
||||
n = n+1;
|
||||
end
|
||||
else
|
||||
% Primo dato
|
||||
Y_TLH(:,1) = PsTLH;
|
||||
Z_TLH(:,1) = 0;
|
||||
end
|
||||
for iii = 1:cx % date
|
||||
% somma singoli spostamenti del singolo nodo
|
||||
sommaY_TLH(:,iii+1) = sum(dY_TLH(:,1:iii),2)+sommaY_TLH(:,1);
|
||||
sommaZ_TLH(:,iii+1) = sum(dZ_TLH(:,1:iii),2)+sommaZ_TLH(:,1);
|
||||
% spostamenti locali riferiti allo 0
|
||||
Ylocal_TLH(:,iii+1) = sommaY_TLH(:,iii+1);
|
||||
Zlocal_TLH(:,iii+1) = sommaZ_TLH(:,iii+1);
|
||||
% cumulata spostamenti
|
||||
Y_TLH(:,iii+1) = Y_TLH(:,1) + cumsum(sommaY_TLH(:,iii+1)) - cumsum(sommaY_TLH(:,1));
|
||||
Z_TLH(:,iii+1) = Z_TLH(:,1) + cumsum(sommaZ_TLH(:,iii+1)) - cumsum(sommaZ_TLH(:,1));
|
||||
end
|
||||
|
||||
%% Calcolo velocità di spostamento giornaliera
|
||||
[numDate,~] = size(ARRAYdate_TLH); % numero di date
|
||||
d = 1;
|
||||
p = 1;
|
||||
diffDate = 0;
|
||||
n = 1;
|
||||
period = 1; % calcolo giornaliero
|
||||
ContSUP = [];
|
||||
for dd = 1:numDate
|
||||
while diffDate < period
|
||||
d = d+1;
|
||||
if d > numDate % Se d supera le date disponibili, esco dal ciclo while
|
||||
break
|
||||
end
|
||||
diffDate = ARRAYdate_TLH(d) - ARRAYdate_TLH(p);
|
||||
end
|
||||
if d >numDate
|
||||
break
|
||||
end
|
||||
ContSUP(n,1) = d; %#ok<*AGROW> % Creo matrice indici dell'estremo superiore della differenza
|
||||
ContINF(n,1) = p; % Creo matrice indici dell'estremo inferiore della differenza
|
||||
p = p+1; % passo alla data di partenza successiva
|
||||
d = p; % resetto il conto di d
|
||||
n = n+1;
|
||||
diffDate = 0;
|
||||
end
|
||||
|
||||
check = isempty(ContSUP);
|
||||
if check == 0
|
||||
[nDate,~] = size(ContSUP);
|
||||
for s = 1:rTLH
|
||||
N = 1;
|
||||
for dd = 1:nDate
|
||||
speed_TLH(s,ContSUP(N,1)) = (Z_TLH(s,ContSUP(N,1))-Z_TLH(s,ContINF(N,1)))...
|
||||
/(ARRAYdate_TLH(ContSUP(N,1))-ARRAYdate_TLH(ContINF(N,1)));
|
||||
speed_local_TLH(s,ContSUP(N,1)) = (Zlocal_TLH(s,ContSUP(N,1))-Zlocal_TLH(s,ContINF(N,1)))...
|
||||
/(ARRAYdate_TLH(ContSUP(N,1))-ARRAYdate_TLH(ContINF(N,1)));
|
||||
acceleration_TLH(s,ContSUP(N,1)) = (speed_TLH(s,ContSUP(N,1))-speed_TLH(s,ContINF(N,1)))...
|
||||
/(ARRAYdate_TLH(ContSUP(N,1))-ARRAYdate_TLH(ContINF(N,1)));
|
||||
acceleration_local_TLH(s,ContSUP(N,1)) = (speed_local_TLH(s,ContSUP(N,1))-speed_local_TLH(s,ContINF(N,1)))...
|
||||
/(ARRAYdate_TLH(ContSUP(N,1))-ARRAYdate_TLH(ContINF(N,1)));
|
||||
N = N+1;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
fclose(fileID);
|
||||
% Approssimo i dati con il corretto numero di cifre decimali
|
||||
[Y_TLH,Z_TLH,Ylocal_TLH,Zlocal_TLH,TempDef_TLH,speed_TLH,...
|
||||
speed_local_TLH,acceleration_TLH,acceleration_local_TLH,AlfaX_TLH,AlfaY_TLH] = ...
|
||||
approx_TLH(Y_TLH,Z_TLH,Ylocal_TLH,Zlocal_TLH,TempDef_TLH,speed_TLH,speed_local_TLH,...
|
||||
acceleration_TLH,acceleration_local_TLH,AlfaX_TLH,AlfaY_TLH,FileName);
|
||||
|
||||
% Riordino matrice errori
|
||||
[r,~] = size(ErrTiltLinkH);
|
||||
Matrice_err = zeros(r,rTLH);
|
||||
for i = 1:r % date
|
||||
d = 1;
|
||||
for n = 1:rTLH % nodi
|
||||
j = 1;
|
||||
err = ErrTiltLinkH(i,d:d+3);
|
||||
while j <= 4
|
||||
if err(1,j) == 1
|
||||
Matrice_err(i,n) = 1;
|
||||
end
|
||||
j = j+1;
|
||||
end
|
||||
d = d+4;
|
||||
end
|
||||
end
|
||||
ErrTiltLinkH = Matrice_err';
|
||||
|
||||
text = 'Tilt Link H calculation executed correctly. elab2D_TLH function closed';
|
||||
fileID = fopen(FileName,'a');
|
||||
fmt = '%s \r';
|
||||
fprintf(fileID,fmt,text);
|
||||
fclose(fileID);
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user