// reference implementation of an FIR template <typename SampleType, typename NumericType> static void reference (const NumericType* firCoefficients, size_t numCoefficients, const SampleType* input, SampleType* output, size_t n) noexcept { if (numCoefficients == 0) {//輸出清零 zeromem (output, sizeof (SampleType) * n); return; } //分配內存 HeapBlock<SampleType> scratchBuffer (numCoefficients #if JUCE_USE_SIMD + (SIMDRegister<NumericType>::SIMDRegisterSize / sizeof (SampleType)) #endif ); #if JUCE_USE_SIMD SampleType* buffer = reinterpret_cast<SampleType*> (SIMDRegister<NumericType>::getNextSIMDAlignedPtr (reinterpret_cast<NumericType*> (scratchBuffer.getData()))); #else SampleType* buffer = scratchBuffer.getData(); #endif //內存清零 zeromem (buffer, sizeof (SampleType) * numCoefficients); for (size_t i = 0; i < n; ++i) { //滑動,將數據向右移動一個位置 for (size_t j = (numCoefficients - 1); j >= 1; --j) buffer[j] = buffer[j-1]; buffer[0] = input[i];//最新採集的數據 SampleType sum (0);//累加和清零 //重新相加 for (size_t j = 0; j < numCoefficients; ++j) sum += buffer[j] * firCoefficients[j]; output[i] = sum;//更新輸出 } }
fir濾波器
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.