knowledge:electronic:2019032101
差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录前一修订版后一修订版 | 前一修订版后一修订版两侧同时换到之后的修订记录 | ||
knowledge:electronic:2019032101 [2023/07/07 03:11] – [理论] ob | knowledge:electronic:2019032101 [2023/07/07 04:22] – [Frequency analysis with FHT] ob | ||
---|---|---|---|
行 145: | 行 145: | ||
振幅和均方根(RMS)之间的关系是已知的,可以表示为振幅= sqrt(2)*RMS。如果我们假设声音波形与正弦波形相似,我们可以利用这个关系来基于计算得到的均方根值估计一个稳定的振幅。 | 振幅和均方根(RMS)之间的关系是已知的,可以表示为振幅= sqrt(2)*RMS。如果我们假设声音波形与正弦波形相似,我们可以利用这个关系来基于计算得到的均方根值估计一个稳定的振幅。 | ||
+ | |||
{{: | {{: | ||
行 161: | 行 162: | ||
当使用低于样本(感知阈值)的参考值时,您的 dB 值将是正值,并且随着接近最大值而变大。 | 当使用低于样本(感知阈值)的参考值时,您的 dB 值将是正值,并且随着接近最大值而变大。 | ||
- | 有几个因素会影响实践中的测量而使这一情况变得更加复杂。首先,人耳对所有频率的敏感度并不相同。通常会对不同频段应用不同的权重。一种这样的测量单位被称为dBA,但还有其他一些略微不同的权重。其次,您的麦克风可能不会对所有频率都具有相同的灵敏度。第三,您的扬声器可能无法以相同的精确水平再现所有频率。这些复杂性需要非常精确和昂贵的设备以及特殊的校准程序,以便能够根据标准正确测量声级。要知道,这篇文章描述的设置测量声级的能力非常初级,仅适合粗略的相对测量。 | + | 有几个因素会影响实践中的测量而使这一情况变得更加复杂。首先,人耳对所有频率的敏感度并不相同。通常会对不同频段应用不同的权重。一种这样的测量单位被称为dBA,但还有其他一些略微不同的权重。其次,您的麦克风可能不会对所有频率都具有相同的灵敏度。第三,您的扬声器可能无法以相同的精确水平再现所有频率。这些复杂性需要非常精确和昂贵的设备以及特殊的校准程序,以便能够根据标准正确测量声级。要知道,这篇文章介绍的测量声级的能力非常有限,仅适合粗略的相对测量。 |
- | ===== Implementation | + | ===== 执行 |
- | Let’s recap that our values are 0 to 1024 which stand for [-max, | + | 让我们回顾一下,我们的值是 |
< | < | ||
行 215: | 行 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/ | ||
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. | 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. | ||
+ | 因此对于N=256和采样率为38.4KHz,我们得到128个150Hz的频率区间,其中第一个区间保存了0-150Hz的幅度值,最后一个区间保存了19050-19200Hz的幅度值。现在我们可以专注于我们感兴趣的特定频率区间,通过串行连接发送所有频率区间的值,存储这些值,以某种方式显示它们等等。 | ||
One of the fun ways to use the data, especially when troubleshooting and developing is to visualize with an analyser. Load the following FHT example code to the Arduino or adapt it to your needs. It gets the samples, runs FHT on the data and sends it in binary form over serial. Your Arduino should be connected to a computer running Processing development environment. In Processing, load the “FHT 128 channel analyser” project. I had to make a change to the project to make it compatible with Processing 3.0 . To do so, move the call to “size” function from within the “setup” function to a new function called “settings”. | One of the fun ways to use the data, especially when troubleshooting and developing is to visualize with an analyser. Load the following FHT example code to the Arduino or adapt it to your needs. It gets the samples, runs FHT on the data and sends it in binary form over serial. Your Arduino should be connected to a computer running Processing development environment. In Processing, load the “FHT 128 channel analyser” project. I had to make a change to the project to make it compatible with Processing 3.0 . To do so, move the call to “size” function from within the “setup” function to a new function called “settings”. | ||
+ | 使用数据的有趣方法之一是使用分析器进行可视化,尤其是在故障排除和开发时。将以下 FHT 示例代码加载到 Arduino 或根据您的需要进行调整。它获取样本,对数据运行 FHT,并通过串行以二进制形式发送。您的 Arduino 应连接到运行 Processing 开发环境的计算机。在处理中,加载“FHT 128 通道分析器”项目。我必须对项目进行更改以使其与Processing 3.0 兼容。为此,将对“size”函数的调用从“setup”函数中移至名为“settings”的新函数。 | ||
+ | |||
{{: | {{: | ||
Another way to analyze the data is for the Arduino to send it over serial in textual form, let it run for some time, then copy it from the serial monitor and paste it in a spreadsheet. For example using a code that is similar to this: | Another way to analyze the data is for the Arduino to send it over serial in textual form, let it run for some time, then copy it from the serial monitor and paste it in a spreadsheet. For example using a code that is similar to this: | ||
+ | 分析数据的另一种方法是 Arduino 以文本形式通过串行发送数据,让它运行一段时间,然后从串行监视器复制数据并将其粘贴到电子表格中。例如,使用类似于以下的代码: | ||
< | < | ||
void MeasureFHT() | void MeasureFHT() | ||
行 267: | 行 269: | ||
Then you can format the data in a spreadsheet, | Then you can format the data in a spreadsheet, | ||
+ | 然后,您可以将电子表格(例如 Excel)中的数据格式化为“3-D 曲面”网格图。例如,请查看 Arduino 和 FHT 捕获并分析的从 1hz 到 5000hz 的频率扫描图: | ||
{{: | {{: | ||
knowledge/electronic/2019032101.txt · 最后更改: 2023/07/07 05:32 由 ob