2

如何简单分析波形文件的频率?没有额外的模块。

4

4 回答 4

5

“分析”是什么意思?它可能意味着很多不同的东西,但我所知道的最简单的方法之一是使用卷积,您可以轻松地为离散函数实现它(您将在数组中有点或尝试离散步骤):

离散卷积方程

这可以通过以下方式轻松完成:

for i in main_array:
    from = i - len(convolution_kernel)/2
    // Todo: check boundaries
    result[i] = 0

    for j in convolution_kernel:
        result[i] += convolution_kernel[j] * main_array( from+j)

或者你可以使用循环卷积(想法取自 eryksuns 评论):

result = [sum(f[m]*g[n-m] for m in xrange(len(f))) for n in xrange(len(g))]

这将使您能够测试某个信号是否存在于另一个信号中(您将尝试频率 10、20、50,... 并获得最佳结果)。

你也可以谷歌determine wave frequency或研究一下傅立叶变换(它是许多信号处理算法的基础)。

于 2012-11-14T10:52:53.507 回答
1

如果您不想实现整个 FFT 算法并且不想要任何其他模块,那么我会推荐Goertzel 算法,它实际上是特定频率的傅里叶变换,并为您提供该频率的功率样本:

define goertzel(sample, target_frequency, sample_rate):
    s_prev = 0 
    s_prev2 = 0 
    normalized_frequency = target_frequency / sample_rate 
    coeff = 2 * cos(2 * PI * normalized_frequency) 
    for element in sample:
      s = element + coeff * s_prev - s_prev2 
      s_prev2 = s_prev 
      s_prev = s 
    end
    power = s_prev2 * s_prev2 + s_prev * s_prev - coeff * s_prev * s_prev2 
    return power
于 2012-11-15T15:19:48.170 回答
1

Disclaimer: Signal processing is not my specialty and this answer may be a bit crude and rudimentary; feel free to correct/ me :)

I would look into fourier-analysis. A Fourier transformation transforms your input from the time domain to the frequency domain. Let me explain that a bit more:

When sampling sound for instance, you determine your sampling frequency and your bit-depth. I believe CD's are sampled at 44.1 kHz with a resolution of 16 bits pr. sample. That means the music is sampled 44,100 times a second and converted to a 16bit value. The music is represented as a vector (or array) with a length of 44,100. It is a function of time, thus this is the time domain.

On the other hand, do a Fourier-transform on the data and you'll have the data represented as a function of frequency instead. You will still have a vector 44,100 elements long, but each element will represent the amplitude - how much "signal" you have sampled at each frequency! In other words, how much signal of each given frequency your signal contains IN TOTAL over the whole sampling period.

You should look into discrete fourier analysis and an implementation of the Fast Fourier Transformation (FFT).

This question touches on FFT analysis a bit more: Scipy/Numpy FFT Frequency Analysis

EDIT:

I've shamelessly stolen some graphics online:

FFT formula:

enter image description here

Time vs Frequency domain:

enter image description here

于 2012-11-14T11:52:08.970 回答
1

如果您的波形文件仅包含一个音符,您只需检测波形的周期性即可获得基频(不是谐波)。通过寻找 0 交叉来做到这一点。

于 2012-11-14T12:02:27.837 回答