Recently, we are working on Digital Filter Research to use these filters to implement some audio functions. Encountered such a problem,AlgorithmUse. m in MATLABCodeDuring the simulation, the results were good and the design was expected. However, some garbage BITs appeared in the C code, and noise appeared in terms of auditory performance, in the frequency field, some impluse in the frequency field will appear.
The reason for the analysis is that the conversion of different data types is not good enough, but it is actually some simple details, but often the Details determine the success or failure.
For example, audio typically uses 16 bits short data, but in C, float or double data is often used as the storage value for intermediate operations, this may result in converting the float or double type data to the short type in the middle or the final result.
Double result;
Short output;
If (result> 32768.0)
Result = 32768.0;
Else if (result <-32768.0)
Results =-32768.0;
Output = (short) result;
This process implies a major error because 0x8000 = 32768. But for short: ox8000 is a negative number, and the above operation will change the original maximum data to a negative number.
The direct consequence will be noise. It should be changed to the following form:
Double result;
Short output;
If (result >=32768.0)
Result = 32767.0;
Else if (result <-32768.0)
Results =-32768.0;
Output = (short) result;
A small problem is often difficult for hero. Here we record that this is accumulation of experience. If you are in the same industry, it is really good to encounter the MATLAB algorithm during algorithm design, but if you encounter such a strange problem in C implementation, you can send it to me, I will solve it with you.