[num,txt,raw] = xlsread('Data 1.xlsx') ;
time = num(:,1);
current = num(:,2);
voltage = num(:,3);
samples = length(time);
dt = (time(end)-time(1))/(samples-1);
Fs = 1/dt;
[dvoltage, ddvoltage] = firstsecondderivatives(time,voltage);
figure(1);
subplot(2,1,1),plot(time,voltage,'-b');grid
subplot(2,1,2),plot(time,dvoltage,'-b');grid
dvoltage_max = max(dvoltage(dvoltage>0));
threshold = dvoltage_max/2;
ind = find(dvoltage > threshold);
ind_start = ind(1)-100;
ind_stop = ind(end)-100;
figure(2);
plot(time,voltage,'-b',time(ind_start:ind_stop),voltage(ind_start:ind_stop),'or');grid
function [dy, ddy] = firstsecondderivatives(x,y)
n = length (x);
dy = zeros;
ddy = zeros;
dy(1) = (-3*y(1) + 4*y(2) - y(3)) / 2*(x(2) - x(1));
ddy(1) = (2*y(1) - 5*y(2) + 4*y(3) - y(4)) / (x(2) - x(1))^2;
for i = 2:n-1
dy(i) = (y(i+1) - y(i-1)) / 2*(x(i+1) - x(i-1));
ddy(i) = (y(i-1) - 2*y(i) + y(i+1)) / (x(i-1) - x(i))^2;
end
dy(n) = (y(n-2) - 4*y(n-1) + 3*y(n)) / 2*(x(n) - x(n-1));
ddy(n) = (-y(n-3) + 4*y(n-2) - 5*y(n-1) + 2*y(n)) / (x(n) - x(n-1))^2;
end
Best Answer