summaryrefslogtreecommitdiff
path: root/arduino/fht_test.ino
diff options
context:
space:
mode:
Diffstat (limited to 'arduino/fht_test.ino')
-rw-r--r--arduino/fht_test.ino68
1 files changed, 68 insertions, 0 deletions
diff --git a/arduino/fht_test.ino b/arduino/fht_test.ino
new file mode 100644
index 0000000..0e2f83c
--- /dev/null
+++ b/arduino/fht_test.ino
@@ -0,0 +1,68 @@
1
2// FHT Options
3#define FHT_N 256
4#define SCALE 256
5#define WINDOW 1
6#define REORDER 1
7#define LOG_OUT 1
8#define LIN_OUT 0
9#define LIN_OUT8 0
10#define OCTAVE 0
11#define OCT_NORM 0
12
13#define BINS 128
14
15#include <FHT.h>
16
17void aquire_data() {
18 noInterrupts();
19
20 for (int i = 0; i < FHT_N; i++) {
21 while(!(ADCSRA & 0x10)); // wait for adc to be ready
22 ADCSRA = 0xf5; // restart adc
23 byte m = ADCL; // fetch adc data
24 byte j = ADCH;
25 int k = (j << 8) | m; // form into an int
26 k -= 0x0200; // form into a signed int
27 k <<= 6; // form into a 16b signed int
28 fht_input[i] = k; // put real data into bins
29 }
30
31 interrupts();
32}
33
34void crunch_data() {
35 fht_window();
36 fht_reorder();
37 fht_run();
38 //fht_mag_octave();
39 fht_mag_log();
40}
41
42void setup() {
43
44 Serial.begin(115200);
45
46 TIMSK0 = 0; // turn off timer0 for lower jitter
47 ADCSRA = 0xe5; // set the adc to free running mode
48 ADMUX = 0x40; // use adc0
49 DIDR0 = 0x01; // turn off the digital input for adc0
50
51}
52
53char buf[2550] = "";
54
55void loop() {
56 aquire_data();
57 crunch_data();
58
59 for (int i = 0; i < BINS; i++) {
60 Serial.print(fht_log_out[i]);
61 Serial.print(' ');
62 }
63
64 Serial.print('\n');
65
66 delay(10000);
67}
68