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.
Get instant access to the code, model, or application of the video or article you found helpful! Simply purchase the specific title, if available, and receive the download link right away! #MATLABHelper #CodeMadeEasy
Ready to take your MATLAB skills to the next level? Look no further! At MATLAB Helper, we've got you covered. From free community support to expert help and training, we've got all the resources you need to become a pro in no time. If you have any questions or queries, don't hesitate to reach out to us. Simply post a comment below or send us an email at [email protected].
And don't forget to connect with us on LinkedIn, Facebook, and Subscribe to our YouTube Channel! We're always sharing helpful tips and updates, so you can stay up-to-date on everything related to MATLAB. Plus, if you spot any bugs or errors on our website, just let us know and we'll make sure to fix it ASAP.
Ready to get started? Book your expert help with Research Assistance plan today and get personalized assistance tailored to your needs. Or, if you're looking for more comprehensive training, join one of our training modules and get hands-on experience with the latest techniques and technologies. The choice is yours – start learning and growing with MATLAB Helper today!
Education is our future. MATLAB is our feature. Happy MATLABing!