这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录前一修订版后一修订版 | 前一修订版 | ||
knowledge:electronic:2019032101 [2023/07/07 02:06] – [使用 3.3V 参考电压和自由运行实现精确采样] ob | knowledge:electronic:2019032101 [2023/07/07 05:32] (当前版本) – [Summary] ob | ||
---|---|---|---|
行 134: | 行 134: | ||
有了这个逻辑,我们就可以获得合适的波形数据供 Arduino 处理。 | 有了这个逻辑,我们就可以获得合适的波形数据供 Arduino 处理。 | ||
- | ===== Sound level measurement | + | ===== 声级测量 |
- | ==== Theory | + | ==== 理论 |
- | The sound level is defined as the amplitude of the waveform and can be measured per set of samples which represent a part of a signal. | + | 声级定义为波形的幅度,可以根据代表信号一部分的样本集进行测量。 |
{{: | {{: | ||
- | For an ideal sine signal, the amplitude would be the max sample, but in practice it is easy for some samples to be outliers and to affect the max value significantly. For this reason it is more practical to use a metric that takes all the sample values into account. You can use an average, but it is more common to use Root Mean Square (RMS) which will give more “weight” to higher values. | + | 对于一个理想的正弦信号来说,振幅应该是最大的样本值。但在实际应用中,有些样本可能成为异常值,并且会对最大值产生显著影响。因此,更实际的做法是使用一个考虑所有样本值的度量标准。你可以使用平均值,但更常见的是使用均方根(RMS),它会给较高的值赋予更多的“权重”。 |
- | The relationship between amplitude and RMS for sine waves is known and is amplitude= sqrt(2)*RMS. If we assume that a sound waveform is similar to a sine waveform we can use this relationship to estimate a stable amplitude based on an RMS value that we calculate. | + | 振幅和均方根(RMS)之间的关系是已知的,可以表示为振幅= sqrt(2)*RMS。如果我们假设声音波形与正弦波形相似,我们可以利用这个关系来基于计算得到的均方根值估计一个稳定的振幅。 |
{{: | {{: | ||
- | The values we are dealing with are relative and not absolute. After all we are using some value of gain to tune the volume levels to our digital 10bit range. It is very common to work with relative values when processing sound waveforms. The volume is then measured as a ratio from some other “reference point” value. A common unit used to express the ratio is decibel | + | 我们处理的数值是相对值,而不是绝对值。毕竟,我们使用一定的增益值来调整音量水平到我们的10位数字范围内。处理声音波形时,使用相对值是非常常见的。音量通常被测量为与其他“参考点”值的比率。用于表达该比率的常用单位是分贝 |
dB=10*log10(v/ | dB=10*log10(v/ | ||
- | Where dB is the level is dB units, | + | 其中dB为电平,单位为dB,v为样本值,v0为参考值。 |
- | Since sound pressure is a field quantity a ratio of squares is used and the value “2” | + | 由于声压是一个场量,因此使用平方比,并且对数中的值“2”变为“20”[由于 |
dB=20*log10(v/ | dB=20*log10(v/ | ||
- | I was trying to achieve relative measurements, | + | 我试图实现相对测量,我选择 |
- | When using a reference value that is higher than your samples (max amplitude), your dB values would be negative and smaller as you approach the max. | + | 当使用低于样本(感知阈值)的参考值时,您的 |
- | When using a reference value that is lower than your samples (threshold of perception), | + | 有几个因素会影响实践中的测量而使这一情况变得更加复杂。首先,人耳对所有频率的敏感度并不相同。通常会对不同频段应用不同的权重。一种这样的测量单位被称为dBA,但还有其他一些略微不同的权重。其次,您的麦克风可能不会对所有频率都具有相同的灵敏度。第三,您的扬声器可能无法以相同的精确水平再现所有频率。这些复杂性需要非常精确和昂贵的设备以及特殊的校准程序,以便能够根据标准正确测量声级。要知道,这篇文章介绍的测量声级的能力非常有限,仅适合粗略的相对测量。 |
+ | ===== 执行 ===== | ||
- | To make this even more complex, several factors affect measurement in practice. First, the human ear is not equally sensitive to all frequencies. It is typical to apply different weights to different frequency ranges. One such a unit of measurement is called dBA, but there are others with slightly different weights. Second, your microphone might not have equal sensitivity to all frequencies. Third, your speakers might not have equal ability to reproduce all frequencies at the same exact level. These complexities require very accurate and expensive equipment together with special calibration procedures to be able to measure sound levels correctly per standards. You need to understand that your ability to measure sound level with the setup described here is pretty rudimentary and suitable for rough relative measurements only. | + | 让我们回顾一下,我们的值是 |
- | + | ||
- | ===== Implementation ===== | + | |
- | + | ||
- | Let’s recap that our values are 0 to 1024 which stand for [-max, | + | |
< | < | ||
行 219: | 行 216: | ||
</ | </ | ||
- | So now with proper module and calibration you can measure sound level of different events or devices and compare them one to the other. | + | 因此,现在通过适当的模块和校准,您可以测量不同事件或设备的声级,并将它们相互比较。 |
- | ===== Frequency analysis with FHT ===== | + | ===== 使用 |
- | What if you want to “break” the sound into individual frequencies and measure or visualize each individual frequency? Can this be done with Arduino? The answer is that it can be done relatively easily thanks to some existing libraries. To turn signals from a time domain to a frequency domain you would generally use a Fourier transform. Such transforms are used for signals of different types, sound, images, radio transmissions, | + | 如果您想将声音“分解”为单独的频率并测量或可视化每个单独的频率,该怎么办?这可以用Arduino来完成吗?答案是肯定的,使用一些现有的库,这可以相对容易地完成。要将信号从时域转换到频域,通常会使用傅里叶变换。这种变换用于不同类型的信号,声音、图像、无线电传输等。每种信号类型都有其自己的属性,最适合声音信号的变换是离散哈莱特变换(DHT)。DHT 将使用形成波形的离散真实值。为了实现 |
- | The Arduino FHT library works with vectors of 16 to 256 samples. This size is denoted as N. In this project I will be using N=256 to achieve maximum resolution, but you may use smaller values if you are short on memory or processing power. | + | Arduino FHT 库可处理 |
- | First, the algorithm takes N real numbers and results in N/2 complex numbers. Then we can pass the data to another function to calculate the magnitude of the complex numbers to get N/2 bins. In the end we get N/2 bins, each covering a frequency range of sampling_rate/ | + | 首先,该算法接受N个实数,并得到N/2个复数。然后我们可以将数据传递给另一个函数,计算复数的幅度,得到N/2个频率区间。最终,我们得到N/2个频率区间,每个区间覆盖sampling_rate/ |
- | + | 因此对于N=256和采样率为38.4KHz,我们得到128个150Hz的频率区间,其中第一个区间保存了0-150Hz的幅度值,最后一个区间保存了19050-19200Hz的幅度值。现在我们可以专注于我们感兴趣的特定频率区间,通过串行连接发送所有频率区间的值,存储这些值,以某种方式显示它们等等。 | |
- | So for N=256 and sampling_rate=38.4Khz we get 128 150hz bins with the first been holding the magnitude value of 0-150hz and the last bin holding the magnitude value of 19050-19200hz. We can now focus on specific bins that interest us, send the values of all the bins over serial connection, store the values, display them in some way, etc. | + | 使用数据的有趣方法之一是使用分析器进行可视化,尤其是在故障排除和开发时。将以下 |
- | + | ||
- | One of the fun ways to use the data, especially when troubleshooting and developing is to visualize with an analyser. Load the following | + | |
{{: | {{: | ||
- | Another way to analyze the data is for the Arduino | + | 分析数据的另一种方法是 |
< | < | ||
void MeasureFHT() | void MeasureFHT() | ||
行 270: | 行 264: | ||
</ | </ | ||
- | Then you can format the data in a spreadsheet, | + | 然后,您可以将电子表格(例如 |
{{: | {{: | ||
- | ===== Summary | + | ===== 概括 |
- | My code for this project can be found at github | + | 我的这个项目的代码可以在 |
- | The Arduino | + | Arduino |
https:// | https:// | ||