DSP program for the Surfboard hardware (PCB to be open sourced) http://www.avbotz.com/ourauv/electrical/signal-processing/

Dependencies:   MODDMA SimpleIOMacros mbed-dsp mbed

Committer:
avbotz
Date:
Fri Aug 02 02:25:12 2013 +0000
Revision:
1:f69ec4c889ff
Parent:
0:2381a319fc35
Initial commit. Not working. MODDMA makes DMA setup slow, and the mbed SPI peripheral corrupts data sometimes. I will write my own SPI and DMA classes and see how it goes.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
avbotz 0:2381a319fc35 1 #include "hydro_dsp.h"
avbotz 0:2381a319fc35 2
avbotz 0:2381a319fc35 3 arm_iir_lattice_instance_q15 iir_filter[NUM_CHANNELS];
avbotz 0:2381a319fc35 4
avbotz 0:2381a319fc35 5 // TODO: need an A and B for each possible frequency
avbotz 0:2381a319fc35 6 // our pinger: 27k
avbotz 0:2381a319fc35 7 // dave's pinger(s): TODO: ask about this
avbotz 0:2381a319fc35 8 q15_t A_27k0[FILTER_ORDER] = {};
avbotz 0:2381a319fc35 9 q15_t B_27k0[FILTER_ORDER+1] = {};
avbotz 0:2381a319fc35 10
avbotz 0:2381a319fc35 11 // Set these variables to select which set of coefficients (taps) we use
avbotz 0:2381a319fc35 12 q15_t* A_select = A_27k0;
avbotz 0:2381a319fc35 13 q15_t* B_select = B_27k0;
avbotz 0:2381a319fc35 14
avbotz 0:2381a319fc35 15 q15_t state_arr[NUM_CHANNELS][FILTER_ORDER + BLOCK_SIZE];
avbotz 0:2381a319fc35 16
avbotz 0:2381a319fc35 17 q15_t filtered[BLOCK_SIZE];
avbotz 0:2381a319fc35 18
avbotz 0:2381a319fc35 19 void setup_dsp()
avbotz 0:2381a319fc35 20 {
avbotz 0:2381a319fc35 21 memset(state_arr, 0, 2*NUM_CHANNELS*(FILTER_ORDER + BLOCK_SIZE));
avbotz 0:2381a319fc35 22 for (int i = 0; i < NUM_CHANNELS; i++) {
avbotz 0:2381a319fc35 23 arm_iir_lattice_init_q15(iir_filter+i, FILTER_ORDER, A_27k0, B_27k0, state_arr[i], BLOCK_SIZE);
avbotz 0:2381a319fc35 24 }
avbotz 0:2381a319fc35 25 }
avbotz 0:2381a319fc35 26
avbotz 0:2381a319fc35 27 // Figure out where the wave starts in the filtered output
avbotz 0:2381a319fc35 28 // TODO: does this work?
avbotz 0:2381a319fc35 29 // Returns the index of the first "high" in the signal or -1 if there is none
avbotz 0:2381a319fc35 30 int find_timestamp_tdoa(q15_t* filtered)
avbotz 0:2381a319fc35 31 {
avbotz 0:2381a319fc35 32 // Uncomment the num_hits stuff if our filtering sucks
avbotz 0:2381a319fc35 33 //char num_hits = 0;
avbotz 0:2381a319fc35 34 for (int j = 0; j < BLOCK_SIZE; j++)
avbotz 0:2381a319fc35 35 {
avbotz 0:2381a319fc35 36 if (filtered[j] > TDOA_THRESH || filtered[j] < -1 * TDOA_THRESH)
avbotz 0:2381a319fc35 37 {
avbotz 0:2381a319fc35 38 return j;
avbotz 0:2381a319fc35 39 /*num_hits++;
avbotz 0:2381a319fc35 40 if (num_hits > TDOA_MIN_NUM_HITS)
avbotz 0:2381a319fc35 41 {
avbotz 0:2381a319fc35 42 return j;
avbotz 0:2381a319fc35 43 }*/
avbotz 0:2381a319fc35 44 }
avbotz 0:2381a319fc35 45 }
avbotz 0:2381a319fc35 46
avbotz 0:2381a319fc35 47 return -1;
avbotz 0:2381a319fc35 48 }