Filter löschen
Filter löschen

How to calculate FWHM and rise time?

16 Ansichten (letzte 30 Tage)
Sofia Santos
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!!!
close all;
pasta = '/Users/sofiasantos/Desktop/sinais'; %directory
for k=1:numel(dados)
data_org = importdata(signals,'\t',7); %text file with 7 columms;
EDA= EDA(:,6);
EDAuS=((EDA/2^10)*3)/0.12; %convert to uS
N= length(EDAuS);
fs = 1000;
t = (0:N-1)/fs;
f = (0:N-1)/T;
[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);
disp('amplitude=');disp(amp); %amplitude da SCR
%% RISE TIME (wrong)
disp('rise time='); disp(rise_time);
halfMax = (minimo + maximo) / 2;
index1 = find(EDAuS_filer >= halfMax, 1, 'first');
index2 = find(EDAuS_filer >= halfMax, 1, 'last');
FWHM = index2-index1 + 1;
disp('FWHM='); disp(FWHM);
  3 Kommentare
Sofia Santos
Sofia Santos am 6 Mai 2020
Thank you for trying, I changed the txt file for another that looks like the imagem I posted.
Star Strider
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
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]);
you can get all the informaiton you want from these functions (pulsewidth, risetime, and others):
for k = 1:2
RT{k,:} = risetime(Dr(:,2,k), Dr(:,1,k));
[W,INITCROSS,FINALCROSS,MIDLEV] = pulsewidth(Dr(:,2,k), Dr(:,1,k));
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
Sofia Santos
Sofia Santos am 7 Mai 2020
Thank you very much for your answer!!
It was such a big help! :)
Star Strider
Star Strider am 7 Mai 2020
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)


Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by