Skip to content

Commit

Permalink
dbfs output from fft; transmit more decimal places but transmit only …
Browse files Browse the repository at this point in the history
…limited number of fft bins to speed up the transmition
  • Loading branch information
Nanu Frechen committed Oct 12, 2023
1 parent dccd789 commit 36352b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
23 changes: 14 additions & 9 deletions Teensy_prototype/FFT_visualisation/FFT_visualisation.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions Teensy_prototype/Teensy_prototype.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 36352b5

Please sign in to comment.