How to calculate FWHM and rise time?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Sofia Santos
am 5 Mai 2020
Kommentiert: Star Strider
am 7 Mai 2020
Hello, I have a lot of signals (.txt) with the values of EDA in the six columm of the text files. I need to create a script that opens all the text files and then calculate the amplitude, time of rise and FWHM, like in the photo. The amplitude is ok, but the time of rise and FWHM is wrong.
I hope you can help me, thank you very much!!!
clear
close all;
%%
pasta = '/Users/sofiasantos/Desktop/sinais'; %directory
dados=dir(fullfile(pasta,'*.txt'));
for k=1:numel(dados)
signals=dados(k).name
data_org = importdata(signals,'\t',7); %text file with 7 columms
EDA=data_org.data;
EDA= EDA(:,6);
EDAuS=((EDA/2^10)*3)/0.12; %convert to uS
%%
N= length(EDAuS);
fs = 1000;
T=N/fs;
t = (0:N-1)/fs;
f = (0:N-1)/T;
%% FILTER
[b,a] = butter(6,0.04,'low');
EDAuS_filer = filtfilt(b,a,EDAuS); %filtering signal EDA
%% AMPLITUDE (good)
minimo= min(EDAuS_filer);
maximo= max(EDAuS_filer);
tempo=find(EDAuS==EDAuS);
amp=[];
amp=abs(maximo-minimo);
disp('amplitude=');disp(amp); %amplitude da SCR
%% RISE TIME (wrong)
index_a=find(t==minimo);
disp(index_a);
index_b=find(t==maximo);
rise_time=abs(index_b-index_a);
disp('rise time='); disp(rise_time);
%% LARGURA A MEIA ALTURA (FWHM) (wrong)
halfMax = (minimo + maximo) / 2;
disp(meia_altura);
index1 = find(EDAuS_filer >= halfMax, 1, 'first');
disp(index1);
index2 = find(EDAuS_filer >= halfMax, 1, 'last');
disp(index2);
FWHM = index2-index1 + 1;
disp('FWHM='); disp(FWHM);
end
3 Kommentare
Star Strider
am 6 Mai 2020
The new file does not look at all like the image you posted, any more than the previous one did. It looks like some sort of digital pulse train or digital communications signal rather than the transient in the image you posted. (Fortunately, it has the same strange format.) The pulses also do not have the same phases and on-off lengths, so they appear apparently randomly.
Akzeptierte Antwort
Star Strider
am 6 Mai 2020
The Signal Processing Toolbox has everything you need to analyse your signals.
After reading and reshaping your file so it is possible to work with it:
filename1 = 'opensignals_201505292090_2018-02-25_18-09-25.txt';
filename2 = 'lixa3.1.txt';
txt = fileread(filename1);
strt = strfind(txt,'# EndOfHeader') + numel('# EndOfHeader');
Dc = textscan(txt(strt:end), '%f%f%f%f%f%f%f', 'CollectOutput',1);
D = cell2mat(Dc);
[~,ia,ix] = unique(D(:,1));
fullend = find(D(:,1) == 15,1,'last');
Dr = reshape(D(1:fullend,[1 6 7])', 3, 16, []);
Dr = permute(Dr,[2,1,3]);
for k = 1:2
RT{k,:} = risetime(Dr(:,2,k), Dr(:,1,k));
[W,INITCROSS,FINALCROSS,MIDLEV] = pulsewidth(Dr(:,2,k), Dr(:,1,k));
PW{k,:} = {W,INITCROSS,FINALCROSS,MIDLEV};
end
Add other function calls as necessary to get the information you want. Note how I saved the pulsewidth output to be certain that all of them are saved, even those with empty fields. This allows you to make appropriate assessments of each pulse. (The permute call is not absolutely required. It just makes the matrices a bit more intuitive to work with.)
I tested this code with both files, and it works with both of them.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!