Trying to combine two IR spectra where x is wavenumber (cm-1) and y is transmittance (0 to 1), having trouble.

7 次查看(过去 30 天)
I am trying to combine two IR spectra from a data base, they are being treated as two components. I want to add them together and plot it and make it into a single spectrum. The problem with this is the number of rows in one set is not the same as the other. The other problem is that the x (wavenumber) values for the two spectra are not the same (spacing is different). I can plot them superimposed, but I want to add them as a linear combination.

回答(2 个)

Voss
Voss 2024-4-16
编辑:Voss 2024-4-16
You'll can interpolate the two spectra onto a common set of wavenumbers. Then you can add the interpolated spectra together. Here's an example:
% some made-up data
x1 = linspace(650,700,6);
y1 = -0.25*sind(x1);
x2 = linspace(645,705,8);
y2 = 0.2*cosd(x2);
% plot the two curves
figure
plot(x1,y1,'.-b',x2,y2,'.-r')
% interpolate each y on a common set of x values,
% in this case the union of the two x vectors
x = union(x1,x2);
y1i = interp1(x1,y1,x);
y2i = interp1(x2,y2,x);
% add the interpolated values together
y = y1i+y2i;
% plot the interpolated values
hold on
plot(x,y1i,'bo',x,y2i,'ro')
% plot the sum
plot(x,y,'o-k')
% make a legend
legend({'y1','y2','y1i','y2i','y1i+y2i'},'Location','best','NumColumns',5)
% vertical lines showing how the x of each original curve
% maps to an x in the sum curve
xline(x,'--','Color',[0.7 0.7 0.7],'HandleVisibility','off');

Star Strider
Star Strider 2024-4-16
It would help to have the data.
The best way is probably to interpolate the longer series to the length of the shorter series. They do not seem to have different names, so I would do something like this, using the resample function —
short_series(:,1) = linspace(651, 900, 397).';
short_series(:,2) = sin(2*pi*(short_series(:,1)-short_series(1,1))*0.01);
long_series = linspace(633, 910, 707).';
long_series(:,2) = sin(2*pi*(long_series(:,1)-long_series(1,1))*0.01);
figure
plot(short_series(:,1), short_series(:,2))
hold on
plot(long_series(:,1), long_series(:,2))
hold off
grid
res2 = resample(long_series(:,2), size(short_series,1), size(long_series,1)).'; % Use 'resample'
res2 = 1x397
0.0031 0.0432 0.0877 0.1311 0.1747 0.2176 0.2603 0.3024 0.3441 0.3849 0.4250 0.4644 0.5028 0.5403 0.5767 0.6120 0.6461 0.6790 0.7106 0.7408 0.7695 0.7968 0.8226 0.8467 0.8693 0.8901 0.9093 0.9267 0.9423 0.9561
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
figure
plot(short_series(:,1), short_series(:,2))
hold on
plot(short_series(:,1), res2)
hold off
grid
Resampling the longer series to the length of the shorter series, instead of the other way round, avoids creating data in the shorter series where none previusly existed.
.

类别

Help CenterFile Exchange 中查找有关 Multirate Signal Processing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by