# This script needs also the script "TruncatedFilterSpectrum.praat". form Truncated-filter spectrogram positive Time_step_(s) 0.005 positive Minimum_pitch_(Hz) 75 positive Maximum_pitch_(Hz) 600 positive Maximum_frequency_(Hz) 5000 positive Frequency_step_(Hz) 10 boolean Pre-emphasize 0 endform Copy... sound if 'Pre-emphasize' Pre-emphasize (in-line)... 50 endif tmin = Get starting time tmax = Get finishing time fsamp = Get sample rate To Pitch (cc)... 0.01 minimum_pitch 10 no 0.03 0.45 0.01 0.35 0.14 maximum_pitch plus Sound sound To PointProcess (peaks)... yes no Rename... pulses numberOfPulses = Get number of points numberOfFrames = (tmax -tmin) / time_step - 1 nfreq = maximum_frequency div frequency_step + 1 Create Matrix... result tmin tmax ... numberOfFrames time_step tmin+time_step ... 0 maximum_frequency nfreq frequency_step 0 0 for iframe to numberOfFrames #Select one period. tmid = tmin + iframe * time_step select PointProcess pulses highIndex = Get high index... tmid if highIndex = 1 or highIndex > numberOfPulses pitch = undefined else begin = Get time from index... highIndex-1 end = Get time from index... highIndex pitch = 1 / (end - begin) if pitch < minimum_pitch ... or pitch > maximum_pitch pitch = undefined else begin -= 0.0006 end -= 0.0006 endif endif if pitch = undefined begin = tmid - 0.005 end = tmid + 0.005 endif select Sound sound Extract part... begin end Rectangular 1 yes Rename... period #Compute spectrum. execute truncatedFilterSpectrum_script.txt ... 0 'maximum_frequency' 10 #Show progress. ;Erase all ;Draw... 0 0 0 0 yes ;Text top... yes Frame 'iframe', pitch 'pitch' Hz #Store results. select Matrix result for ifreq to nfreq Set value... ifreq iframe ... Spectrum_spectrum [1,ifreq ] ^ 2 endfor #Clean up. select Sound period plus Spectrum spectrum Remove endfor select Matrix result To Spectrogram