annotate aim-mat/tools/@signal/calculatephase.m @ 4:537f939baef0 tip

various bug fixes and changed copyright message
author Stefan Bleeck <bleeck@gmail.com>
date Tue, 16 Aug 2011 14:37:17 +0100
parents 20ada0af3d7d
children
rev   line source
bleeck@3 1 % This external file is included as part of the 'aim-mat' distribution package
bleeck@3 2 % (c) 2011, University of Southampton
bleeck@3 3 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 4 % download of current version is on the soundsoftware site:
bleeck@3 5 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 6 % documentation and everything is on http://www.acousticscale.org
tomwalters@0 7 function [phase,vectorstrength,strength]=calculatephase(stim,freq,grafix)
tomwalters@0 8
tomwalters@0 9 % calculates the phase in radian for the stimulus in stim given a frequency
tomwalters@0 10 % of freq.
tomwalters@0 11 if nargin<3
tomwalters@0 12 grafix=0;
tomwalters@0 13 end
tomwalters@0 14
tomwalters@0 15 vals=getvalues(stim);
tomwalters@0 16
tomwalters@0 17 nrvals=length(vals);
tomwalters@0 18 modphase=time2bin(stim,1/freq);
tomwalters@0 19 % vectorstrength=signal(length(modphase),1);
tomwalters@0 20 vectorstrength=zeros(modphase,1);
tomwalters@0 21 sr=getsr(stim);
tomwalters@0 22 for i=1:nrvals
tomwalters@0 23 intphase=mod(i,modphase)+1;
tomwalters@0 24 vectorstrength(intphase)=vectorstrength(intphase)+vals(i);
tomwalters@0 25 end
tomwalters@0 26
tomwalters@0 27 [strength,maxintphase]=max(vectorstrength);
tomwalters@0 28 phase=maxintphase/modphase*2*pi;
tomwalters@0 29
tomwalters@0 30
tomwalters@0 31 if grafix
tomwalters@0 32 figure(5423)
tomwalters@0 33 clf
tomwalters@0 34 plot(vectorstrength);
tomwalters@0 35 set(gca,'ylim',[min(vectorstrength)*1.1 max(vectorstrength)*1.1]);
tomwalters@0 36 xlabel('phase')
tomwalters@0 37 phases=get(gca,'xtick');
tomwalters@0 38 phases=phases/modphase*2*pi;
tomwalters@0 39 for i=1:length(phases)
tomwalters@0 40 phasestr(i,:)=sprintf('%2.2f',phases(i));
tomwalters@0 41 end
tomwalters@0 42 set(gca,'xticklabel',phasestr);
tomwalters@0 43 hold on
tomwalters@0 44 plot(maxintphase,strength,'.','Markerfacecolor','r','Markeredgecolor','r','Markersize',25);
tomwalters@0 45 text(maxintphase,strength*1.15,sprintf('Phase: %2.2f',phase),'verticalal','bottom');
tomwalters@0 46 text(maxintphase,strength*1.15,sprintf('Freq: %3.3f Hz',freq),'verticalal','top');
tomwalters@0 47
tomwalters@0 48 end
tomwalters@0 49
tomwalters@0 50
tomwalters@0 51 return