MATLAB Answers

Optimal parameters for findpeaks in spectral analysis

8 views (last 30 days)
Yu Li
Yu Li on 2 May 2020
Commented: Sangwoo Yoon on 23 Mar 2021
Hi,
I'm trying to mark all the peaks in a Laser Induced Breakdown Spectroscopy (LIBS) spectrum where peaks are numerous and sharp. I'm playing with all the parameters in findpeaks function. Sadly, 'MinPeakDistance' and 'MinPeakHeight' don't work well due to the nature of the spectrum. Can anybody help to give some ideas for optimising the findpeaks?
%Loading data
FileName = uigetfile('*.txt','Please select spectra:');
fid = fopen(FileName,'rt');
temp = textscan(fid, '%f %f %f %f %f', 'headerLines', 8, 'Delimiter',';','CollectOutput', true);
fclose(fid);
temp= cell2mat(temp);
wavelength = temp(:,1);
raw_counts = temp(:,2); % Background subtracted
dark_counts = temp(:,3); % Background subtracted
counts = temp(:,2)-temp(:,3);
% Finding peaks
[PeakValue, PeakIdx] = findpeaks(counts,'MinPeakDistance',10);
figure(1)
plot(wavelength,counts,'b','LineWidth',2,'Markersize',6)
xlim([364 925])
xlabel('Wavelength (nm)')
ylabel('Intensity (arb. unit)')
text(wavelength(PeakIdx),PeakValue,num2str((1:numel(PeakValue))'))
Many thanks

Accepted Answer

Shubh Sahu
Shubh Sahu on 5 May 2020
I assume that you need the peak which are sharp and with high intensity. I made some changes in your code please have a look. Change threshold according to your need.
%Loading data
FileName = uigetfile('*.txt','Please select spectra:');
fid = fopen(FileName,'rt');
temp = textscan(fid, '%f %f %f %f %f', 'headerLines', 8, 'Delimiter',';','CollectOutput', true);
fclose(fid);
temp= cell2mat(temp);
wavelength = temp(:,1);
raw_counts = temp(:,2); % Background subtracted
dark_counts = temp(:,3); % Background subtracted
counts = temp(:,2)-temp(:,3);
threshold=2500;
% Finding peaks
[PeakValue, PeakIdx] = findpeaks(counts);
PeakIdx=PeakIdx(PeakValue>threshold);
figure(1)
plot(wavelength,counts,'b','LineWidth',2,'Markersize',6)
xlim([364 925])
xlabel('Wavelength (nm)')
ylabel('Intensity (arb. unit)')
x=wavelength(PeakIdx);
y=PeakValue(PeakValue>threshold);
text(x,y,num2str((1:numel(y))'))
the result for the above code is some what like this.
  2 Comments
Sangwoo Yoon
Sangwoo Yoon on 23 Mar 2021
Hi, can I ask a sily question?
I have LIBS data file ,where should I put this file to process LIBS data?
I want to know path to put this LIBS data.
I will appreciate your help.
From hs kim ( laser researcher in Mechanical engineering)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by