Spectrometer signal processing.

37 Ansichten (letzte 30 Tage)
Daniel
Daniel am 2 Dez. 2024 um 13:10
Kommentiert: Star Strider vor etwa 18 Stunden
Hi guys,
I got my spectrometer data in this format save as a notepad file:
I would like to covnert time on the graph strat from 0 seconds and dont know how to covvert that.
Units_11:211
1729167932375 13:25:32.375 405650.13
1729167932475 13:25:32.475 400621.04
1729167932575 13:25:32.575 398764.17
1729167932675 13:25:32.675 400905.63
1729167932775 13:25:32.775 400606.19
1729167932875 13:25:32.875 400141.29
Can someone help me with that? Thank you

Akzeptierte Antwort

Star Strider
Star Strider am 2 Dez. 2024 um 14:12
One approach —
Data = {1729167932375 '13:25:32.375' 405650.13
1729167932475 '13:25:32.475' 400621.04
1729167932575 '13:25:32.575' 398764.17
1729167932675 '13:25:32.675' 400905.63
1729167932775 '13:25:32.775' 400606.19
1729167932875 '13:25:32.875' 400141.29};
T1 = cell2table(Data);
Time = datetime(T1{:,2}, InputFormat='HH:mm:ss.SSS', Format='HH:mm:ss.SSS');
ElapsedTime = seconds(Time - Time(1));
T1 = removevars(T1,2);
T1 = addvars(T1, ElapsedTime, 'Before',2)
T1 = 6x3 table
Data1 ElapsedTime Data3 __________ ___________ __________ 1.7292e+12 0 4.0565e+05 1.7292e+12 0.1 4.0062e+05 1.7292e+12 0.2 3.9876e+05 1.7292e+12 0.3 4.0091e+05 1.7292e+12 0.4 4.0061e+05 1.7292e+12 0.5 4.0014e+05
figure
plot(T1{:,2}, T1{:,3})
grid
title('Spectrometer Plot')
I suspect that you will import your file (not provided) with readtable. This approach should work with it.
.
  5 Kommentare
Daniel
Daniel vor etwa 21 Stunden
like in this picture:
Star Strider
Star Strider vor etwa 18 Stunden
As always, my pleasure!
My first objective here was to save ‘Data’ to ‘Daniel_Spectrometer_Data.mat’ so I did that in MATLAB Online. That makes the rest of this easier. I then downloaded it to my computer and used the ‘papereclip’ icon in the top toolstrip to upload it here. (It might be possible to reference it from MATLAB Drive — where it was originally saved — to here, however that is not obvious to me.)
The data look similar to a photoplysmogram, especially in the context of ‘capillary refill time’. Itt may be inverted, since what appears to me to be the dicrotic notch seems to be on the upslope from the minimum rather than on the downslope from the maximum, where I would normally expect to see it.
I’m not quite certain how to approach this, specifically with respect to what I call the ‘Centre Section’. I ended up just deleting it and linearly interpolating the missing values.
I’m not certain how best to normalise it, so I leave that to you. MATLAB offers several options, the most useful (in my opinion) being the rescale function. I manually (offline in MATLAB Online, using find and the plot GUI) defined the ‘idxm’ indices. There are obviously much better ways to do it, however I do not know what your final result is or how you want to process these data, so I have not explored those options. I have provided a way to calculate and plot a fitted curve as well.
I plotted several different, related plots to explore your data. You do not have to use all of them, and most can be deleted.
If you have the Signal Processing Toolbox, theere aree seeveeeral funcitons that can heelp you process these data, not the least of which being its extensive variety of filters. I have also included a simple Fourier transform function and a bandpass filter and its result, siimply as a demonstration.
Try this —
imshow(imread('Screenshot 202...03 105333.png'))
load('Daniel_Spectrometer_Data.mat')
% whos('-file','Daniel_Spectrometer_Data.mat')
T1 = cell2table(Data);
Time = datetime(T1{:,2}, InputFormat='HH:mm:ss.SSS', Format='HH:mm:ss.SSS');
ElapsedTime = seconds(Time - Time(1));
T1 = removevars(T1,2);
T1 = addvars(T1, ElapsedTime, 'Before',2)
T1 = 1531x3 table
Data1 ElapsedTime Data3 __________ ___________ __________ 1.7292e+12 0 4.0565e+05 1.7292e+12 0.1 4.0062e+05 1.7292e+12 0.2 3.9876e+05 1.7292e+12 0.3 4.0091e+05 1.7292e+12 0.4 4.0061e+05 1.7292e+12 0.5 4.0014e+05 1.7292e+12 0.6 4.0127e+05 1.7292e+12 0.7 4.0286e+05 1.7292e+12 0.8 4.0332e+05 1.7292e+12 0.9 3.9873e+05 1.7292e+12 1 3.9566e+05 1.7292e+12 1.1 3.9753e+05 1.7292e+12 1.2 3.9808e+05 1.7292e+12 1.3 3.9792e+05 1.7292e+12 1.4 3.9998e+05 1.7292e+12 1.5 4.0143e+05
figure
plot(T1{:,2}, T1{:,3})
grid
xlabel('Time (s)')
ylabel('Intensity')
title('Spectrometer Plot')
figure
plot(T1{:,2}, T1{:,3}, '-')
grid
xlabel('Time (s)')
ylabel('Intensity')
title('Spectrometer Plot — Lower Section')
ylim([min(ylim) 4.23E+5])
% xlim([58 102])
figure
plot(T1{:,2}, T1{:,3})
grid
xlabel('Time (s)')
ylabel('Intensity')
title('Spectrometer Plot — Lower Section (Detail)')
xlim([0 10])
ylim([min(ylim) 4.2E+5])
figure
plot(T1{:,2}, T1{:,3})
grid
xlabel('Time (s)')
ylabel('Intensity')
title('Spectrometer Plot — Centre Section')
xlim([60 102])
ylim([4.6E+5 4.72E+5])
SpecData = T1{:,[2 3]};
idxm = [606 1013];
SpecData(idxm(1):idxm(2), 2) = NaN;
SpecData = fillmissing(SpecData, 'linear');
pdeg = 15;
p = polyfit(SpecData(:,1), SpecData(:,2), pdeg);
Warning: Polynomial is badly conditioned. Add points with distinct X values, reduce the degree of the polynomial, or try centering and scaling as described in HELP POLYFIT.
fitline = polyval(p, SpecData(:,1));
figure
plot(SpecData(:,1), SpecData(:,2), DisplayName='Data')
hold on
plot(SpecData(:,1), fitline, '-r', LineWidth=3, DisplayName="Polynomial Fit (Degree = "+pdeg+")")
hold off
grid
xlabel('Time (s)')
ylabel('Intensity')
title('Spectrometer Plot')
legend(Location='best')
[FTs1,Fv] = FFT1(SpecData(:,2), SpecData(:,1));
[pks,locs] = findpeaks(abs(FTs1)*2, MinPeakProminence=500);
PeaksTable = table(Fv(locs),pks, VariableNames={'Frequency','Peak Magnitude'})
PeaksTable = 7x2 table
Frequency Peak Magnitude _________ ______________ 0.0097656 6349.2 0.029297 2405.5 0.048828 1170.6 1.1035 809.13 1.123 980.09 1.1377 1163.1 1.1572 1025.9
figure
plot(Fv, abs(FTs1)*2)
grid
xlabel('Frequency (Hz)')
ylabel('Magnitude (Units)')
xline(0.75, '--k', 'Lower Passband Frequency')
xline(1.5, '--k', 'Upper Passband Frequency')
[SpecDataFilt, df] = bandpass(SpecData(:,2), [0.75 1.5], Fv(end)*2, ImpulseResponse='iir');
figure
plot(SpecData(:,1), SpecDataFilt)
grid
xlabel('Time (s)')
ylabel('Intensity')
title('Spectrometer Plot — Bandpass Filtered')
function [FTs1,Fv] = FFT1(s,t)
% Arguments:
% s: Signal Vector Or Matrix
% t: Associated Time Vector
t = t(:);
L = numel(t);
if size(s,2) == L
s = s.';
end
Fs = 1/mean(diff(t));
Fn = Fs/2;
NFFT = 2^nextpow2(L);
FTs = fft((s - mean(s)) .* hann(L).*ones(1,size(s,2)), NFFT)/sum(hann(L));
Fv = Fs*(0:(NFFT/2))/NFFT;
% Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
Fv = Fv(:);
FTs1 = FTs(Iv,:);
end
.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by