diff --git a/AF_trapezoid_integration_v2.m b/AF_trapezoid_integration_v2.m new file mode 100644 index 0000000..9a0d32f --- /dev/null +++ b/AF_trapezoid_integration_v2.m @@ -0,0 +1,39 @@ +%initializing + +d_area = 0; + +% d = your data +% enter your values here: +d_start = 150; +d_end = 600; + +%num_intervals = 50; + +%interval = ceil( (d_end-d_start)/num_intervals ); + +interval = 1; + +d_b = d - d(d_start); %subtracting baseline + +x = (d_start : interval : d_end)'; +y = d_b (x); + +%plotting +figure; hold on +plot (d); + +%AF trapezoid integration +for i = 1 : size(x)-1 + d_area (i) = (x(i+1) - x(i)) * ((y(i) + y(i+1))/2); + + %plotting trapezoid + t_x = [x(i), x(i), x(i+1), x(i+1)]; + t_y = [0, y(i), y(i+1), 0]; + + fill (t_x, t_y, 'r'); +end + +AF_area = sum(d_area) + +%trapz integration +trapz_area = trapz(x,y) diff --git a/EPSC non-silencing.fig b/EPSC non-silencing.fig new file mode 100644 index 0000000..8b6f0ba Binary files /dev/null and b/EPSC non-silencing.fig differ diff --git a/IclTrace.m b/IclTrace.m new file mode 100644 index 0000000..e802036 --- /dev/null +++ b/IclTrace.m @@ -0,0 +1,12 @@ +classdef IclTrace + %ICLTRACE Summary of this class goes here + % Detailed explanation goes here + + properties + end + + methods + end + +end + diff --git a/anal_events.m b/anal_events.m index 7479cb1..e33de2c 100644 --- a/anal_events.m +++ b/anal_events.m @@ -1,3 +1,5 @@ + + %% get the data, init constants clear all; @@ -22,6 +24,7 @@ % find peak at min (stimulus start : peak_end) figure; hold on; +xlim([data_start, data_finish]) grey=[.8,.8,.8]; for i = 1 : size (fig_y) @@ -33,77 +36,52 @@ % data_peaks_x(i) = find (data_sweeps{i} == data_peaks_y(i)); data_peaks_x(i) = data_peaks_x(i) + stim_start; + plot (data_sweeps{i}, 'Color', grey); plot (data_peaks_x(i), data_peaks_y(i), 'ob'); %% finding the onset - data_pos = pos * data_sweeps{i}; - - d_smooth = smooth (data_pos, smooth_deg, 'loess'); - diff_s = diff (d_smooth); - - min_diff = std (diff_s(data_start:stim_start)); - - - diff_pts = find (diff_s (stim_start:peak_end) > min_diff); - - if diff_pts - event_onset_x (i) = diff_pts(1,1) + stim_start; - event_onset_y (i) = data_sweeps{i}(event_onset_x(i)); - - plot (event_onset_x (i), event_onset_y (i), 'ko'); - else - event_onset_x (i) = nan; - event_onset_y (i) = nan; - end + [event_onset_x(i), event_onset_y(i)] = find_onset (data_sweeps{i}, pos); + plot (event_onset_x(i), event_onset_y(i), 'ob'); end +%% average and plot data + +% figure(); hold on; + avg_peak_x = mean (data_peaks_x); avg_peak_y = mean (data_peaks_y); plot (avg_peak_x, avg_peak_y, 'bs'); + avg_onset_x = nanmean (event_onset_x); avg_onset_y = nanmean (event_onset_y); plot (avg_onset_x, avg_onset_y, 'ks'); -%% plotting the data and the average trace - dim = ndims(data_sweeps{2}); %# Get the number of dimensions for your arrays M = cat(dim+1,data_sweeps{:}); %# Convert to a (dim+1)-dimensional matrix y_mean = mean(M,dim+1); %# Get the mean across arrays plot (y_mean, 'r'); -[y_mean_peak_y y_mean_peak_x] = min (y_mean(stim_start:peak_end)); +[y_mean_peak_y, y_mean_peak_x] = min (y_mean(stim_start:peak_end)); y_mean_peak_x = y_mean_peak_x + stim_start; -% y_mean_peak_x = find (y_mean==y_mean_peak_y); +plot (y_mean_peak_x, y_mean_peak_y, 'or'); +[y_mean_onset_x y_mean_onset_y] = find_onset(y_mean, pos); +plot (y_mean_onset_x, y_mean_onset_y, 'or'); -plot (y_mean_peak_x, y_mean_peak_y, 'or'); - -% data_pos = pos * y_mean(stim_start:data_finish); - - data_pos = pos * y_mean(); - - d_smooth = smooth (data_pos, smooth_deg, 'loess'); - diff_s = diff (d_smooth); - - min_diff = std (diff_s(data_start:stim_start)); - - diff_pts = find (diff_s > min_diff); - - event_onset_x = diff_pts(1,1) + stim_start; - event_onset_y = y_mean(event_onset_x); - - plot (event_onset_x, event_onset_y, 'rs'); -%% set axis limits +%% results -xlim([data_start, data_finish]) \ No newline at end of file +avg_onset_x +avg_onset_y +avg_peak_x +avg_peak_y \ No newline at end of file diff --git a/avg_fig_traces.m b/avg_fig_traces.m new file mode 100644 index 0000000..873afa3 --- /dev/null +++ b/avg_fig_traces.m @@ -0,0 +1,30 @@ +%% Averages traces on a selected figure + +data_b = {}; + + +h = findobj(gca,'Type','line'); +fig_x=get(h,'Xdata'); +fig_y=get(h,'Ydata'); + +data_start = 1900; +stim_start = 2000; +data_finish = 2600; + + +%subtract baseline +figure; hold on; +grey=[.8,.8,.8]; + +for i = 1 : size (fig_y) + base = mean (fig_y{i}(data_start:stim_start)); + data_b{i} = fig_y{i} - base; + + plot (data_b{i}(data_start:data_finish), 'Color', grey); +end + +dim = ndims(data_b{2}); %# Get the number of dimensions for your arrays +M = cat(dim+1,data_b{:}); %# Convert to a (dim+1)-dimensional matrix +y_mean = mean(M,dim+1); %# Get the mean across arrays + +plot (y_mean (data_start:data_finish), 'r'); \ No newline at end of file diff --git a/avgcurves.m b/avgcurves.m new file mode 100644 index 0000000..6f180b2 --- /dev/null +++ b/avgcurves.m @@ -0,0 +1,133 @@ +function avgCurve = avgcurves( inputX, inputY ) +%avgcurves Takes (x,y) curve, averages y for any repeating +% x values. + + + + %% sort inputX and inputY into a cell% + tempCell = sortvectors( inputX, inputY ); + + srtCurve.x = tempCell{1}; + srtCurve.y = tempCell{2}; + + +%% initializing newCurve and temp + % pre-allocating empty values for newCurve + newCurve.x = zeros(length(inputX),1); + newCurve.y = zeros(length(inputY),1); + newCurve.std = zeros(length(inputY),1); + newCurve.stdErr = zeros(length(inputY),1); + + % initializing the first new X and Y + newCurve.x(1) = srtCurve.x(1); + newCurve.y(1) = srtCurve.y(1); + + %temp is a buffer vector holding all y-val's that have the same x-val + temp = newCurve.y(1); + + uniqI = 1; %the index of the current unique x,y + +%% create averaged curve + for i = 2 : length( srtCurve.x ) %from the second value : last + + if srtCurve.x(i) == srtCurve.x(i-1) %if two pts in a row are the same + +% if temp ~= inf + temp = [temp; srtCurve.y(i)]; %add new point to temp +% else +% temp = srtCurve.y(i); +% end + + %calculating y (avg), std and stdErr for the current x + newCurve.y(uniqI) = mean(temp(~isnan(temp))); %new y-value is mean(temp) +% newCurve.calcStd (uniqI, temp); + + newCurve.std(uniqI) = std(temp(~isnan(temp))); + newCurve.stdErr(uniqI) = std(temp(~isnan(temp))) / sqrt( length(temp(~isnan(temp))) ); + + else + uniqI = uniqI + 1; %update uniqI + + %update newCurve + newCurve.x(uniqI) = srtCurve.x(i); + newCurve.y(uniqI) = srtCurve.y(i); +% newCurve = newCurve.calcStd (uniqI, temp); + + newCurve.std(uniqI) = std(temp(~isnan(temp))); + newCurve.stdErr(uniqI) = std(temp(~isnan(temp))) / sqrt( length(temp(~isnan(temp))) ); + + temp = newCurve.y(uniqI); %update temp to the next value + + end %if + + end %for + + %delete zero values by making newCurve.x and .y go only until uniqI + +% curve = {newCurve.x newCurve.y newCurve.std newCurve.stdErr}; +% +% curve = curve(1:uniqI,1); +% +% [newCurve.x newCurve.y newCurve.std newCurve.stdErr] = curve{1,:}; +% + + % a little cell magic + + % structure names + curveHeadings = {'x' 'y' 'std' 'stdErr'}; + + %conversting to a matrix + curve_mat = cell2mat( struct2cell(newCurve)' ); + + %assigining non-zero values to a cell + shortCurve_cell = num2cell( curve_mat(1:uniqI,:), 1)'; + + %converting back to a structure + newCurve = cell2struct (shortCurve_cell, curveHeadings, 1); + + + + + +% newCurve.x = newCurve.x(1:uniqI,1); +% newCurve.y = newCurve.y(1:uniqI,1); +% newCurve.std = newCurve.std(1:uniqI,1); +% newCurve.stdErr = newCurve.stdErr(1:uniqI,1); +%% plotting results + + % Create axes +% axes('Position',[0.13 0.1126 0.775 0.815]); +% box('on'); +% hold('all'); + + + %plot raw data and averaged data% + %plot (srtCurve.x, srtCurve.y, 'k.', newCurve.x,newCurve.y, '-ko'); + + plot (newCurve.x,newCurve.y, '-ko'); hold on; + %plot error bars% +% +% stdErr( length(srtCurve) ) = []; +% +% for i=1: length(strCurve.x) +% stdErr = +% +% end + + + % stdErr = 10 * rand (1, length(newCurve.x) ); %generate random stdErr + + + errorbar(newCurve.x, newCurve.y, newCurve.stdErr,'LineStyle','none','Color',[0 0 1]); + + +%% output + + avgCurve = newCurve; + + +end + +% function newCurve = calcStd(uniqI, temp) +% +% end \ No newline at end of file diff --git a/compare_v_th.m b/compare_v_th.m new file mode 100644 index 0000000..df46a23 --- /dev/null +++ b/compare_v_th.m @@ -0,0 +1,29 @@ +function output = compare_v_th (current_cell) + +% current_cell = cell_05; + + for i = 1:min (size(current_cell)) + + sample = current_cell(:,i); + + findAPs(sample); + APdata = find_dv_peaks (sample); + AP_th = find_v_th (APdata.APs); + + total_th = []; + for j = 1:length (AP_th) + total_th = [total_th; AP_th(j).v]; + end + + mean_th(i,1) = mean (total_th); + f = find_v_th ({APdata.mean_AP}); + mean_th_mAP(i,1) = f.v; + end + + output.mean_th = mean_th; + output.mean_th_mAP = mean_th_mAP; + + figure; hold on; + + plot (output.mean_th, '.'); plot (output.mean_th_mAP, 'r.'); +end \ No newline at end of file diff --git a/dt_peaks.m b/dt_peaks.m new file mode 100644 index 0000000..c41b2c9 --- /dev/null +++ b/dt_peaks.m @@ -0,0 +1,42 @@ +barrage = AP_trace(21050:21100); + +d1 = diff (barrage, 1); +d3 = diff (barrage, 3); + +i_pos_d1 = find (d1>0); +pos_d1 = d1(i_pos_d1); +pos_d1_v = barrage(i_pos_d1); + +pos_d3 = d3(i_pos_d1(2:length(i_pos_d1)-2)); +[sorted, i_s] = sort (-pos_d3); sorted = -sorted; +local_max = sorted(2); +i_local_max = i_s(2); + + +% pos_d3_v = barrage(i_pos_d1); + + +figure; hold on; + +plot (d1-0.05, '-rx'); +% plot (i_pos_d1, pos_d1, 'ro'); +plot (pos_d3, '-rx'); +plot (i_local_max, local_max, 'k^'); +plot (i_local_max, barrage(i_local_max), 'or'); + +plot (barrage, '-x'); +% plot (i_pos_d1, pos_d1_v, 'ro'); + + +% [peaks, i] = findpeaks(d); + +% max_peaks = findpeaks (peaks); +% +% [~,i_max] = ismember (max_peaks, d); +% +% figure; hold on; +% plot(i,peaks, 'og'); +% plot(i_max-2,max_peaks,'og'); +% +% plot(barrage); +% plot(d, '-xr'); \ No newline at end of file diff --git a/findAPs.m b/findAPs.m new file mode 100644 index 0000000..cb92e71 --- /dev/null +++ b/findAPs.m @@ -0,0 +1,20 @@ +function [output] = findAPs(input_trace) + + barrage = input_trace; %select APs to analyze from the trace + + %[peaks, i_p] = findpeaks(barrage); %if you want to analyze peaks + + [~, i_t] = findpeaks (-barrage); %obtain x-values for troughs + + APs = cell(length(i_t), 1); %allocate empty cell space + + %adding first and last pts of barrage to minima: + minima = [1; i_t; length(barrage)]; + + %separating APs: + for i = 1:length(minima)-1 + APs{i} = barrage(minima(i):minima(i+1)); + end + + output = APs; %return a cell of AP traces + end \ No newline at end of file diff --git a/findProperties.m b/findProperties.m new file mode 100644 index 0000000..ff5115c --- /dev/null +++ b/findProperties.m @@ -0,0 +1,87 @@ + function output = findProperties( current_cell ) + %FINDAHP Summary of this function goes here + % Detailed explanation goes here + + total_AP = {}; + ap_i = 0; + trough = []; + total_v_th = []; + AHP = []; + mean_AP = []; + +% figure; hold on; + + for cell_i = 1: min (size (current_cell) ) + sample = current_cell(:,cell_i); + p = find_dv_peaks (sample); + + AP_ths = find_v_th (p.APs); + + mean_AP {cell_i, 1} = p.mean_AP; + + total_th = []; + troughs = []; + max_dv = []; + min_dv = []; + + for j = 1:length (p.APs) + [min_y, ~] = min (p.APs{j}); + troughs (j,1) = min_y; + + total_th = [total_th; AP_ths.v_th(j).v]; + max_dv = [max_dv; AP_ths.max_dv{j}]; + min_dv = [min_dv; AP_ths.min_dv{j}]; + end + + mean_barrage_AHPs(cell_i,1) = mean (total_th - troughs); + mean_barrage_ths (cell_i,1) = mean (total_th); + mean_max_dv (cell_i, 1) = mean (max_dv); + mean_min_dv (cell_i, 1) = mean (min_dv); + + if (~isnan(max_dv)) + max_max_dv (cell_i, 1) = max (max_dv); + else + max_max_dv (cell_i, 1) = nan; + end + + if (~isnan(min_dv)) + max_min_dv (cell_i, 1) = max (min_dv); + else + max_min_dv (cell_i, 1) = nan; + end + end + + pos_mean_AP = mean_AP (cellfun(@(V) any(~isnan(V(:))), mean_AP)); + + for i = 1:length(pos_mean_AP) + pos_AP_mat (:,i) = pos_mean_AP{i}; + end + + mean_tot_AP = mean (pos_AP_mat')'; + + + pos_AHPs = mean_barrage_AHPs (~isnan (mean_barrage_AHPs) ); + mean_cell_AHP = mean (pos_AHPs); + + pos_v_th = mean_barrage_ths (~isnan (mean_barrage_ths) ); + mean_cell_v_th = mean (pos_v_th); + + output.mean_AP = mean_AP; +% output.mean_pos_AP = mean_pos_AP; + output.mean_tot_AP = mean_tot_AP; + + output.AHP.raw = mean_barrage_AHPs; + output.AHP.pos = pos_AHPs; + output.AHP.mean = mean_cell_AHP; + + output.v_th.raw = mean_barrage_ths; + output.v_th.pos = pos_v_th; + output.v_th.mean = mean_cell_v_th; + + output.max_dv.max = max_max_dv; + output.max_dv.mean = mean_max_dv; + + output.min_dv.max = max_min_dv; + output.min_dv.mean = mean_min_dv; +end + diff --git a/find_dv_peaks.m b/find_dv_peaks.m new file mode 100644 index 0000000..92d20c2 --- /dev/null +++ b/find_dv_peaks.m @@ -0,0 +1,73 @@ +function output = find_dv_peaks(sample) + + + barrage = sample(19000:31000); + + [p, p_i] = findpeaks(barrage); + + pos_i = p > 0; + + pos_peak_v = p(pos_i); + pos_peak_x = p_i(pos_i); + + % figure; hold on; + % plot (barrage); + % plot (p_i, barrage(p_i), 'or'); + % plot (pos_peak_x, pos_peak_v, '.r'); + + + d1 = diff (barrage, 1); + temp_peaks = findpeaks (d1); + + max_d1 = temp_peaks(temp_peaks>0.005); + + + mean_max_d1 = mean (max_d1); + median_max_d1 = median (max_d1); + max_max_d1 = max (max_d1); + + % {'mean_max_d1', 'median_max_d1', 'max_max_d1'; + % mean_max_d1, median_max_d1, max_max_d1} + + [~,max_d1_x] = ismember (max_d1, d1); + APs = []; + % find APs + APs = cell (length(pos_peak_x),1); + +% figure; hold on; + + for i = 1: length (pos_peak_x) + APs{i,1} = barrage (pos_peak_x(i)-20:pos_peak_x(i)+15)'; +% plot (APs{i,1}, 'b'); + end + + ap_matrix = []; + + mean_AP = []; + median_AP = []; + + % if (APs) + for i = 1:length (APs) + ap_matrix (:,i) = APs{i,1}; + end + + mean_AP = mean (ap_matrix')'; + median_AP = median (ap_matrix')'; + % end + + output.APs = APs; + output.ap_matrix = ap_matrix; + output.mean_AP = mean_AP; + output.median_AP = median_AP; + + % plot (mean_AP, 'r'); + % plot (median_AP, 'g'); + + % + % figure; hold on; + % subplot(2,1,1), plot (barrage), hold on, plot (max_d1_x, barrage(max_d1_x), '.r'); axis tight; + % subplot(2,1,2), plot (max_d1_x, max_d1, '.'); title 'max dv/dt'; + % + % figure; hold on; plot (d1); plot (max_d1_x, d1(max_d1_x), 'ro'); + % figure; plot (max_d1, '.'); +end \ No newline at end of file diff --git a/find_event_onset.m b/find_event_onset.m new file mode 100644 index 0000000..792438f --- /dev/null +++ b/find_event_onset.m @@ -0,0 +1,21 @@ +% Shortcut summary goes here +% click on a trace + +pos = 1; %reverse for negative traces +start = 1900; +finish = 4600; + +d = get(gco,'ydata')'; + +data = pos * d(start:finish); + +min_diff = 1; + +d_s = smooth (data, 0.01, 'loess'); +diff_s = diff (d_s); +diff_pts = find (diff_s > min_diff); + +figure; hold on; +plot (data); +plot (d_s, 'r'); +plot (diff_pts(1,1), data (diff_pts(1,1)), 'ok'); \ No newline at end of file diff --git a/find_mEPSCs.m b/find_mEPSCs.m new file mode 100644 index 0000000..a925dcc --- /dev/null +++ b/find_mEPSCs.m @@ -0,0 +1,98 @@ +function output_traces = find_mEPSCs( input_data, start_data, finish_data ) +%FIND_MEPSCS Detects mEPSCs and labels them on a graph + +data = input_data(start_data:finish_data); %parse data to be analyzeed in + +diff_thresh = 2; +amp_thresh = 3; +decay = 30; %% minimum accepted decay x 0.01 msec; decay = 30 => 0.3 msec +% may have to change these values dep. on your data + +mini_start = []; +peaks = []; +peaks_i = []; + +mini_trace = {}; + +diff_data = diff (data); +mean_data = mean (data); +std_data = std (data); +mean_diff = mean (diff_data); +std_diff = std (diff_data); + + +%% find indexes of local minima of diff_data that are lower than threshold*std +loc_max_diff_i = find (diff_data < mean_diff - diff_thresh*std_diff); + +%% remove closely spaced peaks + +%check for closely spaced double-peaks +n = numel (loc_max_diff_i); +for j = 2:n + if (loc_max_diff_i(j) - loc_max_diff_i(j-1)) < decay + %%remove that peak + loc_max_diff_i (j) = nan; + end +end + +%% +for i = 1:length (loc_max_diff_i) + %check for end of data + if loc_max_diff_i(i) + decay + 10 < length (data) + + %find minimum ("peak") and its index + local_data = data(loc_max_diff_i(i): loc_max_diff_i(i)+decay); + local_peak = min (local_data); + local_peak_i = find (local_data == local_peak) + loc_max_diff_i(i)-1; + + % if the peak doesn't decay too quickly + if data (local_peak_i+decay) < data (loc_max_diff_i(i)) +% mini_start = [mini_start; loc_max_diff_i(i)]; + + %if the peak is below mean - std * threshold + if local_peak < mean_data - std_data * amp_thresh + + %update the peak and peak index array + peaks = [peaks; local_peak]; + peaks_i = [peaks_i; local_peak_i]; + + % sequester the trace + mid_rise = (loc_max_diff_i(i) + local_peak_i) / 2; + mini_trace {length(mini_trace)+1} = data(local_peak_i-decay : local_peak_i+decay*1.5); + end + end + + end +end + +%% average mini's + +trace_array = cell2mat (mini_trace); +avg_trace = mean (trace_array'); +avg_trace = (0 - avg_trace(1)) + avg_trace; + + +%% print out results + +figure; hold on; +plot (data, 'r'); +% plot (diff_data, 'b'); +% plot (loc_max_diff_i+1, data(loc_max_diff_i), 'bo'); +plot (peaks_i, data(peaks_i), 'ko'); + + + +output_traces = mini_trace; + + +figure; hold on; + +for i = 1 : length (mini_trace) + new_trace = (0 - mini_trace{i}(1)) + mini_trace{i}; + plot (new_trace); +end + +plot (avg_trace, 'r', 'LineWidth',1.5); + +end + diff --git a/find_mean_AHP.m b/find_mean_AHP.m new file mode 100644 index 0000000..fab8fb8 --- /dev/null +++ b/find_mean_AHP.m @@ -0,0 +1,29 @@ +current_cell = cell_05; + + for cell_i = 1: min (size (current_cell) ) + sample = current_cell(:,cell_i); + p = find_dv_peaks (sample); + + AP_ths = find_v_th (p.APs); + + + total_th = []; + troughs = []; + max_dv = []; + + for j = 1:length (p.APs) + [min_y, ~] = min (p.APs{j}); + troughs (j,1) = min_y; + + total_th = [total_th; AP_ths.v_th(j).v]; + max_dv = [max_dv; AP_ths.max_dv{j}]; + end + + mean_barrage_AHPs(cell_i,1) = mean (total_th - troughs); + mean_barrage_ths (cell_i,1) = mean (total_th); + mean_max_dv (cell_i, 1) = mean (max_dv); + + + max_max_dv (cell_i, 1) = max (max_dv); + end + \ No newline at end of file diff --git a/find_onset_old.m b/find_onset_old.m new file mode 100644 index 0000000..06c580c --- /dev/null +++ b/find_onset_old.m @@ -0,0 +1,40 @@ +function [ output_x, output_y ] = find_onset(input_data, pos) +%FIND_ONSET Summary of this function goes here +% Detailed explanation goes here + + stim_start = 2000; + peak_end = 2110; + data_start = 1900; + data_finish = 2600; + + smooth_deg = 0.001; + + data_pos = pos * input_data; + d_smooth = smooth (data_pos, smooth_deg, 'loess'); + + diff_s = diff (d_smooth); + min_diff = std (diff_s(data_start:stim_start)); + + [y_max x_max] = max (diff_s (stim_start:peak_end)); + x_max = x_max + stim_start; + + diff_cut = diff_s (stim_start:x_max); + rev_diff_cut = flipud (diff_cut); + + rev_x = find (rev_diff_cut < min_diff); + onset_x = size (rev_diff_cut) - rev_x(1,1) + stim_start; + onset_x = onset_x(1,1); + + output_x = onset_x; + output_y = input_data(onset_x); + + grey=[.8,.8,.8]; + + +% figure; hold on; plot (input_data, 'Color', grey); +% plot (d_smooth*pos, 'r'); +% plot (onset_x, input_data(onset_x), 'or'); +% xlim([data_start, data_finish]); + +end + diff --git a/find_thr.m b/find_thr.m new file mode 100644 index 0000000..ff33f6b --- /dev/null +++ b/find_thr.m @@ -0,0 +1,16 @@ +load('C:\Users\Alex\Documents\MATLAB\data\temp\ap_trace.mat'); + +barrage = AP_trace(21000:21050); + +d1 = diff (barrage, 1); +d3 = diff (barrage, 3); + +figure; hold on; +plot (barrage); +plot (d3, '-xr'); + +v_th_i = find (d1<-0.001, 1, 'first')-1; %offset by one b/c of diff +v_th = barrage(v_th_i); +d_th = d1(v_th_i); + +plot (v_th_i, v_th, 'or'); \ No newline at end of file diff --git a/find_v_th.m b/find_v_th.m new file mode 100644 index 0000000..4344af6 --- /dev/null +++ b/find_v_th.m @@ -0,0 +1,28 @@ +function [output] = find_v_th (APs) + v_th = struct([]); + max_dv = {}; + min_dv = {}; + + for i = 1:length(APs) + dv = diff (APs{i}, 1); %first derivative + + %find first instance of dv/dt>0.001: + v_th_i = find (dv>0.01, 1, 'first')-1; %offset by one b/c of diff + + if (v_th_i) %if v-threshold was found, enter voltage and x vals + v_th(i).v = APs{i}(v_th_i); + v_th(i).x = v_th_i; + max_dv{i,1} = max (dv); + min_dv{i,1} = min (dv); + else + v_th(i).v = nan; + v_th(i).x = nan; + max_dv{i,1} = nan; + min_dv{i,1} = nan; + end + end + + output.v_th = v_th; + output.max_dv = max_dv; + output.min_dv = min_dv; +end diff --git a/merge_figures.m b/merge_figures.m new file mode 100644 index 0000000..edfea72 --- /dev/null +++ b/merge_figures.m @@ -0,0 +1,15 @@ +% merge two figures + +fig1_name = 'TC_input_PT.fig'; +fig2_name = 'TC_input_IT_avg.fig'; + +fig1 = open(fig1_name); +fig2 = open(fig2_name); + +ax1 = get(fig1, 'Children'); +ax2 = get(fig2, 'Children'); + +for i = 1 : numel(ax2) + ax2Children = get(ax2(i),'Children'); + copyobj(ax2Children, ax1(i)); +end \ No newline at end of file diff --git a/plotAPs.m b/plotAPs.m new file mode 100644 index 0000000..34b0ce5 --- /dev/null +++ b/plotAPs.m @@ -0,0 +1,18 @@ +clear t; +t = VoltageTrace (5, sample); + +[rows, cols] = size (t.APs); +buffer = []; + +figure; hold on; + +t = VoltageTrace (5, sample); + +for i = 1:50 + buffer = [buffer; t.APs(1,i).voltage]; + plot (t.APs(1,i).voltage); + i +end + +figure; +plot (buffer, 'r'); \ No newline at end of file diff --git a/plot_data.m b/plot_data.m new file mode 100644 index 0000000..b74d109 --- /dev/null +++ b/plot_data.m @@ -0,0 +1,80 @@ +v_th = struct(); + +v_th_dt = []; +AHP_dt = []; +AHP_con = []; +v_th_con = []; + +max_dt.mean = []; +max_con.mean = []; +max_dt.max = []; +max_con.max = []; +min_dt.max = []; +min_con.max = []; +min_dt.mean = []; +min_con.mean = []; +dt_mean_AP = []; +con_mean_AP = []; +tot_mean_AP = []; + + +for i = 1:length (dt_data) + v_th_dt = [v_th_dt; dt_data{i}.v_th.raw]; + AHP_dt = [AHP_dt; dt_data{i}.AHP.raw]; + max_dt.mean = [max_dt.mean; dt_data{i}.max_dv.mean]; + max_dt.max = [max_dt.max; dt_data{i}.max_dv.max]; + min_dt.mean = [min_dt.mean; dt_data{i}.min_dv.mean]; + min_dt.max = [min_dt.max; dt_data{i}.min_dv.max]; + tot_mean_AP (:,i) = dt_data{i}.mean_tot_AP; +end + +dt_mean_AP = mean (tot_mean_AP')'; + +tot_mean_AP = []; + +for i = 1: length (con_data) + v_th_con = [v_th_con; con_data{i}.v_th.raw]; + AHP_con = [AHP_con; con_data{i}.AHP.raw]; + max_con.mean = [max_con.mean; con_data{i}.max_dv.mean]; + max_con.max = [max_con.max; con_data{i}.max_dv.max]; + min_con.mean = [min_con.mean; con_data{i}.min_dv.mean]; + min_con.max = [min_con.max; con_data{i}.min_dv.max]; + tot_mean_AP (:,i) = dt_data{i}.mean_tot_AP; +end + +con_mean_AP = mean (tot_mean_AP')'; + +figure ('Name', 'mean APs'); hold on; +plot (dt_mean_AP); +plot (con_mean_AP, 'r'); + +figure ('Name', 'voltage threshold'); hold on; +plot (con_curr, v_th_con, 'r.'); +plot (dt_curr, v_th_dt, '.'); + +figure ('Name', 'AHP'); hold on; +plot (con_curr, AHP_con, '.r'); +plot (dt_curr, AHP_dt, '.'); + +figure ('Name', 'average max dv/dt'); hold on; +plot (con_curr, max_con.mean, '.r'); +plot (dt_curr, max_dt.mean, '.'); + +figure ('Name', 'maximum max dv/dt'); hold on; +plot (con_curr, max_con.max, '.r'); +plot (dt_curr, max_dt.max, '.'); + +figure ('Name', 'average min dv/dt'); hold on; +plot (con_curr, min_con.mean, '.r'); +plot (dt_curr, min_dt.mean, '.'); + +figure ('Name', 'maximum min dv/dt'); hold on; +plot (con_curr, min_con.max, '.r'); +plot (dt_curr, min_dt.max, '.'); + + +% +% figure; hold on; +% % +% avgcurves (con_curr, v_th.con); +% avgcurves (dt_curr, v_th.dt); \ No newline at end of file diff --git a/plot_v.m b/plot_v.m new file mode 100644 index 0000000..1b86984 --- /dev/null +++ b/plot_v.m @@ -0,0 +1,2 @@ +t = VoltageTrace (5, AP_trace); +t.plot_all_v(); \ No newline at end of file diff --git a/plotpeaks.m b/plotpeaks.m new file mode 100644 index 0000000..8d093cf --- /dev/null +++ b/plotpeaks.m @@ -0,0 +1,10 @@ +barrage = sample(20005:30005); + +[ap_peaks, p_i] = findpeaks (barrage); + +[ap_troughs, p_t] = findpeaks (-barrage); ap_troughs = -ap_troughs; + +figure; hold on; +plot (barrage); axis tight; +plot (p_i, ap_peaks, 'ro'); +plot (p_t, ap_troughs, '^r'); \ No newline at end of file diff --git a/sample.m b/sample.m new file mode 100644 index 0000000..2fc9e24 --- /dev/null +++ b/sample.m @@ -0,0 +1,8 @@ +[p, i_p] = findpeaks (f); + +[troughs, i_t] = findpeaks (trace); +troughs = –troughs; + + +plot (i_t, troughs, 'ob'); +plot (trace, 'r'); \ No newline at end of file diff --git a/trap_integration_1.fig b/trap_integration_1.fig new file mode 100644 index 0000000..64ab52e Binary files /dev/null and b/trap_integration_1.fig differ