如何从实时音频开发频谱分析仪? [英] How to develop a Spectrum Analyser from a realtime audio?

查看:152
本文介绍了如何从实时音频开发频谱分析仪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,该应用程序可以实时获取来自麦克风的音频,并且没有文件存储空间.基本上,我使用:

I am developing an app that get a source audio from mic in realtime, with no file storage. Basically, I use:

mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile("/dev/null");

我的问题是,如何在没有文件的情况下从该实时音频中绘制频谱图.可以吗?

My question is, how I can do a spectrum graphic from this realtime audio, with no files. It can be done?

我阅读的所有帖子都在分析一个缓冲文件.

All post that I read are analyzing a buffered file.

谢谢,对不起我的英语.

Thank you, and sorry for my english.

推荐答案

是的.

您所需要的只是一种快速FFT算法!

All you need is a fast FFT algorithm !

首先确定所需的频率分辨率,例如,您可以将麦克风的采样率设置为8000hz,现在选择一个块大小(如1024或2048)从麦克风中捕获.

First decide the frequency resolution that you want, for example you can set the sample rate from your mic at 8000hz, now choose one chunk size like 1024 or 2048 to capture from your mic.

如果您选择2048点,采样率为8000,您的频率分辨率是否为3.9063(8000/2048).

If you choose 2048 points and sample rate 8000, do you will have a frequency resolution = 3.9063 (8000 /2048).

在您的2048个点上应用一个窗口函数,然后应用FFT并获得幅度!

Apply one window function over your 2048 points, then apply FFT and get magnitude !

记住Nyquist定理采样率= 8000/2 = 4000,现在您知道FFT在4000 Hz时可以得到3.9063 Hz之间的频率.

Remember of Nyquist theorem sample rate = 8000 / 2 = 4000, now do you know your FFT can get frequencies between 3.9063 Hz at 4000 Hz.

相应频率的FFT Bin:

FFT Bin of corresponding frequencies:

1 -> 3,90625  hz    
2 -> 7,8125  hz    
3 -> 11,71875 hz    
...    
1024 -> 4000 hz    
...    
2048 - > 8000 hz

为此,您只需要FFT的前一半值,在这种情况下为1024.

For it you need just the first half values of FFT, for this case 1024.

现在,如果您从FFT中绘制此数据,您将获得频谱!

Now if you plot this data from your FFT, you will have a spectrum !

编辑

伪代码:

#construct one hanning window Function
Chunk = 2048;
windowed = [Chunk];
hanning = [Chunk];
for i 1:Chunk:
      hanning[i] = ((1 - cos(i*2*pi/Chunk-1))/2)

#start capture from Mic
while true:

    #into values capture 2048 points from your mic
    values=dataFromMic(Chunk);
    #Apply Window hanning = multiply window function(hanning) over your 2048 points
    for i 1:Chunk:
            windowed[i] = values[i] * hanning[i]
    #Apply FFT 
    fftData=fft(windowed);
    #Get Magnitude (linear scale) of first half values
    Mag=abs(fftData(1:Chunk/2))
    # update/show results
    plot(Mag)

end

这篇关于如何从实时音频开发频谱分析仪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆