72 lines
2.1 KiB
Matlab
Executable File
72 lines
2.1 KiB
Matlab
Executable File
% Funzione che definisce accelerazioni (accRSN) e temperature (tempRSN)
|
|
% per i nodi di tipo RSN Link
|
|
|
|
function [TimeRSN,accRSN,tempRSN,ErrRSNLink] = defDatiRSN(MEMS,DatiRSNLink,...
|
|
ErrRSNLink,rRSN,Ndatidespike,FileName)
|
|
|
|
fileID = fopen(FileName,'a');
|
|
fmt = '%s \r';
|
|
text = 'defDatiRSN function started';
|
|
fprintf(fileID,fmt,text);
|
|
|
|
[r,c] = size(DatiRSNLink);
|
|
Ncorr = 0;
|
|
% Elimino gli eventuali Not a Number
|
|
for a = 2:r
|
|
for b = 1:c
|
|
check = isnan(DatiRSNLink(a,b));
|
|
if check == 1
|
|
DatiRSNLink(a,b) = DatiRSNLink(a-1,b);
|
|
ErrRSNLink(a,b) = 1;
|
|
Ncorr = Ncorr+1;
|
|
end
|
|
end
|
|
end
|
|
|
|
text = ['' num2str(Ncorr) ' NaN of RSN Link corrected by defDatiRSN function'];
|
|
fprintf(fileID,fmt,text);
|
|
|
|
% Definisco Data (gg:mm:aaaa hh:mm), Batteria, i 3 dati di accelerometro
|
|
% e la Temperatura per la calibrazione
|
|
TimeRSN = DatiRSNLink(:,1); % data
|
|
accRSN = zeros(r,rRSN*3); % dati accelerometro
|
|
tempRSN = zeros(r,rRSN); % temperatura del nodo
|
|
p = 4; % passo nella definizione dei dati
|
|
s = 1;
|
|
|
|
for i = 1:rRSN
|
|
accRSN(:,s) = DatiRSNLink(:,2+(i-1)*p);
|
|
accRSN(:,s+1) = DatiRSNLink(:,3+(i-1)*p);
|
|
accRSN(:,s+2) = DatiRSNLink(:,4+(i-1)*p);
|
|
s = s+3;
|
|
tempRSN(:,i) = DatiRSNLink(:,5+(i-1)*p);
|
|
if MEMS == 2
|
|
[rT,~] = size(tempRSN);
|
|
for j = 1:rT
|
|
if tempRSN(j,i) > 200
|
|
tempRSN(j,i) = tempRSN(j,i) - 256; % Correzione della temperatura dei nuovi MEMS
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
% il despike NON viene mai eseguito sull'ultimo dato disponibile
|
|
Num_Dati = Ndatidespike; % numero di dati per il despike
|
|
if Num_Dati > r
|
|
Num_Dati = r;
|
|
end
|
|
s = 1;
|
|
for i = 1:rRSN
|
|
% despiking accelerometri
|
|
accRSN(1:end-1,s) = filloutliers(accRSN(1:end-1,s),'linear','movmedian',Num_Dati);
|
|
accRSN(1:end-1,s+1) = filloutliers(accRSN(1:end-1,s+1),'linear','movmedian',Num_Dati);
|
|
accRSN(1:end-1,s+2) = filloutliers(accRSN(1:end-1,s+2),'linear','movmedian',Num_Dati);
|
|
s = s+3;
|
|
end
|
|
|
|
text = 'Data of RSN Link defined correctly';
|
|
fprintf(fileID,fmt,text);
|
|
fclose(fileID);
|
|
|
|
end
|