Files
matlab-python/Tilt/MediaDati_TLH.m

88 lines
3.2 KiB
Matlab
Executable File

% Questa routine calcola le medie (giornaliere o per intervalli definiti)
% necessarie per le elaborazioni successive per i TiltLink
% ACCdef contiene le medie per l'intervallo definito delle accelerazioni
% ARRAYdate contiene le date e il tempo per ogni dato (per media
% giornaliera, la data di quel giorno)
function [ACCdef_TLH,ARRAYdateTLH,ACCdefRis_TLH,TempDef_TLH] = MediaDati_TLH...
(accTLH,TimeTLH,ris_acc_TLH,tempTLH,tolleranzaAcc,NdatiMedia,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'MediaDati_TLH function started';
fprintf(fileID,fmt,text);
%% Accelerazione
[r,~]=size(accTLH);
if NdatiMedia > r
NdatiMedia = r;
end
ACCdef_TLH = smoothdata(accTLH,'gaussian',NdatiMedia);
%% Matrice date
ARRAYdateTLH = TimeTLH;
%% Risultante acc
ACCdefRis_TLH = ris_acc_TLH; % Non faccio la media, mi serve il dato come è per applicare i filtri
% Applico un controllo importante! Se la risultante varia più di 0.01, NON
% faccio la media dei dati attorno, che altrimenti ne sono condizionati!
[r,c] = size(ACCdefRis_TLH); % Nodi in colonna, date in riga
Win = NdatiMedia/2; % Individuo la finestra da NON mediare
cont = 0; % Contatore
cont2 = 0;
for i = 2:r % data
for j = 2:c % nodo
% se il valore assoluto della differenza è maggiore della
% tolleranza, NON faccio la media
if abs(ACCdefRis_TLH(i,j)-ACCdefRis_TLH(i-1,j)) > tolleranzaAcc
Sp = i-Win; % Punto di partenza (date)
if Sp <= 0
Sp = 1;
end
if i+Win > r
Ep = r;
else
Ep = i+Win; % Punto di arrivo (date)
end
Cax = 3*j-2;
Cay = 3*j-1;
Caz = 3*j;
ACCdef_TLH(Sp:Ep,Cax) = accTLH(Sp:Ep,Cax); % ax
ACCdef_TLH(Sp:Ep,Cay) = accTLH(Sp:Ep,Cay); % ay
ACCdef_TLH(Sp:Ep,Caz) = accTLH(Sp:Ep,Caz); % az
cont = cont+1;
end
if ACCdefRis_TLH(i,j) < 0.9 || ACCdefRis_TLH(i,j) > 1.1 % Il nodo è fuori taratura!
Sp = i-Win; % Punto di partenza (date)
if Sp <= 0
Sp = 1;
end
if i+Win > r
Ep = r;
else
Ep = i+Win; % Punto di arrivo (date)
end
Cax = 3*j-2;
Cay = 3*j-1;
Caz = 3*j;
ACCdef_TLH(Sp:Ep,Cax) = accTLH(Sp:Ep,Cax); % ax
ACCdef_TLH(Sp:Ep,Cay) = accTLH(Sp:Ep,Cay); % ay
ACCdef_TLH(Sp:Ep,Caz) = accTLH(Sp:Ep,Caz); % az
cont2 = cont2+1;
end
end
end
text = [' ' num2str(cont) ' values of Tilt Link H accelerometer vector of gravity not subjected to mean process due to values with excessive variations!'];
fprintf(fileID,fmt,text);
text = [' ' num2str(cont2) ' values of Tilt Link H accelerometer vector of gravity not subjected to mean process due to not calibrated values!'];
fprintf(fileID,fmt,text);
%% Temperatura
TempDef_TLH = tempTLH; % Non faccio la media, mi serve il dato come è per applicare i filtri
text = 'Average mean of Tilt Link H data executed correctly. MediaDati_TLH function ended';
fprintf(fileID,fmt,text);
fclose(fileID);
end