FFT Fast Fourier Transform algorithm suitable for single-chip microcomputer, 51 single-chip microcomputer can be used

Publisher:星际穿越Latest update time:2022-07-13 Source: csdnKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere


#define Sample_Frequency 800 //Sampling frequency 800Hz

#define Frequency 100 //Test signal 100Hz


for (i = 0; i < FFT_N; ++i) //Use the Refresh_Data(Compx, i, wave_data) function to fill in data. Here, a 100Hz square wave test signal is created.

if (sin(2 * PI * Frequency * i / Sample_Frequency) > 0)

Refresh_Data(Compx, i, 1);

else if (sin(2 * PI * Frequency * i / Sample_Frequency) < 0)

Refresh_Data(Compx, i, -1);

else

Refresh_Data(Compx, i, 0);

}


create_sin_tab(SIN_TAB); //Create a sine signal table, and then use the table lookup method to calculate the sine value to speed up the calculation

FFT(Compx); //Fast Fourier Transform

Get_Result(Compx, Sample_Frequency); //Get the modulus of the transformed result, store it in the real part of the complex number, store the frequency in the imaginary part of the complex number, and the valid data is the first FFT_N/2 numbers


Effect

insert image description here

Method to calculate frequency:

The sampling frequency is 800Hz, with a total of 16 points, so one grid = 800Hz / 16 = 50 Hz

As shown in the figure, there is a peak in the third grid and the seventh grid respectively, and the corresponding frequencies are 2 x 50Hz = 100Hz and 6 x 50Hz = 300Hz. The results have been calculated by the Get_Result function and stored in the imaginary part of the original array.


For an interpretation of the physical meaning, see How to use FFT (Fast Fourier Transform) to find amplitude and frequency (very detailed including the derivation process) - Xav Pan


performance

Crystal frequency 11.0592MHz 6T mode (22.1184MHz 12T)

The simulation time is about 0.13222819 - 0.06633789 = 0.0658903 (s)

That is, to complete a 16-point FFT transformation, the 11.0592MHz 6T 51 microcontroller takes 65.8903 ms.

insert image description here
insert image description here

The same program, using Vs 2015, runs 65536 points and the calculation results are:

insert image description here

The same data is calculated using Python for 800 points:

Source: The most detailed tutorial on implementing Fast Fourier Transform (FFT) using Python (scipy and numpy) - LoveMIss-Y

insert image description here
insert image description here

Other parts of the code

For some codes of dot matrix screen, please refer to [51 MCU Quick Start Guide] 2.4: IO Expansion (Serial to Parallel) and LED Dot Matrix Screen


main.c

#include

#include "intrins.h"

#include "stdint.h"

#include "FFT.h"

#include

#include "HC74595.h"


void main(void)

{

uint8_t i, j; 

double Largest = 0;


#define Sample_Frequency 800 //Sampling frequency 800Hz

#define Frequency 100 //Test signal 100Hz


for (i = 0; i < FFT_N; ++i) //Use the Refresh_Data(Compx, i, wave_data) function to fill in data. Here, a 100Hz square wave signal is created.

if (sin(2 * PI * Frequency * i / Sample_Frequency) > 0)

Refresh_Data(Compx, i, 1);

else if (sin(2 * PI * Frequency * i / Sample_Frequency) < 0)

Refresh_Data(Compx, i, -1);

else

Refresh_Data(Compx, i, 0);

}


create_sin_tab(SIN_TAB); //Create a sine signal table, and then use the table lookup method to calculate the sine value to speed up the calculation

FFT(Compx); //Fast Fourier Transform

Get_Result(Compx, Sample_Frequency); //Get the modulus of the transformed result, store it in the real part of the complex number, store the frequency in the imaginary part of the complex number, and the valid data is the first FFT_N/2 numbers


for (i = 0; i < FFT_N / 2; ++i) // Process the calculation results into the image part

{         

if(Compx[i].real > Largest)

Largest = Compx[i].real;

}

for(i = 0; i < 8; ++i)

{

for(j = 0; j < (uint8_t)((Compx[i].real / Largest) * 8 + 0.5); ++j)

Mat[8 - j - 1][i] = 1;

}


while(1)

{

imshow(Mat); //Display image

}

}

[1] [2]
Keywords:MCU Reference address:FFT Fast Fourier Transform algorithm suitable for single-chip microcomputer, 51 single-chip microcomputer can be used

Previous article:Precautions for using recursion on 51 MCU
Next article:[51 MCU Quick Start Guide] Simulation Example: Function Generator with Adjustable Amplitude and Adjustable Frequency

Recommended ReadingLatest update time:2024-11-17 03:07

51 MCU software program reset
51 MCU software reset assembly code        POP ACC; pop return address        POP ACC     ; Pop up PC         MOV SP,#30H ; After reset, SP is 07H, which will reset the stack         MOV PSW,#00H ; Clear register         CLR A ; push 0 as new         PUSH ACC ; return address to stack         PUSH AC
[Microcontroller]
Indian startup Mindgrove launches the country's first independently designed and commercialized MCU
This new RISC-V based SoC is the first microprocessor to be completely owned, designed and sold to the open market by India. Although semiconductor technology is related to the national security of almost every country, chip manufacturing is still limited to a few countries. The U.S. International Trade A
[Embedded]
Indian startup Mindgrove launches the country's first independently designed and commercialized MCU
[Zero Foundation] Thoroughly understand various models of 51 microcontrollers (ATMEL series)
Zero, Introduction When beginners start to learn 51 single-chip microcomputers, they are often stunned at first. They are supposed to be 51 single-chip microcomputers, but why is the model AT89C52? What about this S52? When they were in school, most of them used it in a confused way, but they never understood i
[Microcontroller]
[Zero Foundation] Thoroughly understand various models of 51 microcontrollers (ATMEL series)
Application of PHILIPS 51LPC series microcontroller
    1. Introduction     PHILIPS 51LPC series microcontrollers currently include seven models, P87LPC760/1/2/4/7/8/9. 51LPC provides high-speed and low-speed crystal oscillator and RC oscillation modes, which can be selected programmably; it has a wide operating voltage range of 2.7~6.0V, programmable I/O port line out
[Microcontroller]
Application of PHILIPS 51LPC series microcontroller
Several issues that need attention in PIC microcontroller development
1 How to further reduce power consumption Power consumption is an important consideration in battery-powered instruments. The PIC16C×× series microcontrollers have low power consumption (the operating current is less than 2mA at 5V, 4MHz oscillation frequency). To further reduce power consumption, the operating freq
[Microcontroller]
MCU software design based on RTX51
1 Overview Many MCU applications need to execute many tasks at the same time. For such applications, we can use real-time operating systems to flexibly arrange system resources. RTX51 is a small real-time multitasking operating system developed by Keil Corporation of the United States for MCS51 series MCUs. It can w
[Microcontroller]
MCU software design based on RTX51
Summary of using single chip microcomputer to drive LED digital tube display
There are many ways to drive LED digital tubes with a single-chip microcomputer. According to the display mode, there are static display and dynamic (scanning) display. According to the decoding method, there are hardware decoding and software decoding.   Static display means that the display driver circuit has an out
[Microcontroller]
DS1629 and its interface design with single-chip microcomputer
Structural characteristics of 1DS1629 DS1629 is a chip designed specifically for convenient digital measurement of temperature. The temperature measurement accuracy is ±2.0℃ (typical value). DS1629 consists of 6 parts: digital temperature sensor, real-time clock, two-wire serial interface, data register, t
[Microcontroller]
DS1629 and its interface design with single-chip microcomputer
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号