% Funzione che definisce accelerazioni, dati magnetici, temperature, date e % livello della batteria per i nodi di tipo Tilt Link function [TimeTLHR,angTLHR,tempTLHR,ErrTiltLinkHR] = defDatiTLHR(... DatiTiltLinkHR,ErrTiltLinkHR,Ndatidespike,MEMS,rTLHR,NodoTiltLinkHR,... NuovoZeroTLHR,IDcentralina,DTcatena,Unit,FileName) fileID = fopen(FileName,'a'); fmt = '%s \r'; text = 'defDatiTLHR function started'; fprintf(fileID,fmt,text); [r,c]=size(DatiTiltLinkHR); Ncorr = 0; % Elimino gli eventuali Not a Number for a = 2:r % Date for b = 1:c check = isnan(DatiTiltLinkHR(a,b)); if check == 1 DatiTiltLinkHR(a,b) = DatiTiltLinkHR(a-1,b); ErrTiltLinkHR(a,b-1) = 1; Ncorr = Ncorr+1; end end end text = [num2str(Ncorr) ' NaN of Tilt Link HR V corrected by defDatiTLHR function']; fprintf(fileID,fmt,text); TimeTLHR = DatiTiltLinkHR(:,1); % data angTLHR = zeros(r,rTLHR*2); % dati angolari controllo_TLHR = zeros(r,rTLHR*3); tempTLHR = zeros(r,rTLHR); % temperatura del nodo per la calibrazione ctl = 1; p = 2; % passo s = 1; for i = 1:rTLHR angTLHR(:,s:s+1) = DatiTiltLinkHR(:,p:p+1); s = s+2; controllo_TLHR(:,ctl:ctl+2) = DatiTiltLinkHR(:,p+2:p+4); ctl = ctl+3; tempTLHR(:,i) = DatiTiltLinkHR(:,p+5); p = p+6; end if strcmp(Unit,'G301') == 1 i = 1; j = 1; C = 1; while i <= 2*rTLHR for ii = 2:r if angTLHR(ii,i) == -8191 && angTLHR(ii,i+1) == 0 && controllo_TLHR(ii,C) == 0 ... && controllo_TLHR(ii,C+1) == 0 && controllo_TLHR(ii,C+2) == 0 angTLHR(ii,i) = angTLHR(ii-1,i); angTLHR(ii,i+1) = angTLHR(ii-1,i+1); tempTLHR(ii,j) = tempTLHR(ii-1,j); ErrTiltLinkHR(ii,i) = 1; end end i = i+2; j = j+1; C = C+3; end end s = 1; Num_Dati = Ndatidespike; % numero di dati per il despike if Num_Dati > r Num_Dati = r; end for i = 1:rTLHR % despiking accelerometri angTLHR(:,s) = filloutliers(angTLHR(:,s),'linear','movmedian',Num_Dati); angTLHR(:,s+1) = filloutliers(angTLHR(:,s+1),'linear','movmedian',Num_Dati); s = s+2; end %% !!! Controllo che le ampolle non siano fuori scala (32768) AmpolleUpdate = ['' IDcentralina '-' DTcatena '-Ampolle.csv']; [rC,cC] = size(angTLHR); if NuovoZeroTLHR == 1 Dati = csvread(AmpolleUpdate); Dati(:,1) = Dati(:,1) + 730000; [rD,~] = size(Dati); num = 1; cont = 1; if MEMS == 2 % Nuovi nodi if rD ~= 0 for j = 1:rC for ii = 1:cC segno1 = 0; if j == 1 for a = 2:rD if TimeTLHR(j,1) == Dati(a,1) segno1 = sign(Dati(a-1,ii+1)); % segno del valore alla data precedente break end end end if segno1 == 0 if j == 1 else segno1 = sign(angTLHR(j-1,ii)); % segno del valore alla data precedente end end segno2 = sign(angTLHR(j,ii)); % segno del valore alla data successiva if segno2 ~= segno1 % se i due segni sono diversi if abs(angTLHR(j,ii)) > 15000 if segno1 == 1 angTLHR(j,ii) = 32768 + (32768 + angTLHR(j,ii)); % Fondo scala positivo elseif segno1 == -1 angTLHR(j,ii) = -32768 + (-32768 + angTLHR(j,ii)); % Fondo scala negativo end text = ['Tilt Link HR V was out of range on node ' mat2str(cell2mat(NodoTiltLinkHR(num,2))) '']; fprintf(fileID,fmt,text); end end cont = cont+1; if cont == 3 cont = 1; num = num+1; end end cont = 1; num = 1; end indice = 1; for j=1:rC if Dati(end,1) == TimeTLHR(j,1) indice = j+1; break end end else indice = 1; end else indice = []; end else indice = 1; end %% Controllo che l'ampolla non venga letta come MEMS! index = 1; nodo = 1; for b = 1:rTLHR % nodi for a = 1:rC % date if controllo_TLHR(a,index)~=0 && controllo_TLHR(a,index+1)~=0 && controllo_TLHR(a,index+2)~=0 if a == 1 if NuovoZeroTLHR == 1 for aa = 2:rD if TimeTLHR(a,1) == Dati(aa,1) angTLHR(a,2*nodo-1:2*nodo) = Dati(aa-1,2*nodo:2*nodo+1); % valore alla data precedente break end end end else angTLHR(a,2*nodo-1:2*nodo) = angTLHR(a-1,2*nodo-1:2*nodo); end ErrTiltLinkHR(a,2*nodo-1:2*nodo) = 1; end end index = index+3; nodo = nodo+1; end if isempty(indice) == 0 Dati = TimeTLHR(indice:end,1); Dati(:,1) = Dati(:,1) - 730000; datiHR = [Dati(:,1) angTLHR(indice:end,:)]; dat=isempty(datiHR); if dat==0 if NuovoZeroTLHR == 1 delete(AmpolleUpdate); end csvwrite(AmpolleUpdate,datiHR); end end text = 'Data of Tilt Link HR defined correctly. defDatiTLHR function ended'; fprintf(fileID,fmt,text); fclose(fileID); end