STM32F1 CMSIS DSP Filtering Functions

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

Previous topic - Next topic

tha



Returns

The function คืนค่า ARM_MATH_SUCCESS ถ้า initialization สำเร็จหรือ ARM_MATH_ARGUMENT_ERROR ถ้า numTaps ไม่ใหญ่กว่าหรือเท่ากับ 4 และคู่.

Description:

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

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

โปรดทราบว่า numTaps ต้องเป็นคู่และใหญ่กว่าหรือเท่ากับ 4. เพื่อจัดให้มีใช้ an odd length filter เพิ่มง่ายๆ numTaps ขึ้น 1 และเซ็ต the last coefficient เป็นศูนย์. ตัวอย่างเช่น, เพื่อจัดให้มีใช้ filter ที่มี numTaps=3 และ coefficients
    {0.3, -0.8, 0.3}
เซ็ต numTaps=4 และใช้ the coefficients:
    {0.3, -0.8, 0.3, 0}.
คล้ายกัน, เพื่อจัดให้มีใช้ a two point filter
    {0.3, -0.3}
เซ็ต numTaps=4 และใช้ the coefficients:
    {0.3, -0.3, 0, 0}.

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

References ARM_MATH_ARGUMENT_ERROR, ARM_MATH_SUCCESS, arm_fir_instance_q15::numTaps, arm_fir_instance_q15::pCoeffs, arm_fir_instance_q15::pState, and status.

tha



Description:

pCoeffs points to the array of filter coefficients stored in time reversed order:

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

pState points to the array of state variables. pState is of length numTaps+blockSize-1 samples, where blockSize is the number of input samples processed by each call to arm_fir_q31().

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

tha



Description:

pCoeffs points to the array of filter coefficients stored in time reversed order:

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

pState points to the array of state variables. pState is of length numTaps+blockSize-1 samples, where blockSize is the number of input samples processed by each call to arm_fir_q7().

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


tha



Restrictions

ถ้า the silicon ไม่รองรับ unaligned memory access enable the macro UNALIGNED_SUPPORT_DISABLE ในกรณีนี้, output, state buffers ควรถูกวางแนวโดย 32-bit

Scaling and Overflow Behavior:

The function ถูกจัดให้มีใช้โดยใช้ a 64-bit internal accumulator. ทั้ง coefficients and state variables ถูกแสดงใน 1.15 format และการคูณให้ผล a 2.30 result. The 2.30 intermediate results ถูกสะสมใน a 64-bit accumulator ใน 34.30 format. ไม่มีความเสี่ยงของ internal overflow ด้วยความเข้าใกล้นี้และ the full precision of intermediate multiplications ถูกรักษา. หลังจากทุก additions ถูกดำเนินการแล้ว, the accumulator ถูกตัดเป็น 34.15 format โดยการทิ้ง low 15 bits. สุดท้ายy, the accumulator ถูกทำให้อิ่มตัวเพื่อให้ผล a result in 1.15 format.

อ้างอิงถึง the function arm_fir_fast_q15() สำหรับความเร็วกว่าแต่ความเที่ยงตรงน้อยกว่า implementation ของฟังชั่นนี้.

References blockSize, arm_fir_instance_q15::numTaps, arm_fir_instance_q15::pCoeffs, and arm_fir_instance_q15::pState.

tha



Scaling and Overflow Behavior:

The function ถูกจัดให้มีใช้โดยใช้ an internal 64-bit accumulator. The accumulator มี a 2.62 format และรักษา full precision of the intermediate multiplication results แต่จัดให้มีเฉพาะ a single guard bit. ดังนั้น, ถ้า the accumulator result โอเวอร์โฟวส์มันจะพันรอบมากกว่าการตัด. เพื่อหลีกเลี่ยง overflows อย่างสมบูรณ์ the input signal ต้องถูกลดขนาดลง log2(numTaps) bits. หลังจากทุก multiply-accumulates ถูกดำเนินการ, the 2.62 accumulator ถูกเลื่อนไปทางขวา 31 bits และถูกทำให้อิ่มตัวเป็น 1.31 format เพื่อให้ผล the final result.

Refer to the function arm_fir_fast_q31() for a faster but less precise implementation of this filter for Cortex-M3 and Cortex-M4.

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

tha



Scaling and Overflow Behavior:

The function ถูกจัดให้มีใช้โดยใช้ a 64-bit internal accumulator. ทั้ง coefficients and state variables ถูกแสดงใน 1.7 format และการคูณให้ผล a 2.14 result. The 2.14 intermediate results ถูกสะสมใน a 32-bit accumulator ใน 18.14 format. ไม่มีความเสี่ยงของ internal overflow ด้วยความเข้าใกล้นี้และ the full precision of intermediate multiplications ถูกรักษา. The accumulator ถูกแปลงเป็น 18.7 format โดยการทิ้ง the low 7 bits. สุดท้าย, the result ถูกตัดเป็น 1.7 format.

References blockSize, arm_fir_instance_q7::numTaps, arm_fir_instance_q7::pCoeffs, and arm_fir_instance_q7::pState.

tha

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




Description

ชุดของฟังก์ชันนี้จัดให้มีใช้ arbitrary order recursive (IIR) filters. The filters ถูกจัดให้มีใช้อย่างการต่อเป็นหลั่นๆของ second order Biquad sections. The functions รองรับ Q15, Q31 and floating-point data types. Fast version ของ Q15 and Q31 รองรับอีกด้วยบน CortexM4 and Cortex-M3.

The functions ทำงานบน blocks of input and output data และแต่ละการเรียกไปยัง the function จะประมวลผล blockSize samples ผ่าน the filter. pSrc ชี้ไปยัง the array of input data และ pDst ชี้ไปยัง the array of output data. ทั้งสอง arrays บรรจุ blockSize values.

Algorithm

แต่ละ Biquad stage จัดให้มีใช้ a second order filter โดยใช้ the difference equation:

    y[n] = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2]

A Direct Form I algorithm ถูกใช้ด้วย 5 coefficients และ 4 state variables ต่อ stage.

         

Coefficients b0, b1 and b2 คูณกับ the input signal x[n] และถูกเรียกว่า the feedforward coefficients. Coefficients a1 and a2 คูณกับ the output signal y[n] และถูกเรียกว่า the feedback coefficients. ให้ความสนใจอย่างระมัดระวังกับเครื่องหมายของ the feedback coefficients. บาง design tools ใช้ the difference equation

      y[n] = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] - a1 * y[n-1] - a2 * y[n-2]

ในกรณีนี้ the feedback coefficients a1 and a2 ต้องถูกลบล้างเมื่อถูกใช้กับ the CMSIS DSP Library.

Higher order filters ถูกรับรู้เป็นการต่อเป็นหลั่นๆของ second order sections. numStages อ้างอิงถึง the number of second order stages ที่ใช้. ตัวอย่างเช่น, an 8th order filter จะถูกรับรู้ด้วย numStages=4 second order stages.



A 9th order filter จะถูกรับรู้ด้วย numStages=5 second order stages ที่มี the coefficients สำหรับอันหนึ่งของ the stages ถูกกำหนดค่าเป็น a first order filter (b2=0 and a2=0).

The pState ชี้ไปยัง state variables array. แต่ละ Biquad stage มี 4 state variables x[n-1], x[n-2], y[n-1], and y[n-2]. The state variables ถูกจัดเรียงใน the pState array เป็น :

      {x[n-1], x[n-2], y[n-1], y[n-2]}

The 4 state variables สำหรับ stage 1 เป็นอันดับแรก, จากนั้น the 4 state variables สำหรับ stage 2, และต่อไป. The state array มีความยาวรวม 4*numStages values. 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 3 supported data types.

Init Functions

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

•   เซ็ตค่าของ the internal structure fields.
•   ทำให้เป็นศูนย์ค่าใน 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 3 different data type filter instance structures

    arm_biquad_casd_df1_inst_f32 S1 = {numStages, pState, pCoeffs};
    arm_biquad_casd_df1_inst_q15 S2 = {numStages, pState, pCoeffs, postShift};
    arm_biquad_casd_df1_inst_q31 S3 = {numStages, pState, pCoeffs, postShift};

โดยที่ numTaps คือจำนวนของ Biquad stages ใน the filter; pState คือ the address ของ the state buffer; pCoeffs คือ the address ของ the coefficient buffer. postShift shift ที่ถูกใช้.