Compare each spectrum to a reference spectrum.
1 次查看(过去 30 天)
显示 更早的评论
Hi all, say I have a reference signal (spectrum) and assume I have acquired 100 other spectra. I want to compare each of the 100 spectra to the reference spectrum. Is there a code for computing a conformity index by way of comparing each of the 100 spectrum to the reference?
Thank you.
1 个评论
Image Analyst
2023-8-26
There are lots of metrics for comparing curves (signals). For example RMS, Mean absolute deviation (MAD), median absolute deviation, etc. If you have a reference for the "conformity index" that gives the formula for it, then post it. We may have to write it if there is no built-in function for it in MATLAB like there is for rmse and mad.
采纳的回答
Image Analyst
2023-8-27
Try something like this (untested) to compare spectro files to a ref spectro file using RMS. Adapt as needed.
% Specify the folder where the files live.
myFolder = 'C:\Users\yourUserName\Documents\My Pictures';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
% Get a list of all spectroscopy files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.spc'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
%-----------------------------------------------------------------------------------------------------------
% Define the first data file as the reference file.
baseFileName = theFiles(k).name;
refFullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
data = GSSpcRead(refFullFileName);
refWaveNumbers = data.xaxis;
refIntensity = data.data;
%-----------------------------------------------------------------------------------------------------------
% Now compare this to all the others.
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
[folder, baseFileNameNoExtension, extension] = fileparts(fullFileName);
data = GSSpcRead(fullFileName); % Part of the GSTools open source suite of spectro tools.
waveNumbers = data.xaxis;
intensity = data.data;
% If larger wavenumbers are on the left, flip the signals.
if waveNumbers(2) < waveNumbers(1)
waveNumbers = fliplr(waveNumbers);
intensity = fliplr(intensity);
end
plot(waveNumbers, intensity, 'b-', 'LineWidth', 1)
grid on;
xlabel('Wavenumber', 'FontSize', 14);
ylabel('Intensity', 'FontSize', 14);
% Compute difference metric
e(k) = rmse(refIntensity, intensity)
end
GSTools is available here: https://www.mathworks.com/matlabcentral/fileexchange/9938-gstools
2 个评论
Image Analyst
2023-8-27
- You only have to install GSTools if you don't have a reader function for your data. If you already have some function to read in your data, then use that instead of GSTools. If you do use GSTools, it should be added to the path with subfolders.
- I have no idea how you're defining the reference file. I, very arbitrarily, just took the first file to be the reference. If you have some particular file, then just hard code it in or ask the user to specify the reference file with uigetfile
- That was left over pasted code from some boilerplate snippet I had. Basically you can read in the file with whatever function you want that works. Then once you have the data do whatever sort of analysis you want on the signal. Plot it, find spikes, find area under the curve, or whatever it may be.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Signal Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!