主要内容

spectralCentroid

Spectral centroid for audio signals and auditory spectrograms

描述

example

centroid=光谱中心(x,f)返回信号的光谱质心,x, over time. How the function interpretsx取决于形状f

example

centroid=光谱中心(x,f,Name,Value)specifies options using one or moreName,Value配对参数。

例子

全部收缩

Read in an audio file, calculate the centroid using default parameters, and then plot the results.

[audioin,fs] = audioread('Counting-16-44p1-mono-15secs.wav');Centroid = SpectralCentroid(Audioin,fs);t = linspace(0,大小(Audioin,1)/fs,大小(Centroid,1));图(t,centroid)xlabel(“时间)”)ylabel('Centroid (Hz)')

Figure contains an axes object. The axes object contains an object of type line.

在和一个音频文件n buffer the signal into 30 ms frames with 20 ms overlap. Calculate the octave power spectrum using thepoctavefunction.

[audioin,fs] = audioread('Counting-16-44p1-mono-15secs.wav');AudioBuffered = buffer(Audioin,圆形(FS*0.03),圆形(FS*0.02),'nodelay');[p,cf] = poctave(AudioBuffered,fs);

随着时间的推移计算八度功率谱的质心。绘制结果。

centroid = spectralCentroid(p,cf); t = linspace(0,size(audioIn,1)/fs,size(centroid,1)); plot(t,centroid) xlabel(“时间)”)ylabel('Centroid (Hz)')

Figure contains an axes object. The axes object contains an object of type line.

Read in an audio file.

[audioin,fs] = audioread('Counting-16-44p1-mono-15secs.wav');

Calculate the centroid of the power spectrum over time. Calculate the centroid for 50 ms Hamming windows of data with 25 ms overlap. Use the range from 62.5 Hz tofs/2用于质心计算。绘制结果。

centroid = spectralCentroid(audioIn,fs,。。。'Window',hamming(round(0.05*fs)),。。。'OverlapLength',round(0.025*fs),。。。'范围',[62.5,fs/2]);t = linspace(0,大小(Audioin,1)/fs,大小(Centroid,1));图(t,centroid)xlabel(“时间)”)ylabel('Centroid (Hz)')

Figure contains an axes object. The axes object contains an object of type line.

创建一个dsp.AudioFileReader对象逐帧读取音频数据。创建一个dsp.SignalSink记录光谱质心计算。

fileReader = dsp.AudioFileReader('Counting-16-44p1-mono-15secs.wav');logger = dsp.SignalSink;

在音频流循环中:

  1. 在音频数据框架中阅读。

  2. 计算音频框架的光谱中心。

  3. Log the spectral centroid for later plotting.

要计算仅给定输入框架的光谱质体,请指定一个与输入相同数量的样本数的窗口,并将重叠长度设置为零。

绘制已记录的数据。

尽管〜ISDONE(FILEREADER)AUDIOIN = FILEREADER();Centroid = SpectralCentroid(Audioin,filereader.samplate,。。。'Window',hamming(size(audioIn,1)),。。。'OverlapLength',0);记录器(质心)end绘图(Logger.Buffer)ylabel('Centroid (Hz)')

Figure contains an axes object. The axes object contains an object of type line.

如果您的音频流循环的输入具有每帧的可变样本,则与分析窗口大小的每框架不一致的样本不一致spectralCentroid,或者如果要计算重叠数据的光谱质心,请使用dsp.AsyncBuffer

创建一个dsp.AsyncBuffer对象,重置记录器,然后释放文件读取器。

buff = dsp.AsyncBuffer; reset(logger) release(fileReader)

指定使用25 ms重叠的50毫秒帧计算光谱中心体。

fs = filereader.mamplater;samplesperframe =圆形(FS*0.05);SampleSoverLap =圆形(FS*0.025);sampleSperhop = samplesperframe -sampleSoverLap;win =锤子(samplesperframe);尽管〜ISDONE(FILEREADER)AUDIOIN = FILEREADER();write(buff,audioIn);尽管buff.NumUnreadSamples >= samplesPerHop audioBuffered = read(buff,samplesPerFrame,samplesOverlap); centroid = spectralCentroid(audioBuffered,fs,。。。'Window',赢,。。。'OverlapLength',0);记录器(质心)endendrelease(fileReader)

绘制已记录的数据。

绘图(Logger.Buffer)ylabel('Centroid (Hz)')

Figure contains an axes object. The axes object contains an object of type line.

Input Arguments

全部收缩

输入信号,指定为向量,矩阵或3-D数组。功能如何解释x取决于形状f

Data Types:single|双倍的

Hz中的采样率或频率向量分别指定为标量或矢量。功能如何解释x取决于形状f:

  • 如果fis a scalar,xis interpreted as a time-domain signal, andf被解释为样本率。在这种情况下,xmust be a real vector or matrix. Ifxis specified as a matrix, the columns are interpreted as individual channels.

  • 如果fis a vector,xis interpreted as a frequency-domain signal, andfis interpreted as the frequencies, in Hz, corresponding to the rows ofx。在这种情况下,xmust be a realL-经过-M-经过-Narray, whereL是给定频率的光谱值数量f,Mis the number of individual spectra, andNis the number of channels.

  • The number of rows ofx,L, must be equal to the number of elements off

Data Types:single|双倍的

Name-Value Arguments

Specify optional comma-separated pairs ofName,Value参数。Nameis the argument name and价值是相应的值。Name必须出现在引号中。您可以按任何顺序指定几个名称和值对参数NAME1,Value1,...,Namen,Valuen

例子:'Window',hamming(256)

Note

The following name-value pair arguments apply ifx是时间域信号。如果xis a frequency-domain signal, name-value pair arguments are ignored.

在时间域中应用的窗口,指定为逗号分隔对'Window'和a real vector. The number of elements in the vector must be in the range [1,size(x,1)]。向量中的元素数量也必须大于重叠

Data Types:single|双倍的

相邻窗口之间重叠的样本数量,指定为逗号分隔对,由'OverlapLength'和an integer in the range [0,size(Window,1))。

Data Types:single|双倍的

用于计算窗户输入样品的DFT的垃圾箱数量,指定为逗号分隔对“ fftlength”和一个积极的标量整数。如果未指定,FFTLength默认为元素数量Window

Data Types:single|双倍的

Frequency range in Hz, specified as the comma-separated pair consisting of'范围'以及在范围内增加实际值的两元素行向量[0f/2].

Data Types:single|双倍的

频谱类型,指定为逗号分隔对'SpectrumType''power'或者'震级':

  • 'power'- 计算了针对单侧功率谱的光谱质心。

  • '震级'- 计算了针对单侧幅度光谱的光谱质心。

Data Types:char|string

Output Arguments

全部收缩

Hz中的光谱质心作为标量,矢量或矩阵返回。每一行centroid对应于一个窗户的光谱质心x。Each column ofcentroidcorresponds to an independent channel.

算法

The spectral centroid is calculated as described in[1]:

centroid = k = b 1 b 2 f k s k k = b 1 b 2 s k

where

  • fkis the frequency in Hz corresponding to bink

  • skis the spectral value at bink

  • b1b2是带有垃圾箱的带边缘,以计算光谱质心。

参考

[1] Peeters,G。“ Cuidado Project中的声音描述(相似性和分类)的大量音频功能。”技术报告;IRCAM:法国巴黎,2004年。

Extended Capabilities

C/C ++代码生成
使用MATLAB®CODER™生成C和C ++代码。

GPU Arrays
使用并行计算工具箱™在图形处理单元(GPU)上运行加速代码。

Introduced in R2019a