Zero Crossing Rate and Python implementation

Zero crossing rate (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.

  • characteristic:
(1). Generally speaking, unvoiced (unvoiced sound) And the environmental noise ZCR are greater than voiced (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.

In general, the greater the zero-crossing rate, the higher the frequency.

import math
import wave
import numpy as np
import pylab as pl
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
        #ref: http://neural.cs.nthu.edu.tw/jang/books/audiosignalprocessing/basicFeatureZeroCrossingRate.asp
        curFrame = curFrame - np.mean(curFrame) # zero-justified
        zcr[i] = sum(curFrame[0:-1]*curFrame[1::]<=0)
    return zcr

# ============ test the algorithm =============
# read wave file and get parameters.
fw = wave.open('21.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.short)
wave_data.shape = -1, 1
#wave_data = wave_data.T
fw.close()

# calculate Zero Cross Rate
frameSize = 256
overLap = 0
zcr = ZeroCR(wave_data,frameSize,overLap)

# plot the wave
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()

See article:
http://ibillxia.github.io/blog/2013/05/15/audio-signal-processing-time-domain-ZeroCR-python-realization/

Intelligent Recommendation

Speech signal processing (3): short-term amplitude, short-term zero crossing rate and short-term autocorrelation

On the basis of the last recorded voice signal, the short-term analysis of the voice signal mainly involves the short-term amplitude, short-term zero-crossing rate and short-term autocorrelation analy...

Voice endpoint detection method based on short-time energy and zero-crossing rate in short-time time domain processing

Voice endpoint detection method based on short-term energy and zero-crossing rate in short-time domain processing 1. Background It is very important to detect the voice endpoint in voice signal proces...

Zero crossing detection

AC-220V zero point detection The general system structure is as shown in the figure below. Zero-crossing detection has three main functions: (1) SCR trigger. By detecting the AC220V zero-crossing poin...

Zero crossing inspection design

Switch-off delay generates a shutdown current, vout/L* delay time. I1R=This voltage. [1] Deng Chaoxuan. Design of synchronous rectified BUCK type DC-DC zero-crossing detection circuit [D]. Southwest J...

Disciplinary principles, zero -rate and non -zero -zero zero -zero zero 01 and other general waveforms and power spectrum density MATLAB implementation

In the actual baseband transmission system, the radio wave shape transmitted in the channel: (1) Do not contain DC ingredients, and low frequency components should be as small as possible. (2) It is r...

More Recommendation

Analysis of the time domain characteristics of speech signals based on MATLAB (2)-short-term energy, short-term average zero-crossing rate

   After the voice signal is framed, it can be processed in the time domain or in the frequency domain. Here we mainly introduce the characteristics of extracting speech signals in time doma...

Proteus Tutorial - Zero Crossing Detector

Op amps as zero crossing detectors Sine voltage signals are usually converted into square waves using zero crossing detectors. In this circuit, the op amp operates in open-loop comparator mode. The po...

Crossing problem (Java implementation)

Crossing problem (Java implementation) Topic description Input format One line of four positive integers, indicate B point coordinates and horse coordinates Output format Indicates an integer of all p...

1053 Python implementation housing vacancy rate

1053 housing vacancy rate (20 points) Without disturb residents, a method of statistical housing vacancy rate is judged by a continuous variation of electricity according to household. Determined as f...

Python implementation moves zero in LeetCode

demand: Given an array of nums, write a function that moves all 0s to the end of the array while maintaining the relative order of non-zero elements. Example: Claim: Must be manipulated on the origina...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top