%% Funzione che calcola gli spostamenti in modalità triassiale per i Tilt Link function [AlfaX,AlfaY,TempDef_RSN,ARRAYdateRSN,ErrRSNLink] = elaborazione_RSN(conn,... IDcentralina,DTcatena,MEMS,rRSN,ris_acc,tolleranzaAcc,angRSN,Tmax,Tmin,TempDef_RSN,... NodoRSNLink,ARRAYdateRSN,NuovoZeroRSN,NdatiMedia,Ndatidespike,ErrRSNLink,datainiRSN,... pos_inst,FileName) % Inizio del ciclo di elaborazione text = 'elaborazione_RSN function started'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); if NuovoZeroRSN == 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 angRSN = angRSN(ini:end,:); ris_acc = ris_acc(ini:end,:); TempDef_RSN = TempDef_RSN(ini:end,:); ARRAYdateRSN = ARRAYdateRSN(ini:end,1); ErrRSNLink = ErrRSNLink(ini:end,:); end Nnodi = rRSN; % Inizio del ciclo di elaborazione text = 'Elaboration of RSN Link started'; fprintf(fileID,fmt,text); TempDef_RSN = TempDef_RSN'; [rr,cc] = size(angRSN); if MEMS == 2 cc = cc/2; else cc = cc/3; end %% Controllo delle risultanti di accelerazione if MEMS == 2 % Il controllo lo eseguo solo per i MEMS FreeScale ris_acc = ris_acc'; % Nodi in riga, date in colonna [r,c] = size(ris_acc); % controllo che le matrici con le risultanti delle accelerazioni e % le matrici con i dati di angolo di inclinazione assoluto % abbiano le stesse dimensioni (r con cc e c con rr perchè matrice % ris_acc è trasposta!) if r~=cc text = ['Warning! Number of row of absolute angle data do not correspond '... 'to the number of acceleration cosine vector!']; fprintf(fileID,fmt,text); end if c~=rr text = ['Warning! Number of column of absolute angle data do not correspond '... 'to the number of acceleration cosine vector!']; fprintf(fileID,fmt,text); end cont = 1; % contatore cont2 = 1; % contatore angRSN = angRSN'; textA = 'There are not correction of RSN Link based on acceleration vectors filter'; textA2 = 'There are not correction of RSN Link based on uncalibrated acceleration vectors'; for j = 2:c % Data nodo = 1; for i = 1:r % Nodo % se il valore assoluto della differenza è maggiore della % tolleranza, pongo l'angolo pari al valore precendete if abs(ris_acc(i,j)-ris_acc(i,j-1)) > tolleranzaAcc angRSN(nodo:nodo+1,j) = angRSN(nodo:nodo+1,j-1); textA = ['' num2str(cont) ' correction executed for RSN Link - Acceleration vector filter!']; cont = cont+1; end if ris_acc(i,j) < 0.8 || ris_acc(i,j) > 1.3 % Il nodo è fuori taratura! if j == 1 nn = 2; while nn <= c if ris_acc(i,nn) < 0.8 || ris_acc(i,nn) > 1.2 angRSN(nodo:nodo+1,j) = angRSN(nodo:nodo+1,nn); break end end else angRSN(nodo:nodo+1,j) = angRSN(nodo:nodo+1,j-1); TempDef_RSN(i,j) = TempDef_RSN(i,j-1); end textA2 = ['' num2str(cont2) ' correction executed for RSN Link - uncalibrated Acceleration vector!']; cont2 = cont2+1; end nodo = nodo+2; end end fprintf(fileID,fmt,textA); fprintf(fileID,fmt,textA2); else [c,r] = size(ris_acc); angRSN = angRSN'; end %% Temperatura cont3 = 0; % contatore FileTemperature = ['' IDcentralina '-' DTcatena '-RSN-Therm.csv']; if isfile(FileTemperature) == 1 DatiRaw = csvread(FileTemperature); [rDR,cDR] = size(DatiRaw); DatiRaw(:,1) = DatiRaw(:,1) + 730000; else rDR = 1; cDR = 1; end textT = 'There are not correction of RSN Link based on temperature filter'; for b = 1:c % Data nodo = 1; for a = 1:r % Nodo % NON considero i dati al di sopra dei 80 °C o al di sotto dei -30 °C! if TempDef_RSN(a,b) > Tmax || TempDef_RSN(a,b) < Tmin cont3 = cont3+1; if b == 1 if isfile(FileTemperature) == 1 RawDate = find(DatiRaw(:,1)<=datenum(datainiRSN)); if isempty(RawDate) == 1 cc = 2; while cc <= c if TempDef_RSN(a,cc) > Tmax || TempDef_RSN(a,cc) < Tmin cc = cc+1; else break end end TempDef_RSN(a,b) = TempDef_RSN(a,cc); angRSN(nodo:nodo+1,b) = angRSN(nodo:nodo+1,cc); else if isnan(DatiRaw(RawDate(end),a+1)) == 0 TempDef_RSN(a,b) = cellstr(num2str(DatiRaw(b+1,RawDate(end)))); angRSN(nodo:nodo+1,b) = cellstr(num2str(DatiRaw(1+a*2:2+a*2,RawDate(end)))); if ErrRSNLink(b,jj) == 0 ErrRSNLink(b,jj) = 0.5; end wardat = 'Temperature data of RSN Link nodes corrected using Raw Data of reference Csv file.'; fprintf(fileID,fmt,wardat); else cc = 2; while cc <= c if TempDef_RSN(a,cc) > Tmax || TempDef_RSN(a,cc) < Tmin cc = cc+1; else break end end TempDef_RSN(a,b) = TempDef_RSN(a,cc); angRSN(nodo:nodo+1,b) = angRSN(nodo:nodo+1,cc); end end else cc = 2; while cc <= c if TempDef_RSN(a,cc) > Tmax || TempDef_RSN(a,cc) < Tmin cc = cc+1; else break end end TempDef_RSN(a,b) = TempDef_RSN(a,cc); end else TempDef_RSN(a,b) = TempDef_RSN(a,b-1); angRSN(nodo:nodo+1,j) = angRSN(nodo:nodo+1,j-1); if ErrRSNLink(b,jj) == 0 ErrRSNLink(b,jj) = 0.5; end end textT = ['' num2str(cont3) ' correction executed for RSN Link - Temperature filter!']; end nodo = nodo+2; end end if rDR~=1 && cDR~=1 && isempty(DatiRaw) == 0 RawDate1 = find(DatiRaw(:,1)<=ARRAYdateRSN(1)); if isempty(RawDate1) == 1 RawDate2 = 1; elseif RawDate1(end) == rDR RawDate2 = find(ARRAYdateRSN(:,1)>DatiRaw(end,1)); else RawDate2 = find(ARRAYdateRSN(:,1)>DatiRaw(RawDate1(end)+1,1)); end else RawDate1 = []; RawDate2 = 1; end if isempty(RawDate1) == 0 && isempty(RawDate2) == 0 Dati = [DatiRaw(1:RawDate1(end),:); ARRAYdateRSN(RawDate2(1):end) TempDef_RSN(:,RawDate2(1):end)' angRSN(:,RawDate2(1):end)']; elseif isempty(RawDate1) == 1 && isempty(RawDate2) == 0 Dati = [ARRAYdateRSN TempDef_RSN' angRSN']; else Dati = DatiRaw; end % Elimino appoggio più vecchio di un mese RawDate3 = find(Dati(:,1)