Test process 1 of FFT operation using FPU + DSP library of iisf4, stm32f4fpu

Source: Internet
Author: User
Tags mathematical functions

Test process 1 of FFT operation using FPU + DSP library of iisf4, stm32f4fpu

Test environment: Microcontroller: STM32F407ZGT6 IDE: keil5.255.0.0 Firmware Library version: STM32F4xx_DSP_StdPeriph_Lib_V1.4.0

Part 1: UseSource code fileUse the void arm_cfft_radix4_f32 (const arm_cfft_radix4_instance_f32 * S, float32_t * pSrc) function to perform the FFT operation.

Prepare an empty project, configure the Keil environment, and enable FPU units that can prepare F4.

Enable the hardware floating point operation, which is equivalent to defining two macros _ FPU_USED ,__ FPU_PRESENT in C/C ++-> define.


Add global macro definition to enable all functions of DSP Library

In the figure STM32F4XX, USE_STDPERIPH_DRIVER is the configuration macro used in the new project, the new project reference: http://blog.csdn.net/qianrushi_jinxifeng/article/details/19673755

Other macros ARM_MATH_CM4 ,__ CC_ARM, ARM_MATH_MATRIX_CHECK, ARM_MATH_ROUNDING please refer to: http://blog.csdn.net/desert187/article/details/20527921


Add the source code of the DSP library used to the Project

In the directory of stm32f4_dsp_stdperiph_lib \ STM32F4xx_DSP_StdPeriph_Lib_V1.4.0 \ Libraries \ CMSIS \ DSP_Lib \ Source, the following directories are available, all of which are DSP function Libraries.


BasicMathFunctions basic mathematical functions: provides various basic arithmetic functions for floating point numbers, such as vector addition, subtraction, multiplication, division, and so on. The CommonTablesarm_common_tables.c file provides bitwise flip or related parameter tables. ComplexMathFunctions complex mathematical functions, such as vector processing, modulo operation. ControllerFunctions control function. Including sine cosine, PID motor control, vector Clarke transformation, vector Clarke inverse transformation, etc. FastMathFunctions quick mathematical functions. Provides a fast approximate sine, cosine, square root, and other mathematical functions that are faster than the CMSIS library. The FilteringFunctions filter function is mainly used for filtering functions such as FIR and LMS (least root mean square. MatrixFunctions matrix processing function. Including matrix addition, matrix initialization, matrix inversion, matrix multiplication, matrix scale, matrix subtraction, matrix transpose, and other functions. StatisticsFunctions statistical function. Such as average value, maximum value, minimum value, root-mean-square RMS, and variance/standard deviation. SupportFunctions supports function functions, such as data copying, conversion between Q format and floating-point format, and conversion between any Q format. TransformFunctions conversion function. Including complex FFT (CFFT)/complex FFT inverse (CIFFT), Real FFT (RFFT)/real FFT inverse (RIFFT), and DCT (discrete cosine transformation) and supporting initialization functions.

We need some files under CommonTables and TransformFunctions.
Add to project

In addition, we need to Include the corresponding header file path, which can be found in the path of STM32F4xx_DSP_StdPeriph_Lib_V1.4.0 \ Libraries \ CMSIS \ Include.


Compile the main () function,


#include "stm32f4xx_conf.h"
//bit operation
#include "sys.h"
#include "delay.h"
#include "usart.h"
//LCD display function
#include "Nick_lcd.h"
#include "Nick_keys.h"

#include "arm_math.h"
#define FFT_LENGTH 1024 //FFT length, default is 1024 point FFT

Float fft_inputbuf[FFT_LENGTH*2]; //FFT input and output array, this array is the input and output array of arm_cfft_radix4_f32, the previous element is the real part, the latter is the imaginary part, and each two elements represent a point.
Float fft_outputbuf[FFT_LENGTH]; //arm_cmplx_mag_f32() amplitude output array
Arm_cfft_radix4_instance_f32 scfft;

Int main(void)
{
    Delay_init(168);
    Lcd_init(0); //Initialize LCD
    Key_init();
    Uart_init(115200); //Initialize the serial port baud rate to 115200
    
    Arm_cfft_radix4_init_f32(&scfft, FFT_LENGTH, 0, 1); / / initialize the scfft structure, set FFT related parameters
    
    While(1)
    {
        U32 keyval = (u32)keys_scan(0);
        If(keyval==1)
        {
            For(int i=0;i<FFT_LENGTH;i++)//generating signal sequence
            {
                 Fft_inputbuf[2*i]=15 + 10*arm_sin_f32(2*PI*i*100/FFT_LENGTH) + \
                                   5.5*arm_sin_f32(2*PI*i*150/FFT_LENGTH); //Generate the real part
                
                 Fft_inputbuf[2*i+1]=0;//The imaginary part is all 0
            }
            Arm_cfft_radix4_f32(&scfft,fft_inputbuf); //FFT calculation (base 4)
            Arm_cmplx_mag_f32(fft_inputbuf,fft_outputbuf,FFT_LENGTH); //Compute the result of the operation to obtain the amplitude
            
            Printf("FFT Result:\r\n");
            For(int i=0;i<FFT_LENGTH;i++)
            {
                Printf("%f\r\n",fft_outputbuf[i]);
            }
        }
        Delay_ms(60);
    }
} 

Code Analysis: As shown in the code, arm_sin_f32 function is used to generate a signal with a fundamental amplitude of 15, a frequency of 5.5Hz is a range of 10, and a frequency of Hz is a range.

After the FFT operation, use the arm_cmplx_mag_f32 () function to obtain the value and print the value through the serial port.

Compile and run


Result Analysis:

Use matlab to plot the data received by the serial port, as shown below:


, Fundamental amplitude: 15360/1024 = 15

5120Hz composition range: 2/1024 * = 10

2816Hz composition range: 2/1024*5.5 =

Therefore, the result is correct. The blogger is currently in the test phase, so it is not described here.

 

Note: This operation is performed by using the source code. All source codes can be redirected and editable. But it is troublesome to add.

Next, we will use the. lib library provided by ST to perform operations directly. Link: http://www.cnblogs.com/NickQ/p/8541156.html

 

 

 

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.