The MATLAB implementation of short-term average zero-crossing rateAnother blogIt has already been introduced here. Here mainly introduces the short-term average zero-crossing rate of the signal in the Python environment, and compares whether the simulation results of MATLAB and Python are consistent.
Concept: Zero Crossing Rate (ZCR) refers to the number of times the voice signal passes through the zero point (from positive to negative or from negative to positive) in each frame. This feature has been widely used in the fields of speech recognition and music information retrieval, and is a key feature in the classification of percussive sounds.
The mathematical formal definition of ZCR is:
Features:
(1). Generally speaking, the ZCR of unvoiced sound and environmental noise is greater than the voiced sound (voiced sound);
(2). Because the ZCR of unvoiced sound and environmental noise are similar in size, they cannot be distinguished by ZCR;
(3). In practice, the zero-crossing rate is often combined with short-term energy characteristics for endpoint detection, especially ZCR is used to detect the beginning and end of unvoiced sounds;
(4). Sometimes ZCR can also be used for rough fundamental frequency estimation, but this is very unreliable unless there is a subsequent refinement process.
The specific code is as follows:
The ZCR Python implementation is as follows:
import math
import numpy as np
def ZeroCR(waveData,frameSize,overLap):
wlen = len(waveData)
step = frameSize - overLap
frameNum = math.ceil(wlen/step)
zcr = np.zeros((frameNum,1))
for i in range(frameNum):
curFrame = waveData[np.arange(i*step,min(i*step+frameSize,wlen))]
#To avoid DC bias, usually we need to perform mean subtraction on each frame
curFrame = curFrame - np.mean(curFrame) # zero-justified
zcr[i] = sum(curFrame[0:-1]*curFrame[1::]<=0)
return zcr
For a given voice file MORSE.wav, the code to calculate ZCR using the above function is as follows:
import math
import wave
import numpy as np
import pylab as pl
fw = wave.open('F:\【1】Audio\wav\MORSE.wav','rb')
params = fw.getparams()
print(params)
nchannels, sampwidth, framerate, nframes = params[:4]
str_data = fw.readframes(nframes)
wave_data = np.fromstring(str_data, dtype=np.int16)
wave_data = wave_data*1.0/(max(abs(wave_data)))#wave amplitude normalization
fw.close()
# calculate Zero Cross Rate
frameSize = 256
overLap = 0
zcr = ZeroCR(wave_data,frameSize,overLap)
time = np.arange(0, len(wave_data)) * (1.0 / framerate)
time2 = np.arange(0, len(zcr)) * (len(wave_data)/len(zcr) / framerate)
pl.subplot(211)
pl.plot(time, wave_data)
pl.ylabel("Amplitude")
pl.subplot(212)
pl.plot(time2, zcr)
pl.ylabel("ZCR")
pl.xlabel("time (seconds)")
pl.show()
Run the above program to get the following figure:
MATLAB specific code in blogger'sAnother blogIt has already been introduced here.
The results achieved are shown in the following figure:
It can be seen from the results of MATLAB and Python that the short-term average zero-crossing rates of the two are basically the same.
First, short-term average zero zero 1. For continuous speech signals, it can be examined for the case of the time domain waveform through the time axis; 2. For discrete signals, it is essentially the ...
1. Introduction to the concept The short-term zero-crossing rate can be regarded as a simple measure of the signal frequency and is a rough estimate of the spectral characteristics. (1) Zero crossing ...
Zero Crossing Rate Concept: Zero Crossing Rate (ZCR) refers to the number of times the speech signal passes through the zero point (from positive to negative or from negative to positive) in each fram...
Calculation of energy By calculating the rate of zero ...
Yesterday, I learned the short-term moving average usage. By the way, I wrote a memo, remember the inquiry in the inside. First of all, we must know the probability theory, the probability of the coin...
This example shows how to classify sounds using deep learning. 1. Data collection generation Generate 1,000 white noise signals, 1,000 brown noise signals, and 1,000 pink noise signals. Suppose the sa...
1. Get code method Obtain code method 1: The full code has uploaded my resources:[Short -time energy] Based on Matlab voice signal short -term energy [Contains MATLAB source code 1719 period] Obtain c...
In this article, I will use Python to build a simple mobile average cross -line transaction strategy for recovery, and use the Standard S & P500 to test. A simple moving average cross -line crossi...
Foreword: The project before graduation, recently finally had time to organize a blog. The keras+gensim used is completed, and a lot of related information on the Internet is also referenced. The fina...