I'm making an audio filter and I don´t know what is the mistakke that I've made. Im trying to itroduce an audio signal and process it with the arduino but I don´t get what I want. I got the coefficients of the filter with the tool of matlab of Filter designer.
This is the code that I've tried to do.
I put some variables in spanish because that´s my language and I apologize if i can´t express myself in a good way because my writing mistakes. But, I hope that some one could help me. Greatings and Thanks.
When dealing with digital filters it is normal to use the concept of a ring buffer. That is a buffer (array) of size n. You then have a pointer variable for where you write to the buffer each sample you take and increment the input pointer. You then test to see if this pointer is greater than the end of he buffer and if it is you set it to the start of the buffer, which is zero. This is called wrapping round the pointer.
Then you take a copy of that input pointer and decrement it, so that it points to the last sample, get that sample and multiply by the first filter coefficient repeat the decrement and multiply making sure to wrap round this pointer when it reaches -1. When you reach the value of the input pointer you stop and output the sample you have accumulated.
Note this will only output an 8 bit value so you will have to scale the output value rather than just truncate it. You also need an 8 bit D/A converter and restoration filter to the 8 output bits of port D. Are they all free to use?
Also note that an audio input signal must be biased at the mid rail point and so the A/D reading of this mid rail point must be subtracted from the sample value you read to make the samples are zero at this point.
What your code seems to be doing is applying all the coefficients to the single input sample, this is not how digital filters work. Each coefficient must be applied to each one of the last n samples in turn.
You can't create a float type variable with this statement that only works to make two bytes into an int. after that you need to convert it into a float type variable.