Plot peaks for each column in a csv then fit a curve.
Ältere Kommentare anzeigen
I am trying to process some data obtained from an oscilloscope. The columns in the csv represent the amplitude of the signal. I expected to see what is in the picture. I want to find the peaks for each signal and then plot the peaks as a function of tau (ms) ranging from 0.1 and up. I'd also like to fit a curve to each line following the exponential function y = a*e(-x/T1) +c, where a is a constant (-2) and T1 is found from the curve. Finding T1 is the ultimate goal of plotting the signals. I have tried a few different methods: here is my most recent attempt and it did not give me anywhere near what I was hoping for:
filename = 'D:\Grad Lab\NMR\Data\T1 Data\compiledT1nolabel.csv';
data = readtable(filename);
y1= table2array(data(:,1));
y2= table2array(data(:,2));
y3= table2array(data(:,3));
y4= table2array(data(:,4));
y5= table2array(data(:,5));
y6= table2array(data(:,6));
y7= table2array(data(:,7));
Fs = 2e-10;
T = 1/Fs;
L = 2500;
t = (0:L-1)*T;
Fn = Fs/2;
Fy1 = fft(y1)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:length(Fv);
figure(1)
plot(Fv, abs(Fy1(Iv))*2)
grid
title("Fourier Transfrom of Mineral Oil Original Signal")
xlabel('Frequency (Hz)')
ylabel('Amplitude')
Fy1dcoc = fft(y1-mean(y1))/L;
figure(2)
plot(Fv, abs(Fy1dcoc(Iv))*2)
grid
title('Fourier Transform of D-C Offset Corrected Signal')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
[Fy1n_max,Iv_max] = max(abs(Fy1dcoc(Iv))*2);
Wp = 2*Fv(Iv_max)/Fn;
Ws = Wp*2;
Rp = 10
Rs = 30;
[n,Wn] = buttord(Wp,Ws,Rp,Rs);
[b,a] = butter(n,Wn);
[SOS,G] = tf2sos(b,a);
S = filtfilt(SOS,G,y1);
figure(4)
plot(t, y1)
hold on
plot(t, S, '-r', 'LineWidth',1.5)
hold off
grid
legend('Mineral oil', "'S'", 'Location', 'N')
title('Original Signal of Mineral Oil and Uncorrupted Signal (S)')
xlabel('Tau (ms)')
ylabel('Amplitude')
I appreciate any help with this!

Akzeptierte Antwort
Weitere Antworten (2)
Image Analyst
am 3 Nov. 2022
0 Stimmen
See attached demo. It will be easy for you to adapt it to your data. Just replace demo data with your actual data.
6 Kommentare
Alex
am 3 Nov. 2022
Image Analyst
am 3 Nov. 2022
The curve does not look like an inverted exponential:

Why do you want to fit the red line to an inverted exponential instead of some sigmoid function, like the rate equation (demo atached)?
Alex
am 3 Nov. 2022
Image Analyst
am 3 Nov. 2022
I just plotted s vs t, and y1 vs t like you did. I'm not sure why the plot I posted above looks so drastically different than @Star Strider's.
Well if s and y1 are your measured values (I doubt it since they're so smooth) and if you say that the theory behind the situation says that it's supposed to be an inverted exponential decay, then use an exponential decay.
I thought that my demo was pretty well commented. Did you have trouble replacing y with s, and x with your t? If you can't do it, I can do it for you. But essentially it's just passing x and y and the theoretical model into fitnlm() - just a few lines of code if you ignore the comments and fancy plotting stuff.
Alex
am 4 Nov. 2022
Image Analyst
am 6 Nov. 2022
There are 7 columns in that workbook. What do the different columns represent? Which column is the x value and which are/is the y value(s)? What column are you trying to fit with an exponential?
Alex
am 4 Nov. 2022
0 Stimmen
3 Kommentare
Viewing the figure —
F = openfig(websave('peaksmineraloil','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1180283/peaksmineraloil.fig'));
I’ll edit my latest Comment to use only the tallest peak and then all peaks greater than 2 ...
.
Alex
am 6 Nov. 2022
Star Strider
am 6 Nov. 2022
As always, my pleasure!
Kategorien
Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


















