From 36352b571cc4a0e859baec9394a3e78dbdf65d16 Mon Sep 17 00:00:00 2001 From: Nanu Frechen Date: Thu, 12 Oct 2023 12:21:38 +0200 Subject: [PATCH] dbfs output from fft; transmit more decimal places but transmit only limited number of fft bins to speed up the transmition --- .../FFT_visualisation/FFT_visualisation.pde | 23 +++++++++++-------- Teensy_prototype/Teensy_prototype.ino | 8 +++---- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Teensy_prototype/FFT_visualisation/FFT_visualisation.pde b/Teensy_prototype/FFT_visualisation/FFT_visualisation.pde index dd76121..826a583 100644 --- a/Teensy_prototype/FFT_visualisation/FFT_visualisation.pde +++ b/Teensy_prototype/FFT_visualisation/FFT_visualisation.pde @@ -7,7 +7,7 @@ int yStart = 50; int xPos = xStart; // horizontal position of the graph int speed = 0; int oldspeed = 0; -int num_fft_bins = 511; +int num_fft_bins = 150; float[] nums = new float[num_fft_bins+3]; float mic_gain; float spec_speed = 0; @@ -65,7 +65,7 @@ void windowResized() { void draw_axis () { baseline = height-yStart; - img = createImage(1, num_fft_bins, RGB); + img = createImage(1, baseline, RGB); // axis stroke(#FFFFFF); @@ -116,15 +116,20 @@ void draw () { img.loadPixels(); int j = img.height-1; int k = 0; - for (int i = 0; i < num_fft_bins ; i++) { - float col = map(nums[k], 0, 500, 255, 0); - img.pixels[j] = color(col,col,col); - //img.pixels[j+1] = color(23,120,30); - + for (int i = 0; i < img.height ; i++) { + if(k > (num_fft_bins-1)){ + img.pixels[j] = color(255,255,255); + }else{ + + float col = map(nums[k], 120, 0, 255, 0); + img.pixels[j] = color(col,col,col); + //img.pixels[j+1] = color(23,120,30); + } j--; if(i%zoom==0){ k++; } + } //img.pixels[img.height-1-(speed*zoom)-zoom/2] = color(200,20,40); img.updatePixels(); @@ -148,12 +153,12 @@ void draw () { //draw speed as text fill(255); stroke(255); - rect(width-220, 0, 220, 90); + //rect(width-220, 0, 220, 90); fill(#ff0000); textSize(104); textAlign(RIGHT); //if(peak > 0.01){ - text(round(speed*speed_conversion), width, 80); + //text(round(speed*speed_conversion), width, 80); //} if(peak >= 1.0){ fill(#ff0000); diff --git a/Teensy_prototype/Teensy_prototype.ino b/Teensy_prototype/Teensy_prototype.ino index a511fa0..740bc0a 100644 --- a/Teensy_prototype/Teensy_prototype.ino +++ b/Teensy_prototype/Teensy_prototype.ino @@ -56,7 +56,7 @@ void setup() { fft1024.windowFunction(AudioWindowHanning1024); fft1024.setNAverage(1); - fft1024.setOutputType(FFT_RMS); // FFT_RMS or FFT_POWER or FFT_DBFS + fft1024.setOutputType(FFT_DBFS); // FFT_RMS or FFT_POWER or FFT_DBFS pinMode(PIN_A8, OUTPUT); digitalWrite(PIN_A8, LOW); @@ -95,12 +95,12 @@ void loop() { if(fft1024.available()) { float* pointer = fft1024.getData(); - for (int kk=0; kk<512; kk++) saveDat[kk]= *(pointer + kk); + for (int kk=0; kk<512; kk++) saveDat[kk]= -*(pointer + kk); // output spectrum - for(i = 0; i <= 511; i++) + for(i = 0; i <= 150; i++) { - Serial.print(saveDat[i], 0); + Serial.print(saveDat[i], 2); //Serial.write((byte*)&test, sizeof(test));