fft不适用于44100采样率

时间:2015-04-23 10:21:32

标签: android audio fft sample-rate

我之前在询问有关分析FSK信号的几个问题。我正在生成并记录采样率为44100的fsk信号,它包含两个频率,“1”为934Hz,“0”为510Hz,编码消息是一个字符串,我将其转换为二进制代表,每个位使用2048个样本。在表示数据本身的音调之前,我有一个频率为440Hz的预音。我使用以下代码来捕获音频字节,唯一的区别是我将它们写入ByteArrayOutputStream https://stackoverflow.com/questions/23432398/audio-recorder-in-android-process-the-audio-bytes

之前我使用8000采样率并决定提高传输速率,因此我改变了采样率。当我的录音机和发射器使用8000采样率时,我设法找到信号的起点并分析数据,由于某种原因,当我使用44100的采样率时,我的fft似乎不能正常工作,我找不到正确的频率,我甚至看不到我曾经用8000采样率工作时看到的泛音,我使用这个类中的hann窗口函数并乘以每个窗口:https://github.com/jpatanooga/Canova/blob/master/canova-data/canova-data-audio/src/main/java/org/canova/sound/musicg/dsp/WindowFunction.java

目前,我只是在记录的数据中推进每个2048样本以查看结果。我不太清楚为什么fft不起作用,有什么想法?

我附上了一些我使用的功能:

将音频字节转换为表示标准化正弦波的doule数组的函数(发送的数据采用小端格式):

private double[] convertBytes2SineWave(byte[] byteArray)
    {
        double[] doubleArray = new double[byteArray.length / 2];
        short temp;
        double normalizedVal;
        for (int i=0; i<doubleArray.length; i++)
        {   
            //The data send in little endian format - first byte is low order byte
            byte bLow = byteArray[2*i];
            byte bHigh = byteArray[2*i + 1];
            temp = (short)(((bHigh & 0x00FF) << 8) | (bLow & 0x00FF));
            normalizedVal = temp / 32767.0 ; 
            doubleArray[i] = normalizedVal;
        }
        return doubleArray;
    }

fft功能:

    public double[] calculateFFT(double[] signalChunk, int numFFTPoint)
        {           
            double mMaxFFTSample;
            double temp;
            Complex[] y;
            Complex[] complexSignal = new Complex[numFFTPoint];
            double[] absSignal = new double[numFFTPoint/2];

            for(int i = 0; i < numFFTPoint; i++)
            {
                temp = signalChunk[i];
                complexSignal[i] = new Complex(temp,0.0);
            }

            y = FFT.fft(complexSignal);

            mMaxFFTSample = 0.0;
            mPeakPos = 0;
            for(int i = 0; i < (numFFTPoint/2); i++)
            {
                 absSignal[i] = Math.sqrt(Math.pow(y[i].re(), 2) + Math.pow(y[i].im(), 2));
                 if(absSignal[i] > mMaxFFTSample)
                 {
                     mMaxFFTSample = absSignal[i];
                     mPeakPos = i;
                 } 
            }
             return absSignal;
        }

提取数据位的功能:

private void ExtractDataBits()
    {
        byte[] byteArrayData = ByteArrayAudioData.toByteArray();
        sExtractedBits= new StringBuilder();

        double binSize =((double)sampleRate/numberOfFFTPoints);
        int HighFreqPos =(int) (freqOfHighTone/binSize);
        int LowFreqPos =(int) (freqOfLowTone/binSize);
        double[] daOriginalSine = convertBytes2SineWave(byteArrayData);

        double[] smallArray;
        int NumOfRuns = daOriginalSine.length /numberOfFFTPoints;
        int startIndex = 0;
        while(NumOfRuns > 0)
        {
            if(daOriginalSine.length - startIndex < numberOfFFTPoints)
                break;
            smallArray = new double[numberOfFFTPoints];
            System.arraycopy(daOriginalSine, startIndex, smallArray, 0, numberOfFFTPoints);
            smallArray = applyHannWindow(smallArray, numberOfFFTPoints);
            double[]fftRes = calculateFFT(smallArray,numberOfFFTPoints);
            if(fftRes[HighFreqPos] > fftRes[LowFreqPos])
                sExtractedBits.append("1");
            else
                sExtractedBits.append("0");
            startIndex = startIndex + numberOfFFTPoints;
            NumOfRuns--;
        }

    }

0 个答案:

没有答案