Why won't fitpeaks work on my data?

4 Ansichten (letzte 30 Tage)
Sam
Sam am 8 Dez. 2021
Beantwortet: Image Analyst am 13 Dez. 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?

Akzeptierte Antwort

Rik
Rik am 8 Dez. 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 Kommentar
Sam
Sam am 13 Dez. 2021
Thank you very much, I was not aware that only the wavelength was required!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 13 Dez. 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);

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by