Why won't fitpeaks work on my data?

4 visualizaciones (últimos 30 días)
Sam
Sam el 8 de Dic. de 2021
Respondida: Image Analyst el 13 de Dic. de 2021
Hi, I have a Raman spectrum in a .txt file, with one column of my x axis values and another with my y axis. I am trying to write a script so I can conduct bulk analysis of lots of spectra, but I am struggling!
I am using the following code to read in my data.
data = importdata('RamanData.txt');
plot(data);
[pks,loc] = findpeaks(data);
findpeaks(data)
MATLAB plots my data (alongside a diagonal line?)
I also get these errors:
Error using findpeaks
Expected Y to be a vector.
Error in findpeaks>parse_inputs (line 199)
validateattributes(Yin,{'double','single'},{'nonempty','real','vector'},...
Error in findpeaks (line 136)
= parse_inputs(isInMATLAB,Yin,varargin{:});
Error in FindPeak (line 3)
[pks,loc] = findpeaks(data);
Is this an error in my data set up, script or should I be using a different function?

Respuesta aceptada

Rik
Rik el 8 de Dic. de 2021
I guess boldly:
Your txt file contains both the magnitude and the wavelength. The plot function gave you a plot with two lines: one with the magnitude and one with the wavelenghts. That is why your x-axis is 0-1700, instead of 470(?) to 2000 nm(?).
You need to separate the matrix that importdata returned into the two respective vectors. Then you can supply the wavelength only to findpeaks.
You can confirm this by looking at the size of data.
  1 comentario
Sam
Sam el 13 de Dic. de 2021
Thank you very much, I was not aware that only the wavelength was required!

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 13 de Dic. de 2021
It's the magnitude that is required if you want to get indexes.
data = importdata('RamanData.txt');
wavelengths = data(:, 1); % Wavelengths in column 1
magnitude = data(:, 2); % Signal magnitude in column 2
plot(wavelengths, magnitude, 'b-', 'LineWidth', 2);
[peakValues, indexesOfPeaks] = findpeaks(magnitude);
wavelengthsOfPeaks = wavelengths(indexesOfPeaks);
Or specify wavelength as the second input if you want wavelength for location instead of indexes.
data = importdata('RamanData.txt');
wavelengths = data(:, 1); % Wavelengths in column 1
magnitude = data(:, 2); % Signal magnitude in column 2
plot(wavelengths, magnitude, 'b-', 'LineWidth', 2);
[peakValues, wavelengthsOfPeaks] = findpeaks(magnitude, wavelengths);

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by