Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:15 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Audio waveform & frequency in MMBasic

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 07:28pm 19 Dec 2018
Copy link to clipboard 
Print this post

Please view the video



Cycle time is 180mSec and it is running a 1024 point FFT on each channel each cycle as well as playing a WAV file, running the ADC at 10KHz per channel and updating the display !!!!!

Only on the Armmite H7 of course.


'
' OPTION LCDPANEL SSD1963_5_BUFF,RL
' OPTION SDCARD 110,87
'
Option explicit
Option default none
Option VCC 3.308
Const SAMPLESPERSEC = 10000
Const NSAMPLES = 1024
Const PLOTFREQ = NSAMPLES\512
Option autorefresh off
Dim integer i, j, imax, imax1, toggle
Dim float a(NSAMPLES-1) , b(NSAMPLES-1), a1(NSAMPLES-1), b1(NSAMPLES-1)
Dim integer c%(179), d%(179)
Dim float m(NSAMPLES-1) , mmax , m1(NSAMPLES-1), mmax1
CLS
'
' First set up some signals using the onboard DAC playing music
' connect pin 40 to pin 49 and pin 41 to pin 22
'
' start the DAC
'
Play wav "future" 'Leonard Cohen
'
' convert the signals
'
toggle=1
ADC open SAMPLESPERSEC, 49, 22,, adc_done
ADC start a(), b()
Text 10,40,"Channel 1",,3
Text 10,150,"Frequency 1",,3
Text 10,320,"Channel 2",,3
Text 10,430,"Frequency 2",,3
Do
Do
Loop While j=0
j=0
If toggle Then
ADC start a1(),b1()
toggle=0
Else
ADC start a(),b()
toggle=1
EndIf

'
' frequency analyse the signals
'
If toggle Then
FFT magnitude b1(),m()
FFT magnitude a1(),m1()
Else
FFT magnitude b(),m()
FFT magnitude a(),m1()
EndIf
Box 194,0,MM.HRes-287,MM.VRes,1,&HFFFFFF,0
'
' find the maximum magnitude of the frequencies
'
mmax=0
mmax1=0
For i=1 To NSAMPLES\2-1
If m(i)>mmax Then
mmax=m(i)
imax=i
EndIf
If m1(i)>mmax1 Then
mmax1=m1(i)
imax1=i
EndIf
Next i
'
' plot the samples
'
For i=1 To 255
If toggle Then
Line i*2+194, 130 - a1(i-1)*40, i*2+195, 130 - a1(i)*40, 1, RGB(magenta)
Line i*2+194, 410 - b1(i-1)*50, i*2+195, 410 - b1(i)*50, 1, RGB(green)
Else
Line i*2+194, 130 - a(i-1)*40, i*2+195, 130 - a(i)*40, 1, RGB(magenta)
Line i*2+194, 410 - b(i-1)*50, i*2+195, 410 - b(i)*50, 1, RGB(green)
EndIf
Next i
'
' plot the frequency analyses
'
For i=2 To 255
Line i*2+193,470-m((i-1)*PLOTFREQ/2)/mmax*100 ,i*2+194, 470 - m(i*PLOTFREQ/
2)/mmax*100 , 1, RGB(yellow)
Line i*2+193,190-m1((i-1)*PLOTFREQ/2)/mmax1*100, i*2+194, 190 - m1(i*PLOTFR
EQ/2)/mmax1*100, 1, RGB(yellow)
Next i
Refresh
Loop
'
End

Sub adc_done
j=1
End Sub

Edited by matherp 2018-12-21
 
2001cpx

Regular Member

Joined: 03/10/2013
Location: Canada
Posts: 59
Posted: 11:04pm 19 Dec 2018
Copy link to clipboard 
Print this post

Hi,

Great Work!

Very Impressive!!!

a bandpass Filter Using ADC and Dac can be Possible?

Very Interesting!!


Thanks!

"Color Maximite,(Duinomite-Mega,Mini),CGmmStick,GCmicroboard2b,Micromite + explore 64,100,LCD backpack,Lcd Backpack V2,TFT Backpack,Micromite Extreme,Armmite L,F,H,CMM2"
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1114
Posted: 03:07am 20 Dec 2018
Copy link to clipboard 
Print this post

Fantastic work Peter, very impressive. Is the FFT function part of the H7 MMBasic or something you are working on including?

panky

... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 04:04am 20 Dec 2018
Copy link to clipboard 
Print this post

@panky
It's in the latest firmware for the H7

Jim
VK7JH
MMedit
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 07:14am 20 Dec 2018
Copy link to clipboard 
Print this post

My first attempt with an MPU-6050 gyro measuring a tremor.
Most of the code is Peter's audio example with my bit filling the array with motion data from the gyro.
The readings were taken at 10mS intervals.


I saved the screen as an image after drawing it.
It takes a long time to transfer a 800x480 BMP with xmodem!

The measured 5.47 Hz is right in the expected range.
VK7JH
MMedit
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 08:26am 20 Dec 2018
Copy link to clipboard 
Print this post

Jim

I'm delighted its working for you.
Attached updated version of my program that uses a drawing optimisation that I'd forgotten about - significantly improves cycle time. The change should be obvious.


'
' OPTION LCDPANEL SSD1963_5_BUFF,RL
' OPTION SDCARD 110,87
'
Option explicit
Option default none
Option VCC 3.308
Const SAMPLESPERSEC = 10000
Const NSAMPLES = 512
Const PLOTFREQ = NSAMPLES/1024
Option autorefresh off
Dim integer i, j, imax, imax1, toggle
Dim float a(NSAMPLES-1) , b(NSAMPLES-1), a1(NSAMPLES-1), b1(NSAMPLES-1)
Dim integer c%(179), d%(179), x1(255),x2(255),y1(255), y2(255), y3(255), y4(255)
Dim float m(NSAMPLES-1) , mmax , m1(NSAMPLES-1), mmax1
CLS
For i=0 To 255
x1(i)= i*2+194
x2(i)= i*2+195
Next i

'
' First set up some signals using the onboard DAC playing music
' connect pin 40 to pin 49 and pin 41 to pin 22
'
' start the DAC
'
Play wav "future"

'
' convert the signals
'
toggle=1
ADC open SAMPLESPERSEC, 49, 22,, adc_done
ADC start a(), b()
Text 10,40,"Channel 1",,3
Text 10,150,"Frequency 1",,3
Text 10,320,"Channel 2",,3
Text 10,430,"Frequency 2",,3
Do
Do
Loop While j=0
j=0
If toggle Then
ADC start a1(),b1()
toggle=0
Else
ADC start a(),b()
toggle=1
EndIf

'
' frequency analyse the signals
'
If toggle Then
FFT magnitude b1(),m()
FFT magnitude a1(),m1()
Else
FFT magnitude b(),m()
FFT magnitude a(),m1()
EndIf
Box 194,0,MM.HRes-287,MM.VRes,1,&HFFFFFF,0
'
' find the maximum magnitude of the frequencies
'
mmax=0
mmax1=0
For i=1 To NSAMPLES\2-1
If m(i)>mmax Then
mmax=m(i)
imax=i
EndIf
If m1(i)>mmax1 Then
mmax1=m1(i)
imax1=i
EndIf
Next i
mmax=mmax / 100
mmax1=mmax1 /100
'
' plot the samples
'
For i=1 To 255
If toggle Then
y1(i)=130 - a1(i-1)*40
y2(i)=130 - a1(i)*40
y3(i)=410 - b1(i-1)*40
y4(i)=410 - b1(i)*40
Else
y1(i)=130 - a(i-1)*40
y2(i)=130 - a(i)*40
y3(i)=410 - b(i-1)*40
y4(i)=410 - b(i)*40
EndIf
Next i
Line x1(),y1(),x2(),y2(),1,RGB(magenta)
Line x1(),y3(),x2(),y4(),1,RGB(green)
'
' plot the frequency analyses
'
For i=2 To 255
y1(i)=470-m((i-1)*PLOTFREQ)/mmax
y2(i)=470 - m(i*PLOTFREQ)/mmax
y3(i)=190-m1((i-1)*PLOTFREQ)/mmax1
y4(i)=190 - m1(i*PLOTFREQ)/mmax1
Next i
Line x1(),y1(),x2(),y2(),1,RGB(yellow)
Line x1(),y3(),x2(),y4(),1,RGB(yellow)
Refresh
Loop
'
End

Sub adc_done
j=1
End Sub
Edited by matherp 2018-12-21
 
Gray
Newbie

Joined: 26/08/2017
Location: Australia
Posts: 1
Posted: 09:35am 20 Dec 2018
Copy link to clipboard 
Print this post

Wow that's awesome work matherp.
A MM Spectrum Analyser would make a fantastic project.
What would the minimum and maximum frequency range be?
Graham
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 09:46am 20 Dec 2018
Copy link to clipboard 
Print this post

  Quote  What would the minimum and maximum frequency range be?

Maximum sample rate of ADC is 500KHz, slowest - very
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1882
Posted: 03:50am 28 Dec 2018
Copy link to clipboard 
Print this post

Hi matherp, the option for SSD1963 with buffer will only allow 5" or 7" not 8"

OPTION LCDPANEL SSD1963_n_BUFF, orientation

Selects 16-bit bus operation of the 5” and 7” SSD1963 displays
using a memory framebuffer for improved performance. This
uses 400K of memory leaving 98K for user programs.

Apart from oversight with so many thing going on (all great BTW), is there any reason why SSD1963_8_BUFF cannot be added to that option?

Mike.


NANO Inverter: Full download - Only Hex Ver 8.1Ks
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1882
Posted: 11:07pm 28 Dec 2018
Copy link to clipboard 
Print this post

Thanks for the updated buffer option, for anyone new reading this thread, the latest update is at Updated firmware and manual for H7

NANO Inverter: Full download - Only Hex Ver 8.1Ks
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025