From ce44d5e9c3d9ecaae05adbcf71b2c8ccd6fc2fc2 Mon Sep 17 00:00:00 2001 From: ymherklotz Date: Tue, 27 Feb 2018 13:51:19 +0000 Subject: Nearly finished last code --- lab5/RTDSP/.launches/RTDSP.launch | 2 +- lab5/RTDSP/Matlab/coeff.txt | 2 +- lab5/RTDSP/intio.c | 28 ++++++++++------------------ 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/lab5/RTDSP/.launches/RTDSP.launch b/lab5/RTDSP/.launches/RTDSP.launch index 4330703..5ff2289 100644 --- a/lab5/RTDSP/.launches/RTDSP.launch +++ b/lab5/RTDSP/.launches/RTDSP.launch @@ -13,7 +13,7 @@ - + diff --git a/lab5/RTDSP/Matlab/coeff.txt b/lab5/RTDSP/Matlab/coeff.txt index 6c1b0ff..1b9f5ae 100644 --- a/lab5/RTDSP/Matlab/coeff.txt +++ b/lab5/RTDSP/Matlab/coeff.txt @@ -1,2 +1,2 @@ -double a[] = {1.000000000000000e+00, -3.622738280081862e+00, 5.063887790131743e+00, -3.234610259864946e+00, 7.984164681552797e-01, }; +double a[] = {0.0, -3.622738280081862e+00, 5.063887790131743e+00, -3.234610259864946e+00, 7.984164681552797e-01, }; double b[] = {9.756494393306392e-02, -3.428674269973439e-01, 4.911005379625814e-01, -3.428674269973437e-01, 9.756494393306386e-02, }; diff --git a/lab5/RTDSP/intio.c b/lab5/RTDSP/intio.c index e7ae084..a083765 100644 --- a/lab5/RTDSP/intio.c +++ b/lab5/RTDSP/intio.c @@ -46,8 +46,7 @@ #include "Matlab/coeff.txt" int N = sizeof(a)/sizeof(a[0]); -short* x; -double* y; +double* d; /******************************* Global declarations ********************************/ @@ -81,9 +80,8 @@ void init_HWI(void); void ISR_AIC(void); /********************************** Main routine ************************************/ void main(){ - x = (short*)calloc(N, sizeof(short)); - y = (double*)malloc(N * sizeof(double)); - memset(y, 0.0, N * sizeof(double)); + d = (double*)malloc(N * sizeof(double)); + memset(d, 0.0, N * sizeof(double)); // initialize board and the audio port init_hardware(); @@ -132,22 +130,16 @@ void init_HWI() /******************** INTERRUPT SERVICE ROUTINE ***********************/ void ISR_AIC() { - int i = N-1; - double Y = 0.0; + int i = 0; + short x_in = mono_read_16Bit(); + double y_out = d[0]; //Shift the values - for (; i > 0; --i) { - x[i] = x[i-1]; - y[i] = y[i-1]; - - Y += x[i] * b[i] - y[i] * a[i]; + for (; i < N-2; ++i) { + d[i] = d[i+1] + b[i] * x_in - a[i] * y_out; } - - x[0] = mono_read_16Bit(); - - Y += x[0] * b[0]; - y[0] = Y; + d[N-1] = b[N-1] * x_in - a[N-1] * y_out; - mono_write_16Bit((short)Y); + mono_write_16Bit((short)d[0]); } -- cgit