For each function, there are types of floating-point numbers and fixed-point numbers. Since the usage methods are the same, here we only take 32 as a floating-point number as an example.
One. BasicMathFunctions
1. Absolute value
pDst[n] = abs(pSrc[n]), 0 <= n < blockSize
Example
float32_t *pSrc;
float32_t *pDst;
uint32_t blocksize;
arm_add_f32(pSrc,pDst,blocksize);
2. Sum
pDst[n] = pSrcA[n] + pSrcB[n], 0 <= n < blockSize.
example
float32_t *pSrcA;
float32_t *pSrcB;
float32_t *pDst;
uint32_t blocksize;
arm_add_f32(pSrcA,pSrcB,pDst,blocksize);3. Dot multiplication
sum = pSrcA[0]*pSrcB[0] + pSrcA[1]*pSrcB[1] + ... + pSrcA[blockSize-1]*pSrcB[blockSize-1]
example
float32_t *pSrcA;
float32_t *pSrcB;
float32_t *result;
uint32_t blocksize;
arm_dot_prod_f32(pSrcA,pSrcB,blocksize,result);4. Multiplication
sum = pSrcA[0]*pSrcB[0] + pSrcA[1]*pSrcB[1] + ... + pSrcA[blockSize-1]*pSrcB[blockSize-1]
example
float32_t *pSrcA;
float32_t *pSrcB;
float32_t *pDst;
uint32_t blocksize;
arm_mult_f32(pSrcA,pSrcB,blocksize,pDst);5. Opposite numbers
pDst[n] = -pSrc[n], 0 <= n < blockSize.
example
float32_t *pSrc;
float32_t *pDst;
uint32_t blocksize;
arm_mult_f32(pSrcA,pDst,blocksize);6. Offset
pDst[n] = pSrc[n] + offset, 0 <= n < blockSize.
example
float32_t *pSrc;
float32_t offset;
float32_t *pDst;
uint32_t blocksize;
arm_offset_f32(pSrc,offset,pDst,blocksize);7. Subtraction
pDst[n] = pSrcA[n] - pSrcB[n], 0 <= n < blockSize.
Example
float32_t *pSrcA;
float32_t *pSrcB;
float32_t *pDst;
uint32_t blocksize;
arm_sub_f32(pSrcA,pSrcB,pDst,blocksize);8. Scale factor
pDst[n] = pSrc[n] * scale, 0 <= n < blockSize.
Example
float32_t *pSrc;
float32_t scale;
float32_t *pDst;
uint32_t blocksize;
arm_scale_f32(pSrc,scale,pDst,blocksize);Two. FastMathFunctions
The functions in this block are some math.h functions that are used daily, so I won’t go into details
float32_t arm_cos_f32(float32_t x) ;
float32_t arm_sin_f32(float32_t x) ;
arm_status arm_sqrt_q31(q31_t in, q31_t * pOut);
Three.StatisticsMathFunctions
This piece is mainly for some functions that are often used in the process of statistical data analysis and processing.
1. Maximum
Calculate the maximum value in the array and return the maximum value in the array and the position of the maximum value in the array.
float32_t *pSrc;
float32_t pResult;
uint32_t blocksize;
uint32_t pIndex;
arm_max_f32(pSrc,blocksize,&pResult,&pIndex);
2. Minimum
Calculate the minimum value in the array and return the position of the maximum value and the maximum value in the array. Similar to the above usage, no further explanation.
arm_min_f32(pSrc,blocksize,&pResult,&pIndex);
3. Average
Result = (pSrc[0] + pSrc[1] + pSrc[2] + ... + pSrc[blockSize-1]) / blockSize;
float32_t *pSrc;
float32_t pResult;
uint32_t blocksize;
arm_mean_f32(pSrc,blocksize,&pResult);
4. Power
Result = pSrc[0] * pSrc[0] + pSrc[1] * pSrc[1] + pSrc[2] * pSrc[2] + ... + pSrc[blockSize-1] * pSrc[blockSize-1];
float32_t *pSrc;
float32_t pResult;
uint32_t blocksize;
arm_power_f32(pSrc,blocksize,&pResult);
5. Standard deviation
Result = sqrt((sumOfSquares - sum2 / blockSize) / (blockSize - 1))
where:
sumOfSquares = pSrc[0] * pSrc[0] + pSrc[1] * pSrc[1] + ... + pSrc[blockSize-1] * pSrc[blockSize-1]
sum = pSrc[0] + pSrc[1] + pSrc[2] + ... + pSrc[blockSize-1]
float32_t *pSrc;
float32_t pResult;
uint32_t blocksize;
arm_std_f32(pSrc,blocksize,&pResult);
6. Root Mean Square
Result = sqrt(((pSrc[0] * pSrc[0] + pSrc[1] * pSrc[1] + ... + pSrc[blockSize-1] * pSrc[blockSize-1]) / blockSize));
float32_t *pSrc;
float32_t pResult;
uint32_t blocksize;
arm_rms_f32(pSrc,blocksize,&pResult);
7. Variance
Same as above
arm_var_f32(pSrc,blocksize,&pResult);
Four. SupportFunctions
Support functions mainly include data copy, assignment and type conversion. Type conversion generally does not need to be performed in DSP, so it is omitted here.
1. Data copy
pDst[n] = pSrc[n]; 0 <= n < blockSize.
void arm_copy_f32(float32_t * pSrc, float32_t * pDst, uint32_t blockSize)
2. Data filling
pDst[n] = value; 0 <= n < blockSize.
void arm_fill_f32(float32_t value, float32_t * pDst, uint32_t blockSize)
Five. ContrillerFunctions
What is mainly introduced here is the function part of PID control.
PID controller is also called proportional integral derivative controller, and it is currently the most widely used controller. There are many methods for tuning PID parameters on the Internet. I think it is more important to first understand the meaning of PID parameters. Here is a link, https://www.zhihu.com/question/23088613/answer/81176620.
y[n] = y[n-1] + A0 * x[n] + A1 * x[n-1] + A2 * x[n-2]
A0 = Kp + Ki + Kd
A1 = (-Kp ) - (2 * Kd )
A2 = Kd
The function is defined as follows
static __INLINE float32_t arm_pid_f32(arm_pid_instance_f32 * S, float32_t in)
typedef struct
{
float32_t A0; /**< The derived gain, A0 = Kp + Ki + Kd . */
float32_t A1; /**< The derived gain, A1 = -Kp - 2Kd. */
float32_t A2; /**< The derived gain, A2 = Kd . */
float32_t state[3]; /**< The state array of length 3. */
float32_t Kp; /**< The proportional gain. */
float32_t Ki; /**< The integral gain. */
float32_t Kd; /**< The derivative gain. */
} arm_pid_instance_f32;Initialization function
void arm_pid_init_f32(arm_pid_instance_f32 * S, int32_t resetStateFlag)
This function is to obtain A0, A1, A2 through this function after configuring Kp, Ki, Kd by the user. The second parameter is the initialization flag bit, set 1 to initialize.
Reset function
void arm_pid_reset_f32(arm_pid_instance_f32 * S)
Sort function usage 1. The sort function is included in the C++ standard library whose header file is #include. The sorting method in the standard library can be used to sort the data, but we don't ne...
Detailed explanation of STM32 SYSTICK and delay function SysTick timer The SysTick timer is bundled in the NVIC and used to generate the SYSTICK exception (exception number: 15). In the past, most ope...
Recently, PID control is needed in the project. The DSP library of STM32 happens to have a DIP function, so I studied it. First look at the data parameters: When using it, you only need to set the pro...
The earliest I realized FFT was the C program code of FFT collected from the Internet, but the operation efficiency was too low, so I had to give up Later I checked the information and learned that ST...
DSP shortcut Active player in my electric competition (retired after the 21st Friendship), the main simulation direction, often use the DSP library to do conventional data such as FFT. It used to be a...
BUG prompts as follows I have been in a night, a mentally disabled, and I found that the C language compiler is compiled when the header file (.h) is compiled, it is compiled according to its order in...
CLION development STM32 call DSP library I usually do personal projects like to use CLION (team projects also want to use, but others are not familiar) recently doing projects need to use the DSP libr...
I wrote a post before, and it was super troublesome to copy and copy. It felt unreasonable, but later found that there is actually an easier way. It is very simple under IAR, just check the DSP librar...
detailed explanation of the strtol function Functional declaration Base is 0 Endptr's wonderful use Functional declaration Parameter 1:str—— String, the function will be identified from th...
STM32 serial port initialization and detailed explanation Introduction to the serial port Serial initialization steps Serial port transceiver theory Code execution Introduction to the serial port USAR...