annotate toolboxes/MIRtoolbox1.3.2/AuditoryToolbox/CorrelogramFrame.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 % pic = CorrelogramFrame(data, picWidth, start, winLen)
Daniel@0 2 % Compute one frame of a correlogram. The input data is a
Daniel@0 3 % two-dimensional array of cochlear data, each row representing
Daniel@0 4 % firing probabilities from one cochlear channel. The output
Daniel@0 5 % picture is a two dimensional array of width "picWidth".
Daniel@0 6 %
Daniel@0 7 % The correlogram is computed with autocorrelation using
Daniel@0 8 % data from the input array. For each channel, the data from
Daniel@0 9 % is extracted starting at column "start" and extending for
Daniel@0 10 % "winLength" time steps.
Daniel@0 11
Daniel@0 12 % (c) 1998 Interval Research Corporation
Daniel@0 13
Daniel@0 14 function pic = CorrelogramFrame(data, picWidth, start, winLen)
Daniel@0 15
Daniel@0 16 if nargin < 2
Daniel@0 17 disp('Syntax: pic=CorrelogramFrame(data, picWidth[, start, len])');
Daniel@0 18 return
Daniel@0 19 end
Daniel@0 20
Daniel@0 21 if nargin < 3
Daniel@0 22 start = 1;
Daniel@0 23 end
Daniel@0 24
Daniel@0 25 if nargin < 4
Daniel@0 26 [channels, winLen] = size(data);
Daniel@0 27 end
Daniel@0 28
Daniel@0 29 [channels, dataLen] = size(data);
Daniel@0 30 start = max(1, start);
Daniel@0 31 last = min(dataLen, start+winLen-1);
Daniel@0 32
Daniel@0 33 pic = zeros(channels, picWidth);
Daniel@0 34 fftSize = 2^(nextpow2(max(picWidth, winLen))+1);
Daniel@0 35 % disp(['CorrelogramFrame fftSize is ' int2str(fftSize)]);
Daniel@0 36
Daniel@0 37 a = .54;
Daniel@0 38 b = -.46;
Daniel@0 39 wr = sqrt(64/256);
Daniel@0 40 phi = pi/winLen;
Daniel@0 41 ws = 2*wr/sqrt(4*a*a+2*b*b)*(a + b*cos(2*pi*(0:winLen-1)/winLen + phi));
Daniel@0 42
Daniel@0 43 for i=1:channels
Daniel@0 44 f = zeros(1, fftSize);
Daniel@0 45 % d = zeros(1, winLen);
Daniel@0 46 % d(1:(last-start+1)) = data(i,start:last) .* ws(1:(last-start+1));
Daniel@0 47 % f(1:(winLen/2)) = d(winLen/2+1:winLen);
Daniel@0 48 % f(fftSize-(winLen/2)+1:fftSize) = d(1:min(length(d),winLen/2));
Daniel@0 49 f(1:(last-start+1)) = data(i,start:last) .* ws(1:(last-start+1));
Daniel@0 50 f = fft(f);
Daniel@0 51 f = ifft(f.*conj(f));
Daniel@0 52 pic(i,:) = real(f(1:picWidth));
Daniel@0 53 if pic(i,1) > pic(i,2) & pic(i,1) > pic(i,3)
Daniel@0 54 pic(i,:) = pic(i,:)/sqrt(pic(i,1));
Daniel@0 55 else
Daniel@0 56 pic(i,:) = zeros(1,picWidth);
Daniel@0 57 end
Daniel@0 58 end