From f26c24f83eba172804efbdf506cf18d19f48b176 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Fri, 17 Apr 2015 11:09:45 +0200 Subject: Import project --- .gitignore | 186 +++++++++++++++++++++++++++++++++++++++++++++++ arduino/fht_test.ino | 68 +++++++++++++++++ visualizer/visualizer.py | 53 ++++++++++++++ 3 files changed, 307 insertions(+) create mode 100644 .gitignore create mode 100644 arduino/fht_test.ino create mode 100644 visualizer/visualizer.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..470d88b --- /dev/null +++ b/.gitignore @@ -0,0 +1,186 @@ +# Created by .ignore support plugin (hsz.mobi) + +### C++ template +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + + +### Vim template +[._]*.s[a-w][a-z] +[._]s[a-w][a-z] +*.un~ +Session.vim +.netrwhist +*~ + + +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm + +*.iml + +## Directory-based project format: +.idea/ +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties + + +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + + +### C template +# Object files +*.o +*.ko +*.obj +*.elf + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ + + 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 @@ + +// FHT Options +#define FHT_N 256 +#define SCALE 256 +#define WINDOW 1 +#define REORDER 1 +#define LOG_OUT 1 +#define LIN_OUT 0 +#define LIN_OUT8 0 +#define OCTAVE 0 +#define OCT_NORM 0 + +#define BINS 128 + +#include + +void aquire_data() { + noInterrupts(); + + for (int i = 0; i < FHT_N; i++) { + while(!(ADCSRA & 0x10)); // wait for adc to be ready + ADCSRA = 0xf5; // restart adc + byte m = ADCL; // fetch adc data + byte j = ADCH; + int k = (j << 8) | m; // form into an int + k -= 0x0200; // form into a signed int + k <<= 6; // form into a 16b signed int + fht_input[i] = k; // put real data into bins + } + + interrupts(); +} + +void crunch_data() { + fht_window(); + fht_reorder(); + fht_run(); + //fht_mag_octave(); + fht_mag_log(); +} + +void setup() { + + Serial.begin(115200); + + TIMSK0 = 0; // turn off timer0 for lower jitter + ADCSRA = 0xe5; // set the adc to free running mode + ADMUX = 0x40; // use adc0 + DIDR0 = 0x01; // turn off the digital input for adc0 + +} + +char buf[2550] = ""; + +void loop() { + aquire_data(); + crunch_data(); + + for (int i = 0; i < BINS; i++) { + Serial.print(fht_log_out[i]); + Serial.print(' '); + } + + Serial.print('\n'); + + delay(10000); +} + diff --git a/visualizer/visualizer.py b/visualizer/visualizer.py new file mode 100644 index 0000000..ed65384 --- /dev/null +++ b/visualizer/visualizer.py @@ -0,0 +1,53 @@ + +BINS = 128 + + +import serial + +s = serial.Serial("/dev/ttyACM0", 115200) + + +def acquire_data(): + + nb_val = 0 + while nb_val != BINS+1: + l = s.readline() + d = l.decode("utf8") + v = d.split(' ') + nb_val = len(v) + + n = [0] * BINS + for i in range(BINS): + try: + n[i] = int(v[i]) + + except ValueError: + n[i] = 0 + + return n + + +import matplotlib.pyplot as plt +import numpy as np + + +fig = plt.figure() +ax = fig.add_subplot(111) + +li, = ax.plot(range(BINS)) +plt.axis([0, BINS, 0, 250]) + +fig.canvas.draw() +plt.show(block=False) + + +while True: + try: + y = acquire_data() + print(y) + li.set_ydata(y) + fig.canvas.draw() + + except KeyboardInterrupt: + break + -- cgit v1.2.3