tomwalters@0: % support file for 'aim-mat' tomwalters@0: % tomwalters@0: % This external file is included as part of the 'aim-mat' distribution package bleeck@3: % (c) 2011, University of Southampton bleeck@3: % Maintained by Stefan Bleeck (bleeck@gmail.com) bleeck@3: % download of current version is on the soundsoftware site: bleeck@3: % http://code.soundsoftware.ac.uk/projects/aimmat bleeck@3: % documentation and everything is on http://www.acousticscale.org tomwalters@0: tomwalters@0: function retfld=strf(sig,spikes,start,stop,nrfre,maxfre) tomwalters@0: % sig muss ein Signal sein tomwalters@0: % st muss ein Spiketrain sein tomwalters@0: % das Ergebnissignal hat die Länge bis-von tomwalters@0: % das Ergebnis ist ein Feld mit der Länge stop-start und der Breite nrfre tomwalters@0: tomwalters@0: if ~isobject(sig) tomwalters@0: disp('error: Signal must be an Object signal') tomwalters@0: end tomwalters@0: tomwalters@0: if nargin < 6 tomwalters@0: maxfre=GetSR(sig)/2; tomwalters@0: end tomwalters@0: if nargin < 5 tomwalters@0: nrfre=512; tomwalters@0: end tomwalters@0: if nargin < 4 tomwalters@0: stop=0.01; %standart: 10 ms nach 0 tomwalters@0: end tomwalters@0: if nargin < 3 tomwalters@0: start=-0.05; %standart: 50 ms vor 0 tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: % make one big spectrogram of the whole signal and then split the important tomwalters@0: % parts: tomwalters@0: bigspectrum=spectrogram(sig,nrfre,maxfre); tomwalters@0: tomwalters@0: avera=mean(mean(getvalues(bigspectrum))); tomwalters@0: nr_t=getnrt(bigspectrum); tomwalters@0: nr_f=getnrf(bigspectrum); tomwalters@0: tomwalters@0: tomwalters@0: duration= stop-start; % so long is the signal that we want to analyse tomwalters@0: nr_spikes=length(spikes); tomwalters@0: orglen=GetLength(sig); tomwalters@0: tomwalters@0: tomwalters@0: srf=getsr(bigspectrum); tomwalters@0: res_nr_t=round(duration*srf); tomwalters@0: all_vals=getvalues(bigspectrum); tomwalters@0: fld=zeros(nr_f,res_nr_t); tomwalters@0: tomwalters@0: for i=1:nr_spikes tomwalters@0: spiketime=spikes(i); tomwalters@0: t_start=spiketime+start; tomwalters@0: % t_stop=spiketime+stop; tomwalters@0: tomwalters@0: binstart=time2bin(srf,t_start); tomwalters@0: binstop=binstart+res_nr_t-1; tomwalters@0: tomwalters@0: % tempfeld=zeros(nr_f,res_nr_t); tomwalters@0: % fill the rest of the signal with the average value so that its not going tomwalters@0: % down im amplitude tomwalters@0: tempfeld=ones(nr_f,res_nr_t).*avera; tomwalters@0: tomwalters@0: if t_start >= orglen tomwalters@0: break; % no more relevant spikes in this spiketrain tomwalters@0: end tomwalters@0: tomwalters@0: if binstart>0 & binstop <= res_nr_t % der "Normalfall" (full signal is in window) tomwalters@0: tempfeld=all_vals(:,binstart:binstop); tomwalters@0: else % either start or stop are out of signal window tomwalters@0: if binstart<0 %wenn das Signal nicht so lang ist, müssen wir nullen vornedranhängen tomwalters@0: tempfeld(:,-binstart+1:end)=all_vals(:,1:binstop+1); tomwalters@0: end tomwalters@0: if binstop>res_nr_t %wenn das Signal länger sein sollte hängen wir Nullen hintenan tomwalters@0: nr_v=binstop-nr_t; tomwalters@0: tempfeld(:,1:(res_nr_t-nr_v))=all_vals(:,binstart:binstart+(res_nr_t-nr_v)-1); tomwalters@0: end tomwalters@0: end tomwalters@0: % if size(tempfeld,2)>res_nr_t tomwalters@0: % o=0; tomwalters@0: % end tomwalters@0: tempfeld=tempfeld(:,1:res_nr_t); tomwalters@0: fld=fld+tempfeld; tomwalters@0: tomwalters@0: % if mod(i,1)==0 tomwalters@0: % figure(234) tomwalters@0: % testfld=field(res_nr_t,nr_f,srf); tomwalters@0: % testfld=setmaxfre(testfld,maxfre); tomwalters@0: % testfld=setoffset(testfld,start); tomwalters@0: % testfld=setvalues(testfld,fld); tomwalters@0: % plot(testfld,'log') tomwalters@0: % % plot(fld) tomwalters@0: % drawnow tomwalters@0: % end tomwalters@0: end tomwalters@0: tomwalters@0: retfld=field(res_nr_t,nr_f,srf); tomwalters@0: retfld=setmaxfre(retfld,maxfre); tomwalters@0: retfld=setoffset(retfld,start); tomwalters@0: retfld=setvalues(retfld,fld); tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: % figure(23423) tomwalters@0: % plot(fld,'log'); tomwalters@0: % drawnow