Fit a standard Exponential fit to approximate data
1. For every exponential shaped signals, I want to fit a standard exponential decay fit (I’ve drawn in black) by joining the possible points in the green line. Also I need the count of such fits in the plot along with the duration of each.
2. I want to find out the slope (I’ve drawn in violet colour with a question mark) by drawing a line (I’ve drawn in dark cyan) that connects the starting and ending point of the standard fit. How to do?
Herewith I’ve attached the excel sheet and the code that i’ve tried so far.
clc; close all; clear all;
a=readtable(‘Data.xlsx’);
time=a{2:40000,1};amplitude=a{2:40000,3};
max_peak_values = [];
max_peak_locs = [];
window_size = 1000;
for i = 1:window_size:length(amplitude)
end_index = min(i + window_size – 1, length(amplitude));
segment = amplitude(i:end_index);
[max_peak, loc] = max(segment);
max_peak_values = [max_peak_values; max_peak];
max_peak_locs = [max_peak_locs; loc + i – 1];
end
joined_signal = zeros(size(amplitude));
joined_signal(max_peak_locs) = max_peak_values;
for j = 1:length(max_peak_locs)-1
x = [max_peak_locs(j), max_peak_locs(j+1)];
y = [max_peak_values(j), max_peak_values(j+1)];
interp_x = x(1):x(2);
interp_y = linspace(y(1), y(2), length(interp_x));
joined_signal(interp_x) = interp_y;
end
figure;
plot(time, amplitude, ‘b’);
hold on; grid on
plot(time(max_peak_locs), max_peak_values, ‘ro’);
plot(time, joined_signal, ‘g’);1. For every exponential shaped signals, I want to fit a standard exponential decay fit (I’ve drawn in black) by joining the possible points in the green line. Also I need the count of such fits in the plot along with the duration of each.
2. I want to find out the slope (I’ve drawn in violet colour with a question mark) by drawing a line (I’ve drawn in dark cyan) that connects the starting and ending point of the standard fit. How to do?
Herewith I’ve attached the excel sheet and the code that i’ve tried so far.
clc; close all; clear all;
a=readtable(‘Data.xlsx’);
time=a{2:40000,1};amplitude=a{2:40000,3};
max_peak_values = [];
max_peak_locs = [];
window_size = 1000;
for i = 1:window_size:length(amplitude)
end_index = min(i + window_size – 1, length(amplitude));
segment = amplitude(i:end_index);
[max_peak, loc] = max(segment);
max_peak_values = [max_peak_values; max_peak];
max_peak_locs = [max_peak_locs; loc + i – 1];
end
joined_signal = zeros(size(amplitude));
joined_signal(max_peak_locs) = max_peak_values;
for j = 1:length(max_peak_locs)-1
x = [max_peak_locs(j), max_peak_locs(j+1)];
y = [max_peak_values(j), max_peak_values(j+1)];
interp_x = x(1):x(2);
interp_y = linspace(y(1), y(2), length(interp_x));
joined_signal(interp_x) = interp_y;
end
figure;
plot(time, amplitude, ‘b’);
hold on; grid on
plot(time(max_peak_locs), max_peak_values, ‘ro’);
plot(time, joined_signal, ‘g’); 1. For every exponential shaped signals, I want to fit a standard exponential decay fit (I’ve drawn in black) by joining the possible points in the green line. Also I need the count of such fits in the plot along with the duration of each.
2. I want to find out the slope (I’ve drawn in violet colour with a question mark) by drawing a line (I’ve drawn in dark cyan) that connects the starting and ending point of the standard fit. How to do?
Herewith I’ve attached the excel sheet and the code that i’ve tried so far.
clc; close all; clear all;
a=readtable(‘Data.xlsx’);
time=a{2:40000,1};amplitude=a{2:40000,3};
max_peak_values = [];
max_peak_locs = [];
window_size = 1000;
for i = 1:window_size:length(amplitude)
end_index = min(i + window_size – 1, length(amplitude));
segment = amplitude(i:end_index);
[max_peak, loc] = max(segment);
max_peak_values = [max_peak_values; max_peak];
max_peak_locs = [max_peak_locs; loc + i – 1];
end
joined_signal = zeros(size(amplitude));
joined_signal(max_peak_locs) = max_peak_values;
for j = 1:length(max_peak_locs)-1
x = [max_peak_locs(j), max_peak_locs(j+1)];
y = [max_peak_values(j), max_peak_values(j+1)];
interp_x = x(1):x(2);
interp_y = linspace(y(1), y(2), length(interp_x));
joined_signal(interp_x) = interp_y;
end
figure;
plot(time, amplitude, ‘b’);
hold on; grid on
plot(time(max_peak_locs), max_peak_values, ‘ro’);
plot(time, joined_signal, ‘g’); exponential fit MATLAB Answers — New Questions