Page 2 of 3

Re: Make realtime Discrate fournier transform from i2S mic

Posted: Tue Dec 07, 2021 6:45 pm
by zaord
This should works because the 2 fondamentals are far higher than the beating frequency.

1) Do I need to do a hilbert transform before doing what you proposed me ?

2) How can I do low pass filter with micropython ?

3) Thanks a LOT :)

Re: Make realtime Discrate fournier transform from i2S mic

Posted: Wed Dec 08, 2021 9:57 am
by pythoncoder
  1. No
  2. See micropython-filters
The above repo uses STM assembler, but FIR filters are very simple and the code could easily be ported to Python. The nice bit is the website which produces coefficients from passband characteristics.

Re: Make realtime Discrate fournier transform from i2S mic

Posted: Wed Dec 08, 2021 10:11 am
by zaord
Gosh, I don't know assembler :)

I will have a look. Thanks a lot !

Re: Envelope extraction

Posted: Wed Dec 08, 2021 11:03 am
by zaord

Re: Make realtime Discrate fournier transform from i2S mic

Posted: Thu Dec 09, 2021 9:52 am
by pythoncoder
That imports fir.py which uses STM Assembler, so will only run on Pyboards and similar. I suggest you read up on FIR filtering: it really is very simple - just a weighted moving average. Writing a Python version of fir.py would be easy.

Re: Make realtime Discrate fournier transform from i2S mic

Posted: Thu Dec 09, 2021 10:25 am
by zaord
I never learn assembler at school :)
I will try to make it with your comments !

In all the case I will need the table with the coefficient right ?

Re: Make realtime Discrate fournier transform from i2S mic

Posted: Thu Dec 09, 2021 10:39 am
by pythoncoder
You need two arrays, one containing the data and the other the N coefficients. The result is the sum of the products of matching elements of the two arrays. The one challenge is dealing with moving the data through the array. In a realtime solution such as mine this can be done with a circular buffer. If you're not using realtime data your data array will hold the entire sample set, so you only need to change the array index to point to the next N data values to generate successive filtered results.

Re: Make realtime Discrate fournier transform from i2S mic

Posted: Thu Dec 09, 2021 11:19 am
by zaord
My application is realtime :)
I will use a buffer :)

Re: Make realtime Discrate fournier transform from i2S mic

Posted: Fri Dec 10, 2021 4:50 pm
by pythoncoder
Curiosity got the better of me so I simulated this:

Code: Select all

from math import sin, cos, pi
from array import array
import matplotlib.pyplot as plt

length = 800
a = array('f', (0 for _ in range(length)))
b = array('f', (0 for _ in range(length)))
f = 0.0  # Filtered result

for n in range(length):
    a[n] = sin(n *2 * pi / 20) + 0.9 * sin(n * 2 * pi * 22 /(20 * 20))
    if a[n] < 0:
        a[n] = -a[n]
    f += a[n]
    f -= f/20  #IIR single pole filter
    b[n] = f

plt.plot(range(length), b)
plt.show()
with this outcome:
Image

Note that the filtering is a crude single pole IIR design: trivial to code but not too effective.

Re: Make realtime Discrate fournier transform from i2S mic

Posted: Mon Dec 13, 2021 9:50 pm
by zaord
Good !
How to find the fundamental frequency of this output in micropython with a realtime optimization ? i should double it due to absolute value opération right ?
You think I should use a fft ?

Best

Ewen