comparison userProgramsTim/runningACF.m @ 38:c2204b18f4a2 tip

End nov big change
author Ray Meddis <rmeddis@essex.ac.uk>
date Mon, 28 Nov 2011 13:34:28 +0000
parents
children
comparison
equal deleted inserted replaced
37:771a643d5c29 38:c2204b18f4a2
1 function sampledacf = runningACF(inputSignalMatrix, sfreq, params)
2 % runningACF computes within-channel, running autocorrelations (acfs)
3 % and samples it at given time steps
4 %
5 % INPUT
6 % inputSignalMatrix: a matrix (channel x time) of AN activity
7 % sfreq: sampling frequency
8 %
9 % params: a list of parmeters to guide the computation:
10 % params.lags: an array of lags to be computed (seconds)
11 % params.acfTau: time constant (sec) of the running acf calculations
12 %
13 %
14 %
15 % OUTPUT
16 % sampledacf: (time x lags)
17
18 %%
19 boundaryValue=[];
20 [nChannels inputLength]= size(inputSignalMatrix);
21 % list of BFs must be repeated is many fiber types used
22 %BFlist=method.nonlinCF;
23 %nfibertypes=nChannels/length(BFlist);
24 %BFlist=repmat(BFlist',2,1)';
25
26 dt=1/sfreq;
27
28 samplelength=0.003; %sample length in ms
29 gridpoints=round([samplelength:samplelength:inputLength*dt]/dt);
30 gridpoints=[1 gridpoints];
31
32 lags=params.lags;
33
34 nLags=length(lags);
35
36
37 % Establish matrix of lag time constants
38 % these are all the same if tau<1
39
40 if params.acfTau<1 % all taus are the same
41 acfTaus=repmat(params.acfTau, 1, nLags);
42 acfDecayFactors=ones(size(lags)).*exp(-dt/params.acfTau);
43 else
44 error('acfTau must be <1');
45 end
46 % make acfDecayFactors into a (channels x lags) matrix for speedy computation
47 acfDecayFactors=repmat(acfDecayFactors,nChannels, 1);
48
49 % P function lowpass filter decay (only one value needed)
50 %pDecayFactor=exp(-dt/params.lambda);
51
52 % ACF
53 % lagPointers is a list of pointers relative to 'time now'
54 lagPointers=round(lags/dt);
55 lagWeights=ones(nChannels,nLags);
56 if max(lagPointers)+1>inputLength
57 error([' filteredSACF: not enough signal to evaluate ACF. Max(lag)= ' num2str(max(lags))])
58 end
59
60
61
62 acf=zeros(nChannels,nLags);
63 sampledacf = zeros(length(gridpoints),nChannels,nLags);
64 % create a runup buffer of signal
65 buffer= zeros(nChannels, max(lagPointers));
66
67 inputSignalMatrix=[buffer inputSignalMatrix];
68 [nChannels inputLength]= size(inputSignalMatrix);
69
70 timeCounter=0; biggestSACF=0;
71 gridcounter =1;
72 for timePointer= max(lagPointers)+1:inputLength
73 % acf is a continuously changing channels x lags matrix
74 % Only the current value is stored
75 % sacf is the vertical summary of acf ( a vector) and all values are kept and returned
76 % P is the smoothed version of sacf and all values are kept and returned
77 % lagWeights emphasise some BF/lag combinations and ignore others
78 % NB time now begins at the longest lag.
79 % E.g. if max(lags) is .04 then this is when the ACf will begin.
80 % AN AN delayed weights filtering
81
82 % This is the ACF calculation
83 timeCounter=timeCounter+1;
84 acf = (repmat(inputSignalMatrix(:, timePointer), 1, nLags) .* inputSignalMatrix(:, timePointer-lagPointers)).*lagWeights *dt + acf.* acfDecayFactors;
85
86 %just sample on certain samplepoints
87 if ~isempty(find(timeCounter==gridpoints))
88 sampledacf(gridcounter,:,:)=acf;
89 gridcounter = gridcounter+1;
90 end
91
92 end
93 end
94
95
96
97