如何实现用于音频信号的高通滤波器? [英] How to implement a high-pass filter for an audio signal?
问题描述
我试图做这样一个Shazam的音乐识别应用程序。这是一个Android应用程序。首先,我已抓获通过MIC音频信号。下一个我已经实现了汉宁窗口函数和FFT到音频信号,如图如下code:
I am trying to do a music identification application like shazam. This is an android app. First i have captured an audio signal through the MIC. Next I have implemented the hanning window function and FFT to the audio signal as shown as following code :
private class RecordAudio extends AsyncTask<Void, double[], Void> {
@Override
protected Void doInBackground(Void... params) {
started = true;
try {
DataOutputStream dos = new DataOutputStream(
new BufferedOutputStream(new FileOutputStream(
recordingFile)));
int bufferSize = AudioRecord.getMinBufferSize(frequency,
channelConfiguration, audioEncoding);
audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
frequency, channelConfiguration, audioEncoding,
bufferSize);
short[] buffer = new short[blockSize];
double[] toTransform = new double[blockSize];
long t = System.currentTimeMillis();
long end = t + 15000;
audioRecord.startRecording();
while (started) {
//System.currentTimeMillis() < end
int bufferReadResult = audioRecord.read(buffer, 0,
blockSize);
for (int i = 0; i < blockSize && i < bufferReadResult; i++) {
toTransform[i] = (double) buffer[i] / 32768.0;
dos.writeShort(buffer[i]);
}
toTransform = hann(toTransform);
transformer.ft(toTransform);
publishProgress(toTransform);
}
audioRecord.stop();
dos.close();
} catch (Throwable t) {
Log.e("AudioRecord", "Recording Failed");
}
return null;
}
现在我的问题是我怎么需要高通滤波器适用于我的音频信号。对此有任何API?
请有人帮我做这个功能。
Now my question is how do I need to apply high pass filter to my audio signal. Is there any API for this ?? Please some one help me to do this function.
code部分修改
private class RecordAudio extends AsyncTask<Void, double[], Void> {
@Override
protected Void doInBackground(Void... params) {
started = true;
try {
DataOutputStream dos = new DataOutputStream(
new BufferedOutputStream(new FileOutputStream(
recordingFile)));
int bufferSize = AudioRecord.getMinBufferSize(sampleRate,
channelConfiguration, audioEncoding);
audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
sampleRate, channelConfiguration, audioEncoding,
bufferSize);
short[] buffer = new short[blockSize];
double[] toTransform = new double[blockSize];
long t = System.currentTimeMillis();
long end = t + 15000;
audioRecord.startRecording();
while (started) {
//System.currentTimeMillis() < end
int bufferReadResult = audioRecord.read(buffer, 0,
blockSize);
for (int i = 0; i < blockSize && i < bufferReadResult; i++) {
toTransform[i] = (double) buffer[i] / 32768.0;
dos.writeShort(buffer[i]);
}
toTransform = hann(toTransform);
transformer.ft(toTransform);
publishProgress(toTransform);
//new part
//sample rate = 8000
highPassFilter(toTransform, sampleRate);
}
audioRecord.stop();
dos.close();
} catch (Throwable t) {
Log.e("AudioRecord", "Recording Failed");
}
return null;
}
下面是我的高通滤波器的方法:
Here is my high pass filter method:
public void highPassFilter(double []frequency, int samplerate){
double [] f = new double[frequency.length];
for (int n=1; n<frequency.length; n++){
f[n] = (double)frequency[n]/samplerate;
double x = (double)Math.exp(-2 * Math.PI * f[n]);
double []a = new double[] { (1+x)/2, -(1+x)/2 };
double []b = new double[] { x };
}
}
谢谢!
推荐答案
我觉得信号处理可在母语水平(C,C ++)来完成库只有你可以尝试
I think the signal processing could be done in the native level(C,C++) libs only You may try
如果上述方法不帮助,然后尝试这个,以便回答。
If the above doesn't help then try this SO Answer.
这篇关于如何实现用于音频信号的高通滤波器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!