用户工具

站点工具


knowledge:electronic:2019032101

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
knowledge:electronic:2019032101 [2023/07/07 03:47] – [Implementation] obknowledge:electronic:2019032101 [2023/07/07 05:32] (当前版本) – [Summary] ob
行 218: 行 218:
 因此,现在通过适当的模块和校准,您可以测量不同事件或设备的声级,并将它们相互比较。 因此,现在通过适当的模块和校准,您可以测量不同事件或设备的声级,并将它们相互比较。
  
-===== Frequency analysis with FHT =====+===== 使用 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, etc. Each signal type has its own properties and the transform that best suits a sound signal is the Discrete Hartley Transform (DHT). DHT will work with discrete, real values which form our waveform. To implement DHT we will use Fast Hartley Transform (FHT) and specifically the ArduinoFHT library.+如果您想将声音分解为单独的频率并测量或可视化每个单独的频率,该怎么办?这可以用Arduino来完成吗?答案是肯定的,使用一些现有的库,这可以相对容易地完成。要将信号从时域转换到频域,通常会使用傅里叶变换。这种变换用于不同类型的信号,声音、图像、无线电传输等。每种信号类型都有其自己的属性,最适合声音信号的变换是离散哈莱特变换(DHT)。DHT 将使用形成波形的离散真实值。为了实现 DHT,我们将使用快速莱特利变换 (FHT),特别是ArduinoFHT 
  
-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 库可处理 16 至 256 个样本的向量。该大小表示为 N。在这个项目中,我将使用 N=256 来实现最大分辨率,但如果内存或处理能力不足,您可以使用较小的值
  
-First, the algorithm takes 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 Hz. The highest value of the last bin will be sampling_rate/. The reasons for this relate to signal processing theory, specifically aliasing and Nyquist law. In practice, if you want to avoid any strange effects, such as higher frequencies folding” over lower frequencies, you will need to make sure to use a sampling rate that is twice the highest frequency you expect to have in the sound signal. Otherwise you are not sampling fast enough. You should also not over sample, as it will result in low ADC accuracy and wasting of FHT bins on ranges that don’t appear in the signal. I found the value of 20Khz to be a good upper frequency based on the range of my microphone and on the range of typical human hearing. As a result the, sampling at 38.4Khz (divider=32) seemed optimal. +首先,该算法接受N个实数,并得到N/2个复数。然后我们可以将数据传递给另一个函数,计算复数的幅度,得到N/2个频率区间。最终,我们得到N/2个频率区间,每个区间覆盖sampling_rate/N Hz的频率范围。最后一个区间的最大值将为sampling_rate/2。这与信号处理理论,特别是混叠和奈奎斯特定律有关。在实践中,如果你想避免任何奇怪的效果,比如更高频率的折叠到较低频率上,你需要确保使用的采样率是期望声音信号中最高频率的两倍。否则,你的采样速度不够快。你也不应该过度采样,因为这会导致低ADC精度,并浪费在信号中不存在的FHT频率区间。我发现基于我的麦克风范围和典型人类听力范围,20KHz的值是一个不错的上限频率。因此,以38.4KHz(分频器=32)进行采样似乎是最佳选择。 
- +因此对于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. +使用数据的有趣方法之一是使用分析器进行可视化,尤其是在故障排除和开发时。将以下 FHT 示例代码加载到 Arduino 或根据您的需要进行调整。它获取样本,对数据运行 FHT,并通过串行以二进制形式发送。您的 Arduino 应连接到运行 Processing 开发环境的计算机。在处理中,加载“FHT 128 通道分析器项目。我必须对项目进行更改以使其与Processing 3.0 兼容。为此,将对“size”函数的调用从“setup”函数中移至名为“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”.+
  
 {{:knowledge:electronic:pasted:20190321-124951.png|Analyzer}} {{:knowledge:electronic:pasted:20190321-124951.png|Analyzer}}
  
-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 以文本形式通过串行发送数据,让它运行一段时间,然后从串行监视器复制数据并将其粘贴到电子表格中。例如,使用类似于以下的代码:
 <code> <code>
 void MeasureFHT() void MeasureFHT()
行 267: 行 264:
 </code> </code>
  
-Then you can format the data in a spreadsheet, such as Excel, as a “3-D Surface” mesh graph. For example, see a graph of a Frequency Sweep from 1hz to 5000hz as captured and analyzed by the Arduino and FHT+然后,您可以将电子表格(例如 Excel)中的数据格式化为“3-D 曲面网格图。例如,查看 Arduino 和 FHT 捕获并分析从 1hz 到 5000hz 的频率扫描图:
 {{:knowledge:electronic:pasted:20190321-125044.png|Mesh of FHT frequency sweep}} {{:knowledge:electronic:pasted:20190321-125044.png|Mesh of FHT frequency sweep}}
  
-===== Summary =====+===== 概括 =====
  
-My code for this project can be found at github for you to experiment with.+我的这个项目的代码可以在 github 上找到,供你尝试。
  
-The Arduino can be used for relative sound level measurement and for frequency analysis/visualization. One just needs a microphone to match the use case, an Arduino, some coding and optionally the FHT library. Have fun and let me know in the comments if you make something nice using such a setup.+Arduino 可用于相对声级测量和频率分析/可视化。只需要一个与用例匹配的麦克风、一个 Arduino、一些编码以及可选的 FHT 库。祝你玩得开心,如果你使用这样的设置做了一些不错的事情,请在评论中告诉我。
  
 https://blog.yavilevich.com/2016/08/arduino-sound-level-meter-and-spectrum-analyzer/ https://blog.yavilevich.com/2016/08/arduino-sound-level-meter-and-spectrum-analyzer/
  
  
knowledge/electronic/2019032101.1688701672.txt · 最后更改: 2023/07/07 03:47 由 ob