使用 Arduino Nano 在 8*8 LED 点阵上可视化不同条形的频率峰值。
它是关于什么的?
该项目是关于我们如何将复杂的信号转换为简单信号或主要信号。这里我们使用音频信号,并将它们分解成不同频率的信号。
我们正在使用傅里叶变换,它可以帮助我们分解信号。 傅里叶分析将信号从其原始域(通常是时间或空间)转换为频域中的表示。
我们通过音频信号的峰值来可视化不同的频段。并且可以在 8*8 LED 点阵上看到它。
傅里叶分析具有巨大的计算成本,这在小型计算机上是无法完成的。这就是为什么我们将使用快速傅里叶变换,这是一种计算序列的离散傅里叶变换且计算成本较低的算法,也可以在 Arduino 上完成。
Arduino 提供了一个快速傅里叶变换库,有助于更有效地完成我们的工作。
这个怎么运作?
这里的 3.5 毫米音频插孔将信号从计算机传送到电路。然后,它被馈送到额定值为 10 微法的电容器,该电容器用作滤波器。然后连接与 Arduino 模拟输入 A0 连接,因为我们将读取模拟值。它随后与一个额定 1k 欧姆的电阻器连接,接地 (0 伏),另一个与前一个接头并联,连接到正极 (+5 伏) 以实现固定增益。
结论:
使用点阵并熟悉新库是一次有趣的经历,这真的很令人兴奋。我们也可以使用液晶显示器代替LED点阵。对于大型显示器,我们需要改变的只是提高采样率。最后,它也可以是一个很好的学习工具!

项目代码
#include "fix_fft.h"
#define CLOCK 3
#define LATCH 4
#define DATA 5
#define SAMPLES 32 //define according to your need
#define AUDIO A0
char im[SAMPLES];
char data[SAMPLES];
int barht[SAMPLES];
int binary[] = {1, 2, 4, 8, 16, 32, 64, 128};
int columnBinary[] = {1, 2, 4, 8, 16, 32, 64, 128};
void setup()
{
pinMode(CLOCK,OUTPUT);
pinMode(LATCH,OUTPUT);
pinMode(DATA,OUTPUT);
}
void loop()
{
static int i, j;
int val;
// get audio data
for(i = 0; i < SAMPLES; i++)
{
val = analogRead(AUDIO); // 0-1023
data[i] = (char)(val/4 - SAMPLES); // store as char
im[i] = 0; // init all as 0
}
// run FFT
fix_fft(data, im, 5, 0); //2^5=32, as we are taking 32 samples
// extract absolute value of data only, for 32 results
for(i = 0; i < SAMPLES/2; i++)
{
barht[i] = (int)sqrt(data[i] * data[i] + im[i] * im[i]);
}
for(i = 0, j = 0; i < SAMPLES/2; i++, j += 2)
{
barht[i] = barht[j] + barht[j + 1];
}
// display barchart
for(int k = 0; k < SAMPLES/4; k++){ //as we have 8rows and 8columns, so only 8 times we need to iterate. That's why 32/4=8 .
digitalWrite(LATCH, LOW);
int x = columnBinary[barht[k]%8]-1;
shiftOut(DATA, CLOCK, LSBFIRST, ~x); // columns
shiftOut(DATA, CLOCK, LSBFIRST, binary[k]); // rows
digitalWrite(LATCH, HIGH);
}
}
【Arduino 动手做】带有 Arduino Nano 的音乐频谱可视化器
项目链接:https://www.hackster.io/rahulmohoto/music-spectrum-visualizer-with-arduino-nano-f3779e
项目作者:拉胡尔·莫霍托
项目视频 :
https://www.youtube.com/watch?v=SNRZgp_RxRk
https://www.youtube.com/watch?v=C1BSxEyZPps
电路图:https://hacksterio.s3.amazonaws.com/uploads/attachments/1239484/cktdiagram_C7cnepXvi3.fzz
项目代码:
https://www.hackster.io/code_files/497210/download
https://www.hackster.io/code_files/497219/download
https://github.com/rahulmohoto/Music-Visualizer

评论