-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSNRCalc.m
27 lines (20 loc) · 837 Bytes
/
SNRCalc.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function [SNR] = SNRCalc(lastEventStart , meanTrace , dF , Fs)
%%Calculates an approx SNR for the whole input trace based off the dFoverF
%%calcuation and a calculate standard deviation of the noise of the
%%baseline just before the first depolarization/event detected
%inputs
%%find index of largest change and indices of the baseline before the event
%%you want
% z = findchangepts(smoothData) ;
startBase = (150*(Fs/1000)) ; %extends the baseline further up. Can modify!
% endBase = (40*(Fs/1000)) ; %%determines the baseline as 165 to 40 ms before the found depolarization
z = lastEventStart;
iStartBase = z - startBase ;
iEndBase = z ;
%Determine baseline
foundBaseline = (meanTrace(iStartBase:iEndBase)) ;
%now calculate the std of this to find noise of trace
noise = std(foundBaseline) ;
%calcualte SNR
SNR = dF/noise ;
end