% Funzione che definisce accelerazioni (accTL), dati magnetici (magTL), % temperature (tempTL) per i nodi di tipo Tilt Link 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 = 1: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); % Definisco Data (gg:mm:aaaa hh:mm), Batteria, i 3 dati di accelerometro % e magnetometro e la Temperatura per la calibrazione TimeTLH = DatiTiltLinkH(:,1); % data accTLH = zeros(r,rTLH*3); % dati accelerometro tempTLH = zeros(r,rTLH); % temperatura del nodo per la calibrazione p = 7; % passo nella definizione dei dati s = 1; if MEMS == 1 % MEMS ST inverto le colonne Y e Z del magnetometro (MEMS vecchi, PRE 21 Maggio 2016) 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(:,8+(i-1)*p); end elseif MEMS == 2 % MEMS Freescale, dopo 21 Maggio 2016 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(:,8+(i-1)*p); [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 elseif MEMS == 3 % MEMS Murata 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(:,8+(i-1)*p); 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 ended'; fprintf(fileID,fmt,text); fclose(fileID); end