MATLAB: Optimal parameters for findpeaks in spectral analysis

findpeakslibsspectrum

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

Best Answer

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.