Share My Creation FFT Test Program with Source

I've attached an FFT test program with source code for B4R.
I am using B4R 2.51. My MCU is an 80MHz Wemos board.

The FFT is fast. It uses a pre-computed coefficient lookup table. It performs a double precision complex FFT.

The FFT code is in its own module and includes copy / Blackman window, scale, and magnitude squared subroutines.

I generate an integer test waveform to simulate A/D data acquisition.

With a 2000Hz sample rate and 64 sample FFT, I measure a 4.6 millisecond FFT compute time (copy/window, fft, scale, mag squared) on my MCU. This seems to easily support real-time processing of A/D audio.

*** Added Later ***
Unreal !!!
I found an error in the code for FFT.bas
B4X:
Sub ScaleFFT(x() As Double, y() As Double, scl As Double, n As Int) ' Calc magnitude square root
  For i=0 To n - 1
    x(i) = x(i) * scl
    y(i) = y(i) * scl ' <-- should be y(i) = y(i) * scl, NOT y(i) = x(i) * scl
  Next
End Sub

This error has been in this code for almost 3 decades.

upload_2019-2-16_16-9-12.png
 

Attachments

  • SpFftTst.zip
    51.6 KB · Views: 510
Last edited:

Cableguy

Expert
Licensed User
Longtime User

canalrun

Well-Known Member
Licensed User
Longtime User
I have not actually done it yet - I'm waiting for a connector from China :rolleyes:

But encoding (A/D converting) real-time audio should be easily supported up to about a 5000 Hz sample rate (if the A/D supports that rate).

My eventual goal is to A/D audio via the PC headphone jack.

Barry.
 

JohnC

Expert
Licensed User
Longtime User
I remember using FFT in the 90's to do image compression.

What real-world application were you thinking of doing with this?
 

canalrun

Well-Known Member
Licensed User
Longtime User
Skype on a PC, when it receives an incoming call, flashes a little window on the display and plays a notification sound.

The problem is if I am not in front of the PC I don't see the screen window flashing and I am deaf so the ring tone is meaningless. I need a way to be alerted of incoming calls. There are no other "alerters" supported by Skype. It's common for the deaf to flash a bulb instead of playing a notification sound.

I will use this software to continuously capture audio from the PC headphone port. When I detect noise above a certain threshold, at a certain frequency (I assume this will be coming from Skype), I will flash a Wi-Fi connected bulb.

A big problem is that if I'm playing a video on YouTube the bulb will be flashing like crazy – oh well.

I hope Skype or maybe Microsoft adds an Accessibility feature to flash a bulb whenever they have a notification instead of, or in addition to, playing some sound.


In general FFT's are great for measuring the frequency content of a signal. With MCU's the signal is very often audio, possibly from a microphone. For example old-style pushbutton telephones and some smart phones play a tone of a particular frequency whenever one of the number buttons is pressed. You can use an FFT to figure out which button was pressed then use that to perform some action. This is what PBXs do.

Barry.
 

Cableguy

Expert
Licensed User
Longtime User
For your particular purpose, why not try to catch the notification, and then via WiFi (or MQTT) set a small vibration motor along with a small LCD for incoming details?
(Just a thought)
 

canalrun

Well-Known Member
Licensed User
Longtime User
Thanks. But, catching the Windows notification was my first thought. In Windows catching notifications wasn't even possible until recently after one of the Windows 10 updates. In order to do it, it seems like you have to create a UWP program. I've looked at creating a UWP using Microsoft Visual Studio and it looks like a total mess.

If someone knows a different way, I'd love to hear it.

Then programs play games. What looks like an official Windows notification is really just custom software doing something to mimic a notification.

One guy tried to do image processing to capture the pop-up by comparing differences on the display – he said it didn't work.

Another guy tried to intercept the internal Windows message for a pop-up window opening or showing. He said it worked the first time, but they sometimes reuse a window without creating a new one and no Windows message is sent.

I think sometimes we don't appreciate how spoiled we are with the B4X development tools.

I've been sending feedback to Microsoft and the Skype forums about making a visual notification part of Accessibility. A lot of people seem to love the idea. This would not only be good for the deaf, but consider an office environment where you have computers blooping and bleeping on every desk. Substituting a lightbulb flashing gets rid of all that background noise and several bulbs can be positioned around the room to alert someone to a notification back at their desk.

Barry.
 

Cableguy

Expert
Licensed User
Longtime User
I don't use Skype so I can't really help. All I can do is throw around some ideas.
AutoIt seems to have scripts that target the notification system, and there is a jAutoIt lib...
 

canalrun

Well-Known Member
Licensed User
Longtime User
I don't use Skype so I can't really help. All I can do is throw around some ideas.
AutoIt seems to have scripts that target the notification system, and there is a jAutoIt lib...

Thanks. That has possibilities. I will have to look at that more closely.

Barry.
 
Top