Pitch is a crucial part of voiced speech. It contains speaker-specific information. It is additionally required for speech coding tasks. Therefore, the estimation of pitch is one of the significant issues in speech processing. Pitch detection is of interest whenever a single quasi-periodic sound source is to be studied or modelled, specifically in speech and music. Pitch detection algorithms can be divided into methods that operate in the time domain, frequency domain, or both. We are going to see the time-domain method, which is the Autocorrelation of Speech in MATLAB.
I have used MATLAB Version R2019a and the code should be compatible with any version from R2017a.
Speech consists of different frequencies that are harmonically related to each other in the form of a series. The lowest frequency of the harmonic series is known as the fundamental frequency or Pitch frequency. It is the fundamental frequency of vibration of vocal cords.
The number of samples after which the waveform repeats itself is the pitch period in terms of the number of samples. If we know the sampling frequency, we can find the pitch period in seconds.
The autocorrelation method requires a speech segment with at least two periods to find the pitch period. The Equation for Autocorrelation
Let us consider the above as equation (1), where
N = window size
a = signal samples of the voiced segment
k = zero lag location
The main peak in the autocorrelation function is at the zero-lag location (k = 0). The location of the next peak gives an estimate of the period, and the height gives an indication of the periodicity of the signal.
Get Access to
Code, Sample & Report!
Find pitch periods of a speech signal using the Autocorrelation method; Developed in MATLAB R2019a with Signal Processing Toolbox
Now we will discuss the MATLAB Implementation for this method.
Step 1: Record the speech signal and store it in the array (Set sample rate fs as 10000) and give filename.
Function for recording - “audiorecorder(fs,8,1)”
Function to store data - "getaudiodata" (store it in a variable, 'y')
Step 2: Write the data to a WAVE file named name.wav in the current folder.
Function to write data - "audiowrite ('filename', y, fs)"
Use "audioinfo" to get the information of the speech signal.
Step 3: Read the data from 'y' and plot it.
Function to read data - [y, fs] = "audioread" (filename) reads data from the file named filename, and returns sampled data, y, and a sample rate for that data, fs.
Step 4: Take 1000 samples of the voiced segment and plot it.
a = y (4000:5000); (you can take any voiced segment range)
Step 5: Calculate the Autocorrelation of the speech signal
We have continuous speech signals. We are not going to find autocorrelation using MATLAB function "autocorr" - Sample autocorrelation. We will implement the above Eqn.1 for calculations.
We will calculate the autocorrelation for, say, 32 overlapping samples. This means that two speech segments, one extending from sample number 1-32, are correlated to the other segment from sample number 2-33, then 3-33, and so on. Hence, the sample shifts in the steps of 1, starting from 1. We will use a shift up to 320 samples to the shift value for which the correlation is the highest. The distance between two successive maxima in correlation will give a pitch period in terms of the number of samples. We will use for loops for this.
Step 6: Calculate the pitch period
Find peaks for the min, mean and max locations.
Calculate the period by comparing the "time" between peaks
(For all the plots, use the title, xlabel, and ylabel)
Where can we use the Pitch Period Estimation for speech signal in real time-based situations? There are several applications of the Pitch period Estimation. We will see some of them in Human-robot voice interface and Detection in Industrial Background Noise
Pitch frequency cannot be found from the speech signal directly since speech is a time-varying signal. To determine the pitch using the autocorrelation method, we must consider voice with at least two pitch periods. If we consider the unvoiced segment pitch cannot be determined since the unvoiced segment consists of random noise.
Did you find some helpful content from our video or article and now looking for its code, model, or application? You can purchase the specific Title, if available, and instantly get the download link.
Thank you for reading this blog. Do share this blog if you found it helpful. If you have any queries, post them in the comments or contact us by emailing your questions to [email protected]. Follow us on LinkedIn Facebook, and Subscribe to our YouTube Channel. If you find any bug or error on this or any other page on our website, please inform us & we will correct it.
If you are looking for free help, you can post your comment below & wait for any community member to respond, which is not guaranteed. You can book Expert Help, a paid service, and get assistance in your requirement. If your timeline allows, we recommend you book the Research Assistance plan. If you want to get trained in MATLAB or Simulink, you may join one of our training modules.
If you are ready for the paid service, share your requirement with necessary attachments & inform us about any Service preference along with the timeline. Once evaluated, we will revert to you with more details and the next suggested step.
Education is our future. MATLAB is our feature. Happy MATLABing!