├── .gitattributes ├── .github └── workflows │ └── tg-send.yml ├── LICENSE ├── README.md ├── README_EN.md ├── examples └── FFTtest │ └── FFTtest.ino ├── keywords.txt ├── library.properties └── src └── FFT_C.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.github/workflows/tg-send.yml: -------------------------------------------------------------------------------- 1 | 2 | name: Telegram Message 3 | on: 4 | release: 5 | types: [published] 6 | jobs: 7 | build: 8 | name: Send Message 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: send telegram message on push 12 | uses: appleboy/telegram-action@master 13 | with: 14 | to: ${{ secrets.TELEGRAM_TO }} 15 | token: ${{ secrets.TELEGRAM_TOKEN }} 16 | disable_web_page_preview: true 17 | message: | 18 | ${{ github.event.repository.name }} v${{ github.event.release.tag_name }} 19 | ${{ github.event.release.body }} 20 | https://github.com/${{ github.repository }} 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 AlexGyver 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![latest](https://img.shields.io/github/v/release/GyverLibs/FFT_C.svg?color=brightgreen)](https://github.com/GyverLibs/FFT_C/releases/latest/download/FFT_C.zip) 2 | [![PIO](https://badges.registry.platformio.org/packages/gyverlibs/library/FFT_C.svg)](https://registry.platformio.org/libraries/gyverlibs/FFT_C) 3 | [![Foo](https://img.shields.io/badge/Website-AlexGyver.ru-blue.svg?style=flat-square)](https://alexgyver.ru/) 4 | [![Foo](https://img.shields.io/badge/%E2%82%BD%24%E2%82%AC%20%D0%9F%D0%BE%D0%B4%D0%B4%D0%B5%D1%80%D0%B6%D0%B0%D1%82%D1%8C-%D0%B0%D0%B2%D1%82%D0%BE%D1%80%D0%B0-orange.svg?style=flat-square)](https://alexgyver.ru/support_alex/) 5 | [![Foo](https://img.shields.io/badge/README-ENGLISH-blueviolet.svg?style=flat-square)](https://github-com.translate.goog/GyverLibs/FFT_C?_x_tr_sl=ru&_x_tr_tl=en) 6 | 7 | [![Foo](https://img.shields.io/badge/ПОДПИСАТЬСЯ-НА%20ОБНОВЛЕНИЯ-brightgreen.svg?style=social&logo=telegram&color=blue)](https://t.me/GyverLibs) 8 | 9 | # FFT_C 10 | Библиотека преобразования Фурье на С (для esp8266) 11 | 12 | ### Совместимость 13 | Совместима со всеми Arduino платформами (используются Arduino-функции). Но задумывалась для esp8266 14 | 15 | ## Содержание 16 | - [Установка](#install) 17 | - [Инициализация](#init) 18 | - [Использование](#usage) 19 | - [Пример](#example) 20 | - [Версии](#versions) 21 | - [Баги и обратная связь](#feedback) 22 | 23 | 24 | ## Установка 25 | - Библиотеку можно найти по названию **FFT_C** и установить через менеджер библиотек в: 26 | - Arduino IDE 27 | - Arduino IDE v2 28 | - PlatformIO 29 | - [Скачать библиотеку](https://github.com/GyverLibs/FFT_C/archive/refs/heads/main.zip) .zip архивом для ручной установки: 30 | - Распаковать и положить в *C:\Program Files (x86)\Arduino\libraries* (Windows x64) 31 | - Распаковать и положить в *C:\Program Files\Arduino\libraries* (Windows x32) 32 | - Распаковать и положить в *Документы/Arduino/libraries/* 33 | - (Arduino IDE) автоматическая установка из .zip: *Скетч/Подключить библиотеку/Добавить .ZIP библиотеку…* и указать скачанный архив 34 | - Читай более подробную инструкцию по установке библиотек [здесь](https://alexgyver.ru/arduino-first/#%D0%A3%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B0_%D0%B1%D0%B8%D0%B1%D0%BB%D0%B8%D0%BE%D1%82%D0%B5%D0%BA) 35 | ### Обновление 36 | - Рекомендую всегда обновлять библиотеку: в новых версиях исправляются ошибки и баги, а также проводится оптимизация и добавляются новые фичи 37 | - Через менеджер библиотек IDE: найти библиотеку как при установке и нажать "Обновить" 38 | - Вручную: **удалить папку со старой версией**, а затем положить на её место новую. "Замену" делать нельзя: иногда в новых версиях удаляются файлы, которые останутся при замене и могут привести к ошибкам! 39 | 40 | 41 | 42 | ## Инициализация 43 | Нет 44 | 45 | 46 | ## Использование 47 | ```cpp 48 | #define FFT_SIZE 64 // перед подключением библиотеки. Должно быть кратно степени 2 49 | void FFT(int* AVal, int* FTvl); 50 | // AVal - массив анализируемых данных 51 | // FTvl - массив полученных значений 52 | ``` 53 | 54 | 55 | ## Пример 56 | Остальные примеры смотри в **examples**! 57 | ```cpp 58 | // преобразование Фурье на C (для есп8266) 59 | 60 | #define FFT_SIZE 64 // 32/64/128/256/512 61 | #include 62 | #include 63 | VolAnalyzer low, high; 64 | 65 | 66 | int raw[FFT_SIZE]; 67 | int spectr[FFT_SIZE]; 68 | 69 | #define STRIP_PIN D4 // пин ленты 70 | #define MAX_LEDS 512 // макс. светодиодов 71 | #define STRIP_CHIP WS2812 // чип ленты 72 | #define STRIP_COLOR GRB // порядок цветов в ленте 73 | #include // лента 74 | CRGB leds[8]; 75 | 76 | void setup() { 77 | FastLED.addLeds(leds, 8); 78 | FastLED.setBrightness(100); 79 | Serial.begin(9600); 80 | 81 | low.setDt(0); 82 | low.setPeriod(0); 83 | low.setWindow(0); 84 | high.setDt(0); 85 | high.setPeriod(0); 86 | high.setWindow(0); 87 | 88 | low.setVolK(25); 89 | high.setVolK(25); 90 | low.setTrsh(50); 91 | high.setTrsh(50); 92 | low.setVolMax(150); 93 | high.setVolMax(150); 94 | low.setVolMin(30); 95 | high.setVolMin(30); 96 | } 97 | 98 | void loop() { 99 | for (int i = 0; i < FFT_SIZE; i++) raw[i] = analogRead(A0); 100 | 101 | FFT(raw, spectr); 102 | int low_raw = 0; 103 | int high_raw = 0; 104 | for (int i = 0; i < FFT_SIZE / 2; i++) { 105 | spectr[i] = (spectr[i] * (i + 2)) >> 1; 106 | if (i < 2) low_raw += spectr[i]; 107 | else high_raw += spectr[i]; 108 | } 109 | 110 | low.tick(low_raw); 111 | high.tick(high_raw); 112 | 113 | FastLED.clear(); 114 | //fill_solid(leds, low.getVol() * 8 / 150, CHSV(0, 255, 255)); // полоса громкости 115 | fill_solid(leds, 8, CHSV(0, 255, high.getVol())); 116 | fill_solid(leds, 4, CHSV(150, 255, low.getVol())); 117 | FastLED.show(); 118 | Serial.print(low.getVol()); 119 | Serial.print(' '); 120 | Serial.println(high.getVol()); 121 | 122 | /* 123 | for (int i = 0; i < FFT_SIZE / 2; i++) { 124 | if (spectr[i] < 10) spectr[i] = 0; 125 | Serial.print(int(spectr[i])); 126 | Serial.print(' '); 127 | } 128 | Serial.println(); 129 | */ 130 | } 131 | 132 | ``` 133 | 134 | 135 | ## Версии 136 | - v1.0 137 | 138 | 139 | ## Баги и обратная связь 140 | При нахождении багов создавайте **Issue**, а лучше сразу пишите на почту [alex@alexgyver.ru](mailto:alex@alexgyver.ru) 141 | Библиотека открыта для доработки и ваших **Pull Request**'ов! 142 | 143 | 144 | При сообщении о багах или некорректной работе библиотеки нужно обязательно указывать: 145 | - Версия библиотеки 146 | - Какой используется МК 147 | - Версия SDK (для ESP) 148 | - Версия Arduino IDE 149 | - Корректно ли работают ли встроенные примеры, в которых используются функции и конструкции, приводящие к багу в вашем коде 150 | - Какой код загружался, какая работа от него ожидалась и как он работает в реальности 151 | - В идеале приложить минимальный код, в котором наблюдается баг. Не полотно из тысячи строк, а минимальный код 152 | -------------------------------------------------------------------------------- /README_EN.md: -------------------------------------------------------------------------------- 1 | This is an automatic translation, may be incorrect in some places. See sources and examples! 2 | 3 | # Fft_c 4 | Fourier transformation library on C (for ESP8266) 5 | 6 | ## compatibility 7 | Compatible with all arduino platforms (used arduino functions).But thought for ESP8266 8 | 9 | ## Content 10 | - [installation] (# Install) 11 | - [initialization] (#init) 12 | - [use] (#usage) 13 | - [Example] (# Example) 14 | - [versions] (#varsions) 15 | - [bugs and feedback] (#fedback) 16 | 17 | 18 | ## Installation 19 | - The library can be found by the name ** fft_c ** and installed through the library manager in: 20 | - Arduino ide 21 | - Arduino ide v2 22 | - Platformio 23 | - [download the library] (https://github.com/gyverlibs/fft_c/archive/refs/heads/main.zip) .Zip archive for manual installation: 24 | - unpack and put in * C: \ Program Files (X86) \ Arduino \ Libraries * (Windows X64) 25 | - unpack and put in * C: \ Program Files \ Arduino \ Libraries * (Windows X32) 26 | - unpack and put in *documents/arduino/libraries/ * 27 | - (Arduino id) Automatic installation from. Zip: * sketch/connect the library/add .Zip library ... * and specify downloaded archive 28 | - Read more detailed instructions for installing libraries [here] (https://alexgyver.ru/arduino-first/#%D0%A3%D1%81%D1%82%D0%B0%BD%D0%BE%BE%BE%BED0%B2%D0%BA%D0%B0_%D0%B1%D0%B8%D0%B1%D0%BB%D0%B8%D0%BE%D1%82%D0%B5%D0%BA) 29 | ### Update 30 | - I recommend always updating the library: errors and bugs are corrected in the new versions, as well as optimization and new features are added 31 | - through the IDE library manager: find the library how to install and click "update" 32 | - Manually: ** remove the folder with the old version **, and then put a new one in its place.“Replacement” cannot be done: sometimes in new versions, files that remain when replacing are deleted and can lead to errors! 33 | 34 | 35 | 36 | ## initialization 37 | No 38 | 39 | 40 | ## Usage 41 | `` `CPP 42 | #define fft_size 64 // before connecting the library.Should be a multiple of the degree of 2 43 | VOID FFT (int* aval, int* ftvl); 44 | // aval - an array of analyzed data 45 | // ftvl - an array of obtained values 46 | `` ` 47 | 48 | 49 | ## Example 50 | The rest of the examples look at ** Examples **! 51 | `` `CPP 52 | // Transformation of Fourier on C (for ECP8266) 53 | 54 | #define fft_size 64 // 32/64/128/256/512 55 | #include 56 | #include 57 | VOLANALYZER LOW, HIGH; 58 | 59 | 60 | int raw [fft_size]; 61 | int spctr [fft_size]; 62 | 63 | #define strip_pin d4 // Pin tape 64 | #define max_leds 512 // Max.LEDs 65 | #define strip_chip ws2812 // chip tapes 66 | #define strip_color GRB // Procedure of flowers in the tape 67 | #include // Tape 68 | CRGB LEDS [8]; 69 | 70 | VOID setup () { 71 | Fastled.addleds (Leds, 8); 72 | Fastled.Setbrightness (100); 73 | Serial.Begin (9600); 74 | 75 | Low.Setdt (0); 76 | Low.Setperiod (0); 77 | Low.Setwindow (0); 78 | High.Setdt (0); 79 | High.Setperiod (0); 80 | High.Setwindow (0); 81 | 82 | Low.Setvolk (25); 83 | High.Setvolk (25); 84 | Low.Settrsh (50); 85 | High.Settrsh (50); 86 | Low.Setvolmax (150); 87 | High.Setvolmax (150); 88 | Low.Setvolmin (30); 89 | High.Setvolmin (30); 90 | } 91 | 92 | VOID loop () { 93 | for (int i = 0; i > 1; 100 | if (i <2) low_RAW += spectr [i]; 101 | Else High_Raw += Spectr [i]; 102 | } 103 | 104 | L.Cranberries ow.tick (low_RAW); 105 | High.tick (High_Raw); 106 | 107 | Fastled.clear (); 108 | // Fill_SOLID (LEDS, LOW.GETVOL () * 8 /150, ChSV (0, 255, 255));// volume strip 109 | Fill_SOLID (LEDS, 8, ChSV (0, 255, High.getvol ())); 110 | Fill_SOLID (LEDS, 4, ChSV (150, 255, Low.getvol ())); 111 | Fastled.show (); 112 | Serial.print (low.getvol ()); 113 | Serial.print (''); 114 | Serial.println (High.getvol ()); 115 | 116 | /* 117 | for (int i = 0; i 129 | ## versions 130 | - V1.0 131 | 132 | 133 | ## bugs and feedback 134 | Create ** Issue ** when you find the bugs, and better immediately write to the mail [alex@alexgyver.ru] (mailto: alex@alexgyver.ru) 135 | The library is open for refinement and your ** pull Request ** 'ow! 136 | 137 | 138 | When reporting about bugs or incorrect work of the library, it is necessary to indicate: 139 | - The version of the library 140 | - What is MK used 141 | - SDK version (for ESP) 142 | - version of Arduino ide 143 | - whether the built -in examples work correctly, in which the functions and designs are used, leading to a bug in your code 144 | - what code has been loaded, what work was expected from it and how it works in reality 145 | - Ideally, attach the minimum code in which the bug is observed.Not a canvas of a thousand lines, but a minimum code -------------------------------------------------------------------------------- /examples/FFTtest/FFTtest.ino: -------------------------------------------------------------------------------- 1 | // преобразование Фурье на C (для есп8266) 2 | // AVal - массив анализируемых данных 3 | // FTvl - массив полученных значений 4 | // FFT_SIZE - длина массива должна быть кратна степени 2 5 | 6 | #define FFT_SIZE 64 // 32/64/128/256/512 7 | #include 8 | #include 9 | VolAnalyzer low, high; 10 | 11 | // это всё нинада, для тестов 12 | int raw0[] = {24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 51, 86, 114, 151, 183, 219, 246, 292, 325, 352, 369, 398, 396, 399, 394, 392, 373, 369, 368, 363, 346, 333, 300, 277, 243, 214, 170, 125, 89, 44, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 67, 97, 135, 181, 210, 243, 279, 310, 332, 362, 376, 381, 388, 393, 394, 394, 399, 403, 392, 379, 367, 344, 306, 265, 226, 182, 150, 118, 79, 44, 31, 2,}; 13 | int raw1[] = {0, 0, 138, 189, 68, 0, 0, 0, 73, 189, 139, 0, 0, 0, 13, 163, 181, 48, 0, 0, 0, 99, 194, 108, 0, 0, 0, 21, 171, 171, 17, 0, 0, 0, 123, 193, 102, 0, 0, 0, 50, 178, 164, 8, 0, 0, 0, 140, 190, 66, 0, 0, 0, 75, 193, 144, 0, 0, 0, 4, 166, 189, 58, 0, 0, 0, 105, 205, 117, 0, 0, 0, 34, 187, 174, 22, 0, 0, 0, 128, 196, 91, 0, 0, 0, 40, 176, 152, 2, 0, 0, 0, 129, 177, 66, 0, 0, 0, 57, 183, 135, 0, 0, 0, 0, 140, 176, 45, 0, 0, 0, 79, 186, 109, 0, 0, 0, 4, 154, 168, 21, 0, 0, 0, 100, 185, 102, 0,}; 14 | int raw2[] = {0, 85, 0, 156, 108, 0, 175, 81, 0, 170, 60, 0, 142, 69, 0, 165, 69, 0, 163, 68, 0, 165, 66, 0, 136, 55, 0, 182, 65, 0, 184, 75, 0, 142, 69, 0, 175, 74, 0, 202, 82, 0, 173, 72, 0, 174, 67, 0, 184, 68, 0, 197, 56, 0, 183, 68, 0, 188, 61, 0, 201, 51, 0, 211, 46, 0, 176, 46, 0, 182, 52, 0, 180, 43, 0, 188, 42, 0, 186, 62, 0, 194, 32, 0, 181, 34, 0, 190, 45, 0, 165, 44, 0, 177, 70, 0, 168, 57, 0, 186, 69, 0, 199, 26, 0, 183, 39, 0, 174, 45, 0, 182, 30, 0, 187, 32, 0, 188, 61, 0, 182, 61, 0, 182, 33, 0, 194, 40,}; 15 | // это всё нинада 16 | 17 | int raw[FFT_SIZE]; 18 | int spectr[FFT_SIZE]; 19 | 20 | #define STRIP_PIN D4 // пин ленты 21 | #define MAX_LEDS 512 // макс. светодиодов 22 | #define STRIP_CHIP WS2812 // чип ленты 23 | #define STRIP_COLOR GRB // порядок цветов в ленте 24 | #include // лента 25 | CRGB leds[8]; 26 | 27 | void setup() { 28 | FastLED.addLeds(leds, 8); 29 | FastLED.setBrightness(100); 30 | Serial.begin(9600); 31 | 32 | low.setDt(0); 33 | low.setPeriod(0); 34 | low.setWindow(0); 35 | high.setDt(0); 36 | high.setPeriod(0); 37 | high.setWindow(0); 38 | 39 | low.setVolK(25); 40 | high.setVolK(25); 41 | low.setTrsh(50); 42 | high.setTrsh(50); 43 | low.setVolMax(150); 44 | high.setVolMax(150); 45 | low.setVolMin(30); 46 | high.setVolMin(30); 47 | 48 | /* 49 | // рабочие моменты с FHT 50 | delay(3000); 51 | uint32_t us = micros(); 52 | FFT(raw0, spectr); 53 | us = micros() - us; 54 | Serial.println(us); 55 | //for (int i = 0; i < 3; i++) { 56 | FFT(raw0, spectr); 57 | for (int k = 0; k < FFT_SIZE / 2; k++) { 58 | Serial.print(int(spectr[k])); 59 | Serial.print(' '); 60 | } 61 | Serial.println(); 62 | FFT(raw1, spectr); 63 | for (int k = 0; k < FFT_SIZE / 2; k++) { 64 | Serial.print(int(spectr[k])); 65 | Serial.print(' '); 66 | } 67 | Serial.println(); 68 | FFT(raw2, spectr); 69 | for (int k = 0; k < FFT_SIZE / 2; k++) { 70 | Serial.print(int(spectr[k])); 71 | Serial.print(' '); 72 | } 73 | Serial.println(); 74 | //} 75 | */ 76 | 77 | } 78 | 79 | void loop() { 80 | for (int i = 0; i < FFT_SIZE; i++) raw[i] = analogRead(A0); 81 | 82 | FFT(raw, spectr); 83 | int low_raw = 0; 84 | int high_raw = 0; 85 | for (int i = 0; i < FFT_SIZE / 2; i++) { 86 | spectr[i] = (spectr[i] * (i + 2)) >> 1; 87 | if (i < 2) low_raw += spectr[i]; 88 | else high_raw += spectr[i]; 89 | } 90 | 91 | low.tick(low_raw); 92 | high.tick(high_raw); 93 | 94 | FastLED.clear(); 95 | //fill_solid(leds, low.getVol() * 8 / 150, CHSV(0, 255, 255)); // полоса громкости 96 | fill_solid(leds, 8, CHSV(0, 255, high.getVol())); 97 | fill_solid(leds, 4, CHSV(150, 255, low.getVol())); 98 | FastLED.show(); 99 | Serial.print(low.getVol()); 100 | Serial.print(' '); 101 | Serial.println(high.getVol()); 102 | 103 | /* 104 | for (int i = 0; i < FFT_SIZE / 2; i++) { 105 | if (spectr[i] < 10) spectr[i] = 0; 106 | Serial.print(int(spectr[i])); 107 | Serial.print(' '); 108 | } 109 | Serial.println(); 110 | */ 111 | } 112 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For FFT_C 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | FFT_C KEYWORD1 9 | 10 | ####################################### 11 | # Methods and Functions (KEYWORD2) 12 | ####################################### 13 | 14 | FFT KEYWORD2 15 | 16 | ####################################### 17 | # Constants (LITERAL1) 18 | ####################################### 19 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=FFT_C 2 | version=1.0 3 | author=AlexGyver 4 | maintainer=AlexGyver 5 | sentence=FFT library in C 6 | paragraph=FFT library in C 7 | category=Data Processing 8 | url=https://github.com/GyverLibs/FFT_C 9 | architectures=* -------------------------------------------------------------------------------- /src/FFT_C.h: -------------------------------------------------------------------------------- 1 | /* 2 | Библиотека преобразования Фурье на С (для esp8266) 3 | GitHub: https://github.com/GyverLibs/FFT_C 4 | 5 | Основано на https://ru.wikibooks.org/wiki/%D0%A0%D0%B5%D0%B0%D0%BB%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D0%B8_%D0%B0%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC%D0%BE%D0%B2/%D0%91%D1%8B%D1%81%D1%82%D1%80%D0%BE%D0%B5_%D0%BF%D1%80%D0%B5%D0%BE%D0%B1%D1%80%D0%B0%D0%B7%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5_%D0%A4%D1%83%D1%80%D1%8C%D0%B5 6 | AlexGyver, alex@alexgyver.ru 7 | https://alexgyver.ru/ 8 | MIT License 9 | 10 | Версии: 11 | v1.0 - релиз 12 | */ 13 | 14 | // AVal - массив анализируемых данных 15 | // FTvl - массив полученных значений 16 | // FFT_SIZE - длина массива должна быть кратна степени 2 17 | 18 | static float sinF[] = {0.0, -1.0, -0.707107, -0.382683, -0.195090, -0.098017, -0.049068, -0.024541, -0.012272, -0.006136}; 19 | void FFT(int* AVal, int* FTvl); 20 | 21 | void FFT(int* AVal, int* FTvl) { 22 | int i, j, m, Mmax, Istp, count = 0; 23 | float Tmpr, Tmpi, Tmvl[FFT_SIZE * 2]; 24 | float Wpr, Wr, Wi; 25 | 26 | for (i = 0; i < FFT_SIZE * 2; i += 2) { 27 | Tmvl[i] = 0; 28 | Tmvl[i + 1] = AVal[i / 2]; 29 | } 30 | 31 | i = j = 1; 32 | while (i < FFT_SIZE * 2) { 33 | if (j > i) { 34 | Tmpr = Tmvl[i]; 35 | Tmvl[i] = Tmvl[j]; 36 | Tmvl[j] = Tmpr; 37 | Tmpr = Tmvl[i + 1]; 38 | Tmvl[i + 1] = Tmvl[j + 1]; 39 | Tmvl[j + 1] = Tmpr; 40 | } 41 | i = i + 2; 42 | m = FFT_SIZE; 43 | while ((m >= 2) && (j > m)) { 44 | j = j - m; 45 | m = m >> 1; 46 | } 47 | j = j + m; 48 | } 49 | 50 | Mmax = 2; 51 | while (FFT_SIZE * 2 > Mmax) { 52 | Wpr = sinF[count + 1] * sinF[count + 1] * 2; 53 | Istp = Mmax * 2; 54 | Wr = 1; 55 | Wi = 0; 56 | m = 1; 57 | 58 | while (m < Mmax) { 59 | i = m; 60 | m = m + 2; 61 | Tmpr = Wr; 62 | Tmpi = Wi; 63 | Wr += -Tmpr * Wpr - Tmpi * sinF[count]; 64 | Wi += Tmpr * sinF[count] - Tmpi * Wpr; 65 | 66 | while (i < FFT_SIZE * 2) { 67 | j = i + Mmax; 68 | Tmpr = Wr * Tmvl[j] - Wi * Tmvl[j - 1]; 69 | Tmpi = Wi * Tmvl[j] + Wr * Tmvl[j - 1]; 70 | 71 | Tmvl[j] = Tmvl[i] - Tmpr; 72 | Tmvl[j - 1] = Tmvl[i - 1] - Tmpi; 73 | Tmvl[i] = Tmvl[i] + Tmpr; 74 | Tmvl[i - 1] = Tmvl[i - 1] + Tmpi; 75 | i = i + Istp; 76 | } 77 | } 78 | count++; 79 | Mmax = Istp; 80 | } 81 | for (i = 0; i < FFT_SIZE; i++) { 82 | j = i * 2; 83 | FTvl[i] = (int)(Tmvl[j] * Tmvl[j] + Tmvl[j + 1] * Tmvl[j + 1]) >> 18; 84 | } 85 | } --------------------------------------------------------------------------------