Last active
February 7, 2016 12:28
-
-
Save son0p/0fce9ae0ecb3dcfebce5 to your computer and use it in GitHub Desktop.
Revisions
-
federico lopez renamed this gist
Feb 7, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
federico lopez revised this gist
Feb 7, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ ```java // get FFT spectrum // calculate frequency (approx) // first bin is DC (freq = 0Hz) @@ -36,3 +37,4 @@ for ( 0 => int i; i < fft.size()/2; i++ ) i * samplingRate / fft.size() => float freq; <<< "bin:", i, "freq:", freq, "power:", spectral[i]$polar >>>; } ``` -
federico lopez created this gist
Feb 7, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ // get FFT spectrum // calculate frequency (approx) // first bin is DC (freq = 0Hz) // make sure to filter out the DC (signal - mean(signal) => signal) // also make sure to applying band-pass filter at Nyquist frequency // Nyquist frequency == sampling rate / 2 // Input signal SinOsc g => FFT fft => blackhole; // set samplingRate second / samp => float samplingRate; <<< "Sampling rate =", samplingRate >>>; // FFT bin size 16 => fft.size; // spectrum, first half bins, 0..N/2-1 // the rest is useless, it's only conjugate of the first half complex spectral[fft.size()/2]; // a sample frequency of the sinusoidal input 5500 => g.freq; // let fft.size samples pass fft.size()::samp => now; // take fast fourier transform fft.upchuck(); // get the spectrum fft.spectrum( spectral ); // display spectrum at Nth bin <<< "Spectrum:" >>>; for ( 0 => int i; i < fft.size()/2; i++ ) { i * samplingRate / fft.size() => float freq; <<< "bin:", i, "freq:", freq, "power:", spectral[i]$polar >>>; }