Skip to content

Commit 86720cf

Browse files
authored
Update readme.md
1 parent 8529a22 commit 86720cf

File tree

1 file changed

+37
-1
lines changed
  • projects/18-01-11_microphone_spectrograph

1 file changed

+37
-1
lines changed
Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,38 @@
11
# Realtime Spectrograph
2-
write-up in progress...
2+
3+
* **YouTube Demonstration: https://youtu.be/MS1Qgo710Vo**
4+
* This examples uses [naudio](https://github.com/naudio/NAudio) library to access the sound card
5+
* Unlike previous examples in this repository, the FFT is calculated using nAudio (not Accord)
6+
7+
![](spectrograph.gif)
8+
9+
## Example: FFT with NAudio
10+
```c#
11+
using NAudio.Wave; // for sound card access
12+
using NAudio.Dsp; // for FastFourierTransform
13+
```
14+
15+
```c#
16+
// prepare the complex data which will be FFT'd
17+
Complex[] fft_buffer = new Complex[fft_size];
18+
for (int i=0; i < fft_size; i++)
19+
{
20+
fft_buffer[i].X = (float)(unanalyzed_values[i] * FastFourierTransform.HammingWindow(i, fft_size));
21+
fft_buffer[i].Y = 0;
22+
}
23+
24+
// perform the FFT
25+
FastFourierTransform.FFT(true, (int)Math.Log(fft_size, 2.0), fft_buffer);
26+
27+
// a list with FFT values
28+
List<double> new_data = new List<double>();
29+
for (int i = 0; i < spec_data[spec_data.Count - 1].Count; i++)
30+
{
31+
// should this be sqrt(X^2+Y^2)?
32+
double val;
33+
val = (double)fft_buffer[i].X + (double)fft_buffer[i].Y;
34+
val = Math.Abs(val);
35+
if (checkBox1.Checked) val = Math.Log(val);
36+
new_data.Add(val);
37+
}
38+
```

0 commit comments

Comments
 (0)