有没有一种简单的方法可以找到声音信号中包络的频率?

Is there an easy way of finding frequency of envelopes in sound signals?

我有一个 5 秒长的声音信号,它来自螺旋桨的声音。我需要通过找到包络线的频率来找到螺旋桨的转速。

import wave
import numpy as np
import matplotlib.pyplot as plt

raw = wave.open('/content/drive/MyDrive/Demon.wav','r')
signal = raw.readframes(-1)
signal = np.frombuffer(signal , dtype="int16")
frate = raw.getframerate()

time = np.linspace(0,len(signal) / frate,num = len(signal))

plt.figure(1)
plt.title("Sound Wave")
plt.xlabel("Time")

plt.plot(time, signal)
plt.show()

这是声音文件本身的 link:https://sndup.net/5v3j

因为它是一个 5 秒长度的信号并且有 80.000 个样本,我想通过查看信号的 1 秒部分来详细了解它。

partial_signal = signal [1 : 16000]
partial_time = time[1 : 16000]
plt.plot(partial_time,partial_signal)
plt.show()

绘图的输出如下所示。

编辑:看起来图像不会显示在这里是图像的 link: https://imgur.com/P5lnSM1 现在我需要通过使用 only python.

来找到包络线的频率,从而找到螺旋桨的转速

您可以通过对信号幅度应用快速傅里叶变换 (FFT) 来轻松做到这一点。这是一个例子:

import wave
import numpy as np
import matplotlib.pyplot as plt
from scipy.fft import rfft, rfftfreq
from scipy.ndimage import gaussian_filter

raw = wave.open('Demon.wav','r')
signal = raw.readframes(-1)
signal = np.frombuffer(signal , dtype="int16")
frate = raw.getframerate()
time = np.linspace(0,len(signal) / frate,num = len(signal))


# Compute the amplitude of the sound signal
signalAmplitude = signal.astype(np.float64)**2

# Filter the signal to remove very short-timed amplitude modulations (<= 1 ms)
signalAmplitude = gaussian_filter(signalAmplitude, sigma=frate/1000)

# Compute the frequency amplitude of the FFT signal
tmpFreq = np.abs(rfft(signalAmplitude))

# Get the associated practical frequency for this signal
hzFreq = rfftfreq(signal.shape[0], d=1/frate)

finalFrequency = hzFreq[1+tmpFreq[1:].argmax()]
print(finalFrequency)


# Show sound frequency diagram
plt.xticks(np.arange(21))
plt.xlim([1, 20]) # Show only interesting low frequencies
plt.plot(hzFreq, tmpFreq)
plt.show()

频率图如下:

最终检测到的频率为3.0Hz,与我们听到的非常吻合。