STM32F1 CMSIS DSP Filtering Functions

Started by tha, July 26, 2021, 07:18:31 AM

Previous topic - Next topic

tha

file:///D:/System%20Workbench/STM32CubeF1-master/Drivers/CMSIS/docs/DSP/html/group__FIR.html




Description

ชุดของ functions นี้จัดให้มีใช้งาน Finite Impulse Response (FIR) filters สำหรับ Q7, Q15, Q31, และ floating-point data types. Fast versions ของ Q15 and Q31 ถูกจัดให้มีอีกด้วย. The functions ทำงานบน blocks of input and output data และแต่ละการเรียกไปยัง the function จะประมวลผล blockSize samples ผ่าน the filter. pSrc and pDst ชี้ไปยัง input and output arrays ที่บรรจุค่า blockSize.

tha

Algorithm:

The FIR filter algorithm ขึ้นอยู่กับลำดับของ multiply-accumulate (MAC) operations. แต่ละ filter coefficient b[n] ถูกคูณด้วย a state variable ซึ่งเท่ากับ a previous input sample x[n].

y[n] = b[0] * x[n] + b[1] * x[n-1] + b[2] * x[n-2] + ...+ b[numTaps-1] * x[n-numTaps+1]

     

pCoeffs ชี้ไปยัง a coefficient array ขนาด numTaps. Coefficients ถูกเก็บใน time reversed order.

{b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}

pState ชี้ไปยัง a state array ขนาด numTaps + blockSize - 1. Samples ใน the state buffer ถูกเก็บในลำดับต่อไปนี้.

{x[n-numTaps+1], x[n-numTaps], x[n-numTaps-1], x[n-numTaps-2]....x[0], x[1], ..., x[blockSize-1]}

โปรดทราบว่าความยาวของ the state buffer เกินความยาวของ the coefficient array ไป blockSize-1. The increased state buffer length ยอมให้ circular addressing, ซึ่งมักถูกใช้ใน the FIR filters, ถูกหลีกเลี่ยงและให้ผล a significant speed improvement. The state variables ถูกอัฟเดตหลังจากแต่ละ block of data ถูกประมวลผล; the coefficients ไม่ถูกแตะต้อง.

tha

Instance Structure

The coefficients และ state variables สำหรับ a filter ถูกเก็บเข้าด้วยกันใน an instance data structure. A separate instance structure ต้องถูกกำหนดสำหรับแต่ละ filter. Coefficient arrays อาจถูกแชร์ในหมู่ instances ทั้งหลายในขณะที่ state variable arrays ไม่สามารถถูกแชร์. มี separate instance structure declarations สำหรับแต่ละของ the 4 supported data types.


tha

Initialization Functions

มี an associated initialization function สำหรับแต่ละ data type อีกด้วย. The initialization function ดำเนินการทำงานต่อไปนี้ :

   •   เซ็ตค่าของ the internal structure fields.
   •   ทำให้เป็นศูนย์ the value ใน the state buffer. เพื่อทำนี้แบบ manual โดยไม่มีการเรียก the init function, กำหนดฟิลด์ย่อยต่อ
       ไปนี้ของ the instance structure: numTaps, pCoeffs, pState. เซ็ตทั้งหมดของค่าใน pState เป็นศูนย์อีกด้วย.

การใช้ของ the initialization function เป็นทางเลือก. อย่างไรก็ตาม, ถ้า the initialization function ถูกใช้, ดังนั้น the instance structure ไม่สามารถถูกวางลงใน a const data section. เพื่อวาง an instance structure ลงใน a const data section, the instance structure ต้องถูกเริ่มต้นแบบ manual. เซ็ตค่าใน the state buffer เป็นศูนย์ก่อน static initialization. The code ข้างล่างเริ่มต้นแบบคงที่แต่ละของ the 4 different data type filter instance structures

     arm_fir_instance_f32 S = {numTaps, pState, pCoeffs};
     arm_fir_instance_q31 S = {numTaps, pState, pCoeffs};
     arm_fir_instance_q15 S = {numTaps, pState, pCoeffs};
     arm_fir_instance_q7 S =  {numTaps, pState, pCoeffs};

โดยที่ numTaps คือจำนวนของ filter coefficients ใน the filter; pState คือ the address ของ the state buffer; pCoeffs คือ the address ของ the coefficient buffer.

Fixed-Point Behavior

ต้องใช้ความระมัดระวังเมื่อใช้ the fixed-point versions of the FIR filter functions. โดยเฉพาะอย่างยิ่ง, the overflow and saturation behavior of the accumulator ที่ใช้ในแต่ละ function ต้องถูกพิจารณา. อ้างอิงถึง the function specific documentation ข้างล่างสำหรับแนวทางการใช้งาน.

tha


tha



Scaling and Overflow Behavior:

fast version นี้ใช้ a 32-bit accumulator ที่มี 2.30 format. The accumulator รักษา full precision ของ the intermediate multiplication results แต่จัดให้มีเฉพาะ a single guard bit. ดังนั้น, ถ้า the accumulator result โอเวอร์โฟวส์มันจะพันรอบและบิดเบือน the result. เพื่อหลีกเลี่ยง overflows อย่างสมบูรณ์ the input signal ต้องถูกลดขนาดลง log2(numTaps) bits. The 2.30 accumulator ดังนั้นถูกตัดเป็น 2.15 format และถูกทำให้อิ่มตัวเพื่อให้ผล the 1.15 result.

อ้างอิงถึง the function arm_fir_q15() สำหรับ a slower implementation ของฟังชั่นนี้ซึ่งใช้ 64-bit accumulation เพื่อหลีกเลี่ยง wrap around distortion. ทั้ง the slow and the fast versions ใช้ the same instance structure. ใช้ the function arm_fir_init_q15() เพื่อเริ่มต้น the filter structure.

References __PKHBT, __SIMD32, __SMLAD(), __SMLADX(), _SIMD32_OFFSET, arm_fir_instance_q15::numTaps, arm_fir_instance_q15::pCoeffs, and arm_fir_instance_q15::pState.

tha



Scaling and Overflow Behavior:

ฟังชั่นนี้ถูกทำให้ดีขึ้นสำหรับความเร็วที่การใช้ไปของ fixed-point precision และ overflow protection. The result ของแต่ละ 1.31 x 1.31 multiplication ถูกตัดเป็น 2.30 format.  intermediate results เหล่านี้ถูกบวกไปยัง a 2.30 accumulator. สุดท้าย, the accumulator ถูกทำให้อิ่นตัวและถูกแปลงเป็น a 1.31 result. The fast version มี the same overflow behavior อย่าง the standard version และจัดให้มี less precision เนื่องจากมันทิ้ง the low 32 bits ของแต่ละ multiplication result. เพื่อหลีกเลี่ยง overflows อย่างสมบูรณ์ the input signal ต้องถูกลดขนาดลง log2(numTaps) bits.

อ้างอิงถึง the function arm_fir_q31() สำหรับ a slower implementation ของฟังชั่นนี้ซึ่งใช้ 64-bit accumulation เพื่อจัดให้มี higher precision. ทั้ง the slow and the fast versions ใช้ the same instance structure. ใช้ the function arm_fir_init_q31() เพื่อเริ่มต้น the filter structure.

References multAcc_32x32_keep32_R, arm_fir_instance_q31::numTaps, arm_fir_instance_q31::pCoeffs, and arm_fir_instance_q31::pState.

tha



Description:

pCoeffs ชี้ไปยัง the array of filter coefficients ถูกเก็บใน time reversed order.

{b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}

pState ชี้ไปยัง the array of state variables. pState มีความยาว numTaps + blockSize - 1 samples. โดยที่ blockSize คือจำนวนของ input samples ที่ถูกประมวลผลโดยแต่ละการเรียกไปยัง arm_fir_f32().

References arm_fir_instance_f32::numTaps, arm_fir_instance_f32::pCoeffs, and arm_fir_instance_f32::pState.

Referenced by main().