Finding and Graphing FWHM (Trouble with Find Function)

14 vues (au cours des 30 derniers jours)
Nichole Peterson
Nichole Peterson le 27 Mar 2020
Commenté : Star Strider le 27 Mar 2020
Hello! After looking at many other FWHM question i've come up with the code below. I have attached that data and the plotted data as well as the data ploted with FWHM.The FWHM is obviously incorrect, it is failing in the find function. hmLeft is giving me 1 and hmRight is giving me 500.Let me know your suggestions!
load data_10micronslit.txt;
xdata10 = data_10micronslit(:,1);
ydata10 = data_10micronslit(:,2);
ymax = max(ydata10);
halfmax = ymax/2;
hmLeft = find(ydata10 >= halfmax, 1, 'first');
hmRight = find(ydata10 >= halfmax, 1, 'last');
figure
plot(xdata10,ydata10,'bo');
xlabel('Wavelength (nm)');
ylabel('Signal');
title('Signal vs Wavelength');
hold on
line([hmLeft hmLeft], [0 halfmax], 'Color', 'r', 'LineWidth', 1);
line([hmRight hmRight], [0 halfmax], 'Color', 'r', 'LineWidth', 1);
line([hmLeft hmRight], [halfmax halfmax], 'color', 'r', 'LineWidth', 1);
hold off

Réponses (1)

Star Strider
Star Strider le 27 Mar 2020
Without ‘data_10micronslit.txt’, it is impossible to provide a specific solution. However the findpeaks function will return the FWHM of each peak it identifies (if you request that it do so). Additionally, the islocalmin and islocalmax functions can help to define the beginning and end of peaks as well as the amplitude of the peaks, and from that you can then use interp1 (twice) to calculate FWHM.
  5 commentaires
Nichole Peterson
Nichole Peterson le 27 Mar 2020
I am also finding that as I use this with othe data sets, like the one i have attached, I am getting the following as an output:
pks =
0.2038
0.2678
0.2966
0.3091
0.3441
0.3543
0.3452
0.3648
0.3676
0.3686
0.3677
0.3686
0.3588
0.3472
0.3454
0.3258
0.3158
0.2393
0.2301
locs =
251
262
267
271
279
281
283
286
288
292
294
296
299
301
303
308
310
328
330
fwhm =
0.6763
0.6262
1.1284
0.5787
0.8014
0.9827
0.7835
0.6270
1.0751
9.1444
0.7254
87.7117
0.6506
0.6384
0.9176
0.6596
0.7704
0.6441
0.7670
Star Strider
Star Strider le 27 Mar 2020
For the second data set, the code changes slightly:
[pks,locs] = findpeaks(ydata10, 'MinPeakProminence',0.05);
[~,~,fwhm,prom] = findpeaks(ydata10, xdata10, 'MinPeakProminence',0.05);
idxrng = [locs-90:locs; locs:locs+90]'; % Calculate ‘x’ Values To Plot ‘FWHM’
xm = xdata10(idxrng);
ym = ydata10(idxrng);
B1 = [xm(:,1), ones(size(xm(:,1)))] \ ym(:,1);
B2 = [xm(:,2), ones(size(xm(:,2)))] \ ym(:,2);
hmv = (pks-ymin)/2;
hm(1) = (hmv+ymin-B1(2))/B1(1);
hm(2) = (hmv+ymin-B2(2))/B2(1);
and produces:
NOTE — There are two findpeaks calls in my code, one to calculate the FWHM value, and the other one to return the data necessary for the plot.

Connectez-vous pour commenter.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by