简体   繁体   English

如何分析波形文件的频率

[英]How to analyse frequency of wave file

How to analyse frequency of wave file in a simple way? 如何以简单的方式分析波形文件的频率? Without extra modules. 没有额外的模块。

What does it mean "analyse"? “分析”是什么意思? It can mean lot of different things, but one of simplest way I know about is to use convolution which you may easily implement for discrete functions (you'll have the points in array or be trying discrete step): 它可能意味着许多不同的东西,但我所知道的最简单的方法之一是使用卷积 ,你可以轻松地实现离散函数 (你将在数组中有点或尝试离散步骤):

离散卷积方程

Which can be easily done by: 这可以通过以下方式轻松完成:

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)

Or you could use circular convolution (idea taken from eryksuns comment): 或者你可以使用循环卷积(从eryksuns评论中获取的想法):

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

Which will give you ability to test whether certain signal is present in another signal (and you'll try frequencies 10,20,50,... and just get the best result). 这将使您能够测试某个信号是否存在于另一个信号中(并且您将尝试频率10,20,50,......并获得最佳结果)。

You may also google determine wave frequency or study Fourier transformation a bit (it's base for a lot of signal processing algorithms). 您也可以谷歌determine wave frequency或稍微研究傅立叶变换 (它是许多信号处理算法的基础)。

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. 我相信CD的采样频率为44.1 kHz,分辨率为16位。 sample. 样品。 That means the music is sampled 44,100 times a second and converted to a 16bit value. 这意味着音乐每秒采样44,100次并转换为16位值。 The music is represented as a vector (or array) with a length of 44,100. 音乐表示为长度为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! 您仍然会有一个长度为44,100个元素的向量,但每个元素将代表幅度 - 您在每个频率上采样了多少“信号”! In other words, how much signal of each given frequency your signal contains IN TOTAL over the whole sampling period. 换句话说,在整个采样周期内,信号包含的每个给定频率的信号总数为IN TOTAL。

You should look into discrete fourier analysis and an implementation of the Fast Fourier Transformation (FFT). 您应该研究离散傅立叶分析和快速傅里叶变换(FFT)的实现。

This question touches on FFT analysis a bit more: Scipy/Numpy FFT Frequency Analysis 这个问题更多地涉及FFT分析: Scipy / Numpy FFT频率分析

EDIT: 编辑:

I've shamelessly stolen some graphics online: 我在网上无耻地窃取了一些图片:

FFT formula: FFT公式:

在此输入图像描述

Time vs Frequency domain: 时间与频率域:

在此输入图像描述

If your wave file consists of only one note, you can get the fundamental frequency (not the harmonics) simply by detecting the periodicity of the wave. 如果您的波形文件只包含一个音符,则只需检测波形的周期性即可获得基频(而不是谐波)。 Do this by looking for 0-crossings. 通过寻找0交叉来做到这一点。

If you don't want to implement a whole FFT algorithm and don't want any additional modules then I would recomment the Goertzel Algorithm which is effectively a Fourier transform for a specific freqency and gives you the power at that frequency for a sample: 如果您不想实现整个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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM