Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your goal is to take all magnitudes of individual frequencies in mag[i] and to find the largest one. For start, you can just loop over them and find the maximum mag[i]. Then you have to recalculate it's corresponding frequency from <code>i</code> index.</p> <p>Frequency is determined by this equation:</p> <pre><code>freq = i * Fs / N; </code></pre> <p>Where <code>Fs</code> is sampling frequency of your time domain data (input wave data), <code>N</code> - number of samples you did compute FFT from. <code>i</code> is the index of your frequency domain data (computed magnitudes and phases)</p> <p>In your case you can add line like into your for cycle to debug it:</p> <pre><code>double freq = (double)i*(double)fs/(double)N; System.out.println("Frequency: "+ Double.toString(freq) + "Magnitude: "+ Double.toString(mag[i])); </code></pre> <p>Check this link for more information: <a href="https://stackoverflow.com/questions/7674877/how-to-get-frequency-from-fft-result">How to get frequency from fft result?</a></p> <p><strong><a href="http://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem" rel="nofollow noreferrer">Nyquist theorem</a></strong></p> <p>... states that you can perfectly reconstruct frequencies only if you have twice the samples.... for reconstructing 1000Hz, you have to have at least 2000 samples per second. (Still this wave will be very distorted.).</p> <p>If you have samplerate of 22000Hz, you would be able to somehow measure frequencies up to 11000Hz. Your data in <code>mag</code> and <code>phase</code> will be meaningful to the first half of array <code>0..N/2</code>, then, you'll see just a mirror image of previous data (see the link to <a href="http://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem" rel="nofollow noreferrer">wikipedia page</a> for a picture.)</p> <p>If you want to determine your N <a href="https://dsp.stackexchange.com/questions/2857/fourier-transform-minimum-sample-requirement">check this answer</a> or google more. Try to start with arbitrary numbers like one tenth of samplerate fs. The larger N, the slower will be your algorithm.</p> <p><a href="http://en.wikipedia.org/wiki/Piano_key_frequencies" rel="nofollow noreferrer">Table of note frequencies</a></p> <p>Simplest way is to make a table of all frequencies you will detect and then just compare your frequency with maximum magnitude to all frequencie values in table. With a small tolerance, for example +-2% of the value in table. Be sure those tolerances do not overlap for two consecutive notes.</p> <p><strong>Microphone input</strong></p> <p>Google up keywords like java microphone input library tutorial, or check <a href="https://stackoverflow.com/questions/3705581/java-sound-api-capturing-microphone">this answer</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload