Files
matlab-python/ATD/defDatiTLH.m

69 lines
2.0 KiB
Matlab
Executable File

% Funzione che definisce accelerazioni (accTLH), dati magnetici (magTLH),
% temperature (tempTLH), date (TimeTLH)per i nodi di tipo Tilt Link H
function [TimeTLH,accTLH,tempTLH,ErrTiltLinkH] = defDatiTLH(...
DatiTiltLinkH,ErrTiltLinkH,Ndatidespike,rTLH,MEMS,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'defDatiTLH function started';
fprintf(fileID,fmt,text);
[r,c] = size(DatiTiltLinkH);
Ncorr = 0;
% Elimino gli eventuali Not a Number
for a = 2:r
for b = 2:c
check = isnan(DatiTiltLinkH(a,b));
if check == 1
DatiTiltLinkH(a,b) = DatiTiltLinkH(a-1,b);
ErrTiltLinkH(a,b-1) = 1;
Ncorr = Ncorr+1;
end
end
end
text = ['' num2str(Ncorr) ' NaN of Tilt Link H corrected by defDatiTLH function'];
fprintf(fileID,fmt,text);
TimeTLH = DatiTiltLinkH(:,1); % data
accTLH = zeros(r,rTLH*3); % dati accelerometro
tempTLH = zeros(r,rTLH); % temperatura del nodo per la calibrazione
p = 4; % passo nella definizione dei dati
s = 1;
for i = 1:rTLH
accTLH(:,s) = DatiTiltLinkH(:,2+(i-1)*p);
accTLH(:,s+1) = DatiTiltLinkH(:,3+(i-1)*p);
accTLH(:,s+2) = DatiTiltLinkH(:,4+(i-1)*p);
s = s+3;
tempTLH(:,i) = DatiTiltLinkH(:,5+(i-1)*p);
if MEMS == 2
[rT,~] = size(tempTLH);
for j = 1:rT
if tempTLH(j,i) > 200
tempTLH(j,i) = tempTLH(j,i) - 256; % Correzione della temperatura dei nuovi MEMS
end
end
end
end
s = 1;
Num_Dati = Ndatidespike; % numero di dati per il despike
if Num_Dati > r
Num_Dati = r;
end
for i = 1:rTLH
% despiking accelerometri
accTLH(:,s) = filloutliers(accTLH(:,s),'linear','movmedian',Num_Dati);
accTLH(:,s+1) = filloutliers(accTLH(:,s+1),'linear','movmedian',Num_Dati);
accTLH(:,s+2) = filloutliers(accTLH(:,s+2),'linear','movmedian',Num_Dati);
s = s+3;
end
text = 'Data of Tilt Link H defined correctly. defDatiTLH function closed';
fprintf(fileID,fmt,text);
fclose(fileID);
end