findpeaks returns wrong width

5 ビュー (過去 30 日間)
AN
AN 2020 年 6 月 28 日
回答済み: Star Strider 2020 年 6 月 28 日
I have a pulse that repeats 4 times with same period (attached oscilloscope data points). I try to isolate the 4 peaks and respective width imposing that the minimum distance between peaks is very close to the inverse of pulse frequency. I use the code pasted below. As you can see in the resulting table, the width of the third peak is the distance (at half prominence) between the signal and a border vertical line that MATLAB consider to separate two neighbour very close peaks. However to avoid this kind of situations I used the clause 'MinPeakDistance' with a value that is smaller but close to the period of the pulses. Nevertheless the function gives a wrong value for the width of the third peak because still a border with a close peak is considered. Why? How can we correct the problem?
function Results=FindPeaks(file)
folder='replace this string with the folder path where the data file is';
D=csvread(strcat(folder,file),11);
A1 = D(:,2);
t1 = D(:,1);
t = t1;
A = A1;
%number of expected peaks:
%frequency of periodic signal
f=7.0025*10^6;
%sampling interval
s=4*10^(-12);
NExp=round(length(t)*s*f);
%plot raw data with all peaks
figure(1)
plot(t,A1);
findpeaks(A,t,'Annotate','extents');
%create a table with relevant peaks, considering FWHM of the
%prominence.
[pks,locs,fwhm,proms]=findpeaks(A,t,'Annotate','extents','MinPeakDistance',1.4*10^(-7),'MinPeakHeight',0.136,'Threshold',1e-7,'MinPeakProminence',0.1);
PkTime = locs;
Results = table(pks, PkTime, fwhm, proms, 'VariableNames',{'Value','PeakTime', 'FWHM', 'Prominence'});
NAct=length(pks);
disp(NExp)
disp(NAct)
end

採用された回答

Star Strider
Star Strider 2020 年 6 月 28 日
If you have the Signal Processing Toolbox, use the pulsewidth function for this:
D = readmatrix('test.csv');
A1 = D(:,2);
t1 = D(:,1);
t = t1;
A = A1;
Idx = ~isnan(t);
t = t(Idx); % Eliminate ‘NaN’ Values
A = A(Idx);
[Width,InitX,FinalX,MidLvl] = pulsewidth(A,t);
figure
plot(t, A)
hold on
plot(InitX, ones(size(InitX))*MidLvl, '>g')
plot(FinalX, ones(size(FinalX))*MidLvl, '<r')
hold off
grid
text(FinalX, ones(size(FinalX))*MidLvl, compose('\\leftarrow %5.3E', Width))
Producing:
The plot simply illustrates the result.
.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by