Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8514387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:51:13+00:00 2026-06-11T04:51:13+00:00

I’m fighting for such question as recovering the original frequency from audio data recorded

  • 0

I’m fighting for such question as recovering the original frequency from audio data recorded by mic.

Sorry for my english…

Let me explain this question more clearly. I have generated some specific frequency using the following code I:

void genTone() {
    numSamples = (int)(0.2 * sampleRate);   //duration * sampleRate;
    sample = new double[numSamples];
    generatedSnd = new byte[2 * numSamples];

    // fill out the array
    for (int i = 0; i < numSamples; ++i) {
        sample[i] = Math.sin(2 * Math.PI * i / (sampleRate/freqOfTone));
    }

    // convert to 16 bit pcm sound array
    // assumes the sample buffer is normalised.
    int idx = 0;
    for (final double dVal : sample) {
        // scale to maximum amplitude
        final short val = (short) ((dVal * 32767));
        // in 16 bit wav PCM, first byte is the low order byte
        generatedSnd[idx++] = (byte) (val & 0x00ff);
        generatedSnd[idx++] = (byte) ((val & 0xff00) >>> 8);
    }
}

And I have recored the sound using the following code II:

private void recordInBackground() {
    int read = 0;
    while (isRecording) {
        short data[] = new short[bufferSize];   // bufferSize = 4096

        read = audioRecorder.read(data, 0, bufferSize);
        if (read != AudioRecord.ERROR_INVALID_OPERATION) {
            try {
                float tempHammingRes[] = null;
                hamming(bufferSize);

                Complex[] complexs = new Complex[bufferSize];
                Complex[] results = new Complex[bufferSize];
                for (int i = 0; i < bufferSize; ++i) {
                    data[i] /= 32767; 
                    tempHammingRes[i] = tempHammingRes[i] * data[i];
                    complexs[i]= new Complex(tempHammingRes[i], 0);
                }

                results = FFT.fft(complexs);

                double highScore = 0.0;
                int freq = 1;

                for (int line = 1; line < bufferSize; ++line) {
                    double magnitude = Math.log(results[line].abs() + 1) / Math.log(10.0)*20.0;
                    if (magnitude > highScore) {
                        highScore = magnitude;
                        freq = line;
                    }
                }

                double currentFrequence = ComputeFrequency(freq, bufferSize);

                Log.d(TAG, "highScore = " + highScore + " freq = " + currentFrequence);

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


}

Now, I have a question that in the code block II there will be obtained same frequency in the continuous FFT caculating interval. For example there are some logs outputed from the code blocks II:

highScore = 151.77662972416104 freq = 7999.5849609375 // first 8000

highScore = 146.33073029829455 freq = 7999.5849609375 // second 8000

highScore = 146.44411729898255 freq = 9000.87890625

highScore = 144.43481176938155 freq = 9000.87890625

highScore = 142.78046692784702 freq = 10002.1728515625

highScore = 141.91874938214298 freq = 10002.1728515625

highScore = 136.47269911015098 freq = 11003.466796875

highScore = 136.6873278405228 freq = 11003.466796875

I only generated one 8khz, but I get two sound frequency. I also decrease the duration of output tone or incrase the input buffersize of audio recorder. Unfortunately, it doesn’t help what I want to do..

Is there anybody know whether I’m wrong or the output of fft is like this in nature?

Thanks very much for your any answer!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:51:15+00:00Added an answer on June 11, 2026 at 4:51 am

    I see a few potential problems here. I could be misreading your code, but I’ll mention these things because they LOOK like problems:

    1. Despite windowing, the FFT always has “side-lobes”. You’ve selected the hamming window which is probably ideal for this purpose, but you may be witnessing sidelobes. You shouldn’t be, but if something is happening between genTone and recordInBackground (eg, of you are playing the sound through a speaker and rerecording it), that could generate enough noise and distortion to occasionally make the sidelobe data as prominent as the primary data.

    2. It looks like you are reading all the way through the FFT results. Only the first half of the FFT will contain relevant results, and the second half is a mirror image of the first half. Due to slight numerical errors, you could be finding results in the second half larger than the first half. This problem also suggests you may be calculating your frequencies wrong. I cover this here (and more!):Frequency detection using fft aka pitch

    3. You bit-reverse your data going out, but not coming in. Maybe that’s fine depending on what you are doing, but just from this much code it’s wrong. The FFT can “see through” that, but you’ve effectively created a tremendous amount of noise.

    I also noticed you are trying to compute the log of the absolute value of results of your FFT. This will only serve to make your calculations take longer. For your purposes, magnitude = results[line].abs() is fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't have much knowledge about the IPv6 protocol, so sorry if the question
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.