diff options
Diffstat (limited to 'lab5/RTDSP/intio.c')
-rw-r--r-- | lab5/RTDSP/intio.c | 54 |
1 files changed, 21 insertions, 33 deletions
diff --git a/lab5/RTDSP/intio.c b/lab5/RTDSP/intio.c index 6c90633..124fc03 100644 --- a/lab5/RTDSP/intio.c +++ b/lab5/RTDSP/intio.c @@ -36,19 +36,16 @@ // Some functions to help with writing/reading the audio ports when using interrupts. #include <helper_functions_ISR.h> +#include "Matlab/filter_coeff.txt" // Some functions to help with configuring hardware #include "helper_functions_polling.h" // PI defined here for use in your code #define PI 3.141592653589793 -#include "Matlab/filter_coeff_ell_a.txt" -#include "Matlab/filter_coeff_ell_b.txt" - -int N = sizeof(a)/sizeof(a[0]); -short* x; -double* y; - +#define N 249 +double buffer[N]= {0}; +unsigned ptr = N-1; /******************************* Global declarations ********************************/ @@ -82,24 +79,14 @@ void ISR_AIC(void); short circ_fir(void); /********************************** Main routine ************************************/ void main(){ - int i; - x = (short*)calloc(N, sizeof(short)); - y = (double*)calloc(N, sizeof(double)); // initialize board and the audio port init_hardware(); /* initialize hardware interrupts */ init_HWI(); - - /* Initialises array to 0 */ - for (i = 0; i < N; ++i) { - y[i] = 0.0; - x[i] = 0; - } /* loop indefinitely, waiting for interrupts */ while(1) {}; - } /********************************** init_hardware() **********************************/ @@ -139,22 +126,23 @@ void init_HWI() /******************** INTERRUPT SERVICE ROUTINE ***********************/ void ISR_AIC() { - int i; - - //Shift the values - for (i = N-1; i > 0; --i) { - x[i] = x[i-1]; - y[i] = y[i-1]; + buffer[ptr] = (double) mono_read_16Bit(); + mono_write_16Bit((short)circ_fir()); + if (ptr == 0) + ptr = N; + ptr--; +} + +// Perform linear convolution +short circ_fir() +{ + double y = 0; + int i = 0; + for(; i+ptr < N; i++) { + y += buffer[i+ptr] * b[N-i-1]; } - - x[0] = mono_read_16Bit(); - y[0] = 0.0; - - for (i = 0; i < N; ++i) { - y[0] += b[i] * x[i]; - if (i != 0) - y[0] -= a[i] * y[i]; + for(; i < N; i++) { + y += buffer[i+ptr-N] * b[N-i-1]; } - - mono_write_16Bit((short)y[0]); + return y; } |