I am having a weird problem where my array of samples (uint16_t) will get altered after data processing. I tried the const qualifier, I tried malloc and memcpy, I tried dummy variables, yet the original sample array still gets affected. The data processing function is a low pass filter, which in this case is operated similar to a moving weighted average. It multiplies some coefficient with the samples around the current sample and sums them together. The only reason I can think of from this function that might change this array is memory being overwritten, but I cannot find out how. I am using the LPCLink2 with the LPC4370 chip. Here is the convolution function.
static void convolute(uint16_t data[SAMPLES_PER_PULSE], const uint16_t const sample[SAMPLES_PER_PULSE]) {
for (int i = 10; i < SAMPLES_PER_PULSE; i++) {
data[i] = coefficients[0] * (sample[i+1] + sample[i-9]) + coefficients[1] * (sample[i+0] + sample[i-8]) + coefficients[2] * (sample[i-1] + sample[i-7]) + coefficients[3] * (sample[i-2] + sample[i-6]) + coefficients[4] * (sample[i-3] + sample[i-5]) + coefficients[5] * (sample[i-4]);
}
for (int i = 0; i < 10; i++) {
data[i] = data[10];
}
}
I setup my code to only display the samples array after data processing is done. I run my program with and without this function being called and without this function the samples are their expected values. With this function they are unpredictable and wrong. My full code is included as a file below