2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MaixAmigo で FFT

Posted at

MaixAmigo

MaixAmigoのCPU K210はハードウェアFFTがあります。サウンドICはES8374で、アナログマイクからADCに入力します。

デモ

Sipeed社の GitHub MaixPy_script にあるデモ demo_fft_spectrum.py をES8374を使用するようにしてみました。

from es8374 import ES8374
from machine import I2C
from Maix import GPIO, I2S, FFT
import image, lcd, math

from fpioa_manager import fm

sample_rate = 38640
sample_points = 1024
fft_points = 512
hist_x_num = 50


lcd.init(freq=20000000)

fm.register(13, fm.fpioa.I2S0_MCLK, force=True)
fm.register(21, fm.fpioa.I2S0_SCLK, force=True)
fm.register(18, fm.fpioa.I2S0_WS, force=True)
fm.register(35, fm.fpioa.I2S0_IN_D0, force=True)
fm.register(34, fm.fpioa.I2S0_OUT_D2, force=True)

i2c = I2C(I2C.I2C3, freq=600*1000, sda=27, scl=24)  # amigo
dev = ES8374(i2c)
dev.setVoiceVolume(0)
dev.start(0x03)
rx = I2S(I2S.DEVICE_0, pll2=262144000, mclk=31)
rx.channel_config(rx.CHANNEL_0, rx.RECEIVER, align_mode = I2S.STANDARD_MODE)
rx.set_sample_rate(sample_rate)
img = image.Image()
if hist_x_num > 320:
    hist_x_num = 320
hist_width = int(320 / hist_x_num)#changeable
x_shift = 0
while True:
    audio = rx.record(sample_points)
    fft_res = FFT.run(audio.to_bytes(),fft_points)
    fft_amp = FFT.amplitude(fft_res)
    img = img.clear()
    x_shift = 0
    for i in range(hist_x_num):
        if fft_amp[i] > 240:
            hist_height = 240
        else:
            hist_height = fft_amp[i]
        img = img.draw_rectangle((x_shift,240-hist_height,hist_width,hist_height),[255,255,255],2,True)
        x_shift = x_shift + hist_width
    lcd.display(img)
    fft_amp.clear()

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?