clear all; clc; % Data loading fname = '14n10056'; % file name [data0,dt,~] = abfload([fname,'.abf']); dt = dt*10^(-6); Fs = 1/dt; % The sampling frequency of the original signal Ldata0=length(data0); T = linspace(0,Ldata0*dt/60,Ldata0); % Time intervals tmin = 7; % [min] tmax = 8; % [min] %if tmax>T(Ldata0) | tmin<0, errordlg('The desired interval transcends the time limits of the series. Enter correct time limits.'); break; end; figure; plot(data0); % plot(T,data0); xlabel('Time [min]'); ylabel('Voltage [mV]'); title(['Full time series from ',fname,'.abf']); % Cutting a piece LoAW = 1; % Length of the averaging window L = floor(tmax*60/dt) - floor(tmin*60/dt); % modLLoAW = mod(L,LoAW); if modLLoAW~=0, L=L+modLLoAW; warning(['ROUND: The length of the original series increased by ',num2str(modLLoAW),' points']); end; clear modLLoAW; xinit = data0(floor(tmin*60/dt)+1:floor(tmin*60/dt)+L)'; %clear data0; tinit = linspace(tmin,tmax,L); %% Time averaging and downsampling Lx = floor(L/LoAW); t1 = linspace(tmin,tmax,Lx); % Assigning values to the beginning of the interval x = zeros(1,Lx); fs = Fs/LoAW; for k=1:Lx x(k) = sum(xinit((k-1)*LoAW+1:k*LoAW))/LoAW; % The tail is not taken into account end; figure; plot(t1,x); title('Downsampled signal'); ylabel('Voltage [mV]'); xlabel('Time [min]')