bleeck@3: % 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: function [phase,vectorstrength,strength]=calculatephase(stim,freq,grafix) tomwalters@0: tomwalters@0: % calculates the phase in radian for the stimulus in stim given a frequency tomwalters@0: % of freq. tomwalters@0: if nargin<3 tomwalters@0: grafix=0; tomwalters@0: end tomwalters@0: tomwalters@0: vals=getvalues(stim); tomwalters@0: tomwalters@0: nrvals=length(vals); tomwalters@0: modphase=time2bin(stim,1/freq); tomwalters@0: % vectorstrength=signal(length(modphase),1); tomwalters@0: vectorstrength=zeros(modphase,1); tomwalters@0: sr=getsr(stim); tomwalters@0: for i=1:nrvals tomwalters@0: intphase=mod(i,modphase)+1; tomwalters@0: vectorstrength(intphase)=vectorstrength(intphase)+vals(i); tomwalters@0: end tomwalters@0: tomwalters@0: [strength,maxintphase]=max(vectorstrength); tomwalters@0: phase=maxintphase/modphase*2*pi; tomwalters@0: tomwalters@0: tomwalters@0: if grafix tomwalters@0: figure(5423) tomwalters@0: clf tomwalters@0: plot(vectorstrength); tomwalters@0: set(gca,'ylim',[min(vectorstrength)*1.1 max(vectorstrength)*1.1]); tomwalters@0: xlabel('phase') tomwalters@0: phases=get(gca,'xtick'); tomwalters@0: phases=phases/modphase*2*pi; tomwalters@0: for i=1:length(phases) tomwalters@0: phasestr(i,:)=sprintf('%2.2f',phases(i)); tomwalters@0: end tomwalters@0: set(gca,'xticklabel',phasestr); tomwalters@0: hold on tomwalters@0: plot(maxintphase,strength,'.','Markerfacecolor','r','Markeredgecolor','r','Markersize',25); tomwalters@0: text(maxintphase,strength*1.15,sprintf('Phase: %2.2f',phase),'verticalal','bottom'); tomwalters@0: text(maxintphase,strength*1.15,sprintf('Freq: %3.3f Hz',freq),'verticalal','top'); tomwalters@0: tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: return