#this scripts gives the statistical mode F0-value in Hertz or Semitones #You will get a histogramlike scatterplot showing a frequency-based #distribution of all measured F0-values #### #Before running the script you need to a Sound object selected in the objects window!!!!!!!!!!! ######Version 0.3.4#################2011-01-26###################################### ######For comments please contact me : grawunder_AT_eva.mpg.de###################### #################################################################################### #TO DO LIST # integrate pitch ac/cc arguments # integrate #of steps / increment # include exact mode form F0 histogram comment Clean Viewport? Title? Grid? Mode value? boolean erase_all 1 boolean title 1 boolean frame 1 boolean mode_value 1 comment Oriantation of the plot optionmenu Ordinate 2 option count&semit option semit&count choice F0_unit: 2 button Hertz button Semitones (re 100Hz) button Semitones (re x Hz) integer semitone_reference 100 real step_width 10 (=milliseconds) comment You may set: "x" or "+" or "o" or "." word mark o comment What steps shall be on the axes? integer left_vertical_horizontal_increment 10 integer right_vertical_horizontal_increment 10 optionmenu method 1 option auto_correlation option auto_correlation_exact option cross_correlation option cross_correlation_exact real left_floor_ceiling 50 real right_floor_ceiling 300 boolean Set_limits_for_display 0 real left_upper_lower_limit -20 real right_upper_lower_limit 20 boolean Remove_tables 0 endform limits=set_limits_for_display step_width=step_width/1000 left_limit=left_upper_lower_limit right_limit=right_upper_lower_limit select all name$ = selected$("Sound") select Sound 'name$' tmin = Get start time tmax = Get end time #To Pitch... 0.01 75 300 if method==1 To Pitch (ac)... 0 left_floor_ceiling 15 no 0.03 0.45 0.01 0.35 0.14 right_floor_ceiling elsif method==2 To Pitch (ac)... 0 left_floor_ceiling 15 yes 0.03 0.45 0.01 0.35 0.14 right_floor_ceiling elsif method==3 To Pitch (cc)... 0 left_floor_ceiling 15 no 0.03 0.45 0.01 0.35 0.14 right_floor_ceiling elsif method==4 To Pitch (cc)... 0 left_floor_ceiling 15 yes 0.03 0.45 0.01 0.35 0.14 right_floor_ceiling endif Rename... pitch rounds=round ((tmax-tmin)/step_width) Create Table with column names... table rounds time semit count #echo Results: a=0 for i to rounds time = tmin + i * step_width select Pitch pitch if f0_unit=1 pitch = Get value at time... time Hertz Linear elif f0_unit=2 pitch = Get value at time... time "semitones re 100 Hz" Linear elif f0_unit=3 pitch = Get value at time... time Hertz Linear endif if not pitch = undefined a=a+1 select Table table Set numeric value... a time time if not f0_unit=3 Set numeric value... a semit 'pitch:1' else Set numeric value... a semit 'pitch' endif Set numeric value... a count 1 endif endfor ##these lines are necessary because Table table containes also ? ? values select Table table Extract rows where column (number)... count "equal to" 1 ##transform Hz to semitones and round if f0_unit=3 select Table table__count__1 #Formula... semit if semitone_reference>self then 12/(log10(2)*log10(semitone_reference/self)) else 12/(log10(2)*log10(self/semitone_reference)) fi #Formula... semit 12/(log10(2)*log10(self/semitone_reference)) Formula... semit 12*log10(self/semitone_reference)/log10(2) Formula... semit self*10 Formula... semit round(self) Formula... semit self/10 elif f0_unit=1 Formula... semit round(self) endif ##calculate mode select Table table__count__1 Collapse rows... semit count "" "" "" select Table table__count__1_pooled nrrows = Get number of rows mod=Get quantile... count 0.75 for y from 1 to nrrows co=Get value... y count if 'co' > 'mod' mod='co' else endif endfor rmodal=Search column... count 'mod' modal=Get value... 'rmodal' semit ##delete extreme outliers if f0_unit=3 select Table table__count__1_pooled pmin=Get minimum... semit pmax=Get maximum... semit rwpmin=Search column... semit 'pmin' #echo 'rwpmin' Remove row... 'rwpmin' rwpmax=Search column... semit 'pmax' Remove row... 'rwpmax' endif if erase_all=1 Erase all else endif #pause ok? #the scripts plots on the selected viewport, otherwise activate the following line #Select outer viewport... 0 6 0 6 if frame=1 frame$="yes" else frame$="no" endif if f0_unit=1 pitch_title$="F0 (in Hz)" elif f0_unit=2 pitch_title$="F0 (in semitones re 100Hz)" elif f0_unit=3 pitch_title$="F0 (in semitones re 'semitone_reference'Hz)" endif if ordinate=1 if limits=1 Scatter plot (mark)... count 0 0 semit left_limit right_limit 1 frame$ 'mark$' else Scatter plot (mark)... count 0 0 semit 0 0 1 frame$ 'mark$' endif Text left... yes 'pitch_title$' Text bottom... yes frequency (counts) else if limits=1 Scatter plot (mark)... semit left_limit right_limit count 0 0 1 frame$ 'mark$' else Scatter plot (mark)... semit 0 0 count 0 0 1 frame$ 'mark$' endif Text bottom... yes 'pitch_title$' Text left... yes frequency (counts) endif if title=1 Text top... yes 'name$' else endif if mode_value=1 if not f0_unit=1 Text top... no mode='modal'st else f0_unit=1 Text top... no mode='modal'Hz endif else endif if frame=1 Draw inner box else endif # horizontal_increment=left_vertical_horizontal_increment vertical_increment=right_vertical_horizontal_increment Marks bottom every... 1 horizontal_increment yes yes yes Marks left every... 1 vertical_increment yes yes yes if remove_tables=1 call remove_tables endif procedure remove_tables select Pitch pitch plus Table table plus Table table__count__1 plus Table table__count__1_pooled Remove select Sound 'name$' endproc ############################MPI EVA Leipzig, Sven Grawunder (c) Copyright 2011 Sven Grawunder. All Rights Reserved. #########################