Skip to content

Instantly share code, notes, and snippets.

@TakehikoShimojima
Last active March 16, 2020 00:17
Show Gist options
  • Save TakehikoShimojima/bfaf858a3fe3a1bb0514112193b67a05 to your computer and use it in GitHub Desktop.
Save TakehikoShimojima/bfaf858a3fe3a1bb0514112193b67a05 to your computer and use it in GitHub Desktop.
#include "arduinoFFT.h"
arduinoFFT FFT = arduinoFFT(vReal, vImag, FFTsamples, samplingFrequency); // FFTオブジェクトを作る
for (int i = 0; i < FFTsamples; i++) { // 振動をサンプリングする
float ax, ay, az; // 加速度データを読み出す変数
long t = micros();
M5.MPU6886.getAccelData(&ax,&ay,&az); // MPU6886から加速度を取得
vReal[i] = az * 1000; // mGに変換
vImag[i] = 0;
delayMicroseconds(SAMPLE_PERIOD * 1000 - (micros() - t));
}
DCRemoval(vReal, FFTsamples); // 直流分を除去
FFT.Windowing(FFT_WIN_TYP_HAMMING, FFT_FORWARD); // 窓関数
FFT.Compute(FFT_FORWARD); // FFT処理(複素数で計算)
FFT.ComplexToMagnitude(); // 複素数を実数に変換
double x = FFT.MajorPeak();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment