2015-02-03 5 views
1

오디오 신호를 캡처하고 백그라운드 노이즈를 제거하고 윈도우 기능을 적용하고 그 신호를 시각화하는 프로그램을 작성할 수있었습니다. 내 프로그램은 오류없이이 시점까지 작동합니다. 이제 내 코드에 하이 패스 필터를 구현하려고합니다. 이미이 부분에 대한 API를 찾았습니다. 하지만 제 코드에 따르면 그것을 적용 할 수 없었습니다. 내 코드는 다음과 같습니다.오디오 신호에 하이 패스 필터 구현

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); 

      NoiseSuppressor.create(audioRecord.getAudioSessionId()); 
      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; 
    } 

This은 API 링크입니다.

누구든지이 기능을 수행하도록 도움을 줄 수 있습니까? 나는 정말로 그것을 바르게 평가할 것이다! :)

미리 감사드립니다.

+0

3 일 전에 [동일한 질문] [1]에게 질문했습니다. [1] : http://stackoverflow.com/questions/28252665/how-to-implement-a-high-pass-filter-for-an-audio-signal – Jens

+0

@Jens 예. 그것이 나를 도와주지 않았기 때문에 나는 그것을 다시 게시했다. 어쨌든 어제 밤 나는 하이 패스 필터 기능을 구현할 수있었습니다. 그래서 내가 뭘해야합니까 ?? 이 질문을 닫아야합니까? 왜냐하면 나는 stackoverflow에 새로운 사람이기 때문이다. –

+0

일반적으로 첫 번째 질문에 대한 응답에 설명을 추가하여 응답이 사용자의 질문에 응답하지 않는 이유를 설명합니다. 아마도 가독성을 높이기 위해 원래의 질문을 수정 (편집) 할 수 있습니다. StackOverflow 사용자는 자세를 취한 후 오랜 시간이 질문을 계속 읽는 것을 기억하십시오. – Jens

답변

4

여기는 C#에서 찾은 라이브러리에서 java로 변환하는 클래스입니다. 나는 그것을 사용하고 그것은 잘 작동합니다. 나는이

Filter filter = new Filter(15000,44100, Filter.PassType.Highpass,1); 
    for (int i = 0; i < numSamples; i++) 
    { 
     filter.Update(floatArray[i]); 
     floatArray[i] = filter.getValue(); 
    } 

을 사용하는 방법이 floatArray의 FFT를 가지고 후에는이 여과 볼 수, 당신은 로우 패스 필터도

public class Filter { 


/// <summary> 
/// rez amount, from sqrt(2) to ~ 0.1 
/// </summary> 
private float resonance; 

private float frequency; 
private int sampleRate; 
private PassType passType; 


public float value; 

private float c, a1, a2, a3, b1, b2; 

/// <summary> 
/// Array of input values, latest are in front 
/// </summary> 
private float[] inputHistory = new float[2]; 

/// <summary> 
/// Array of output values, latest are in front 
/// </summary> 
private float[] outputHistory = new float[3]; 

public Filter(float frequency, int sampleRate, PassType passType, float resonance) 
{ 
    this.resonance = resonance; 
    this.frequency = frequency; 
    this.sampleRate = sampleRate; 
    this.passType = passType; 

    switch (passType) 
    { 
     case Lowpass: 
      c = 1.0f/(float)Math.tan(Math.PI * frequency/sampleRate); 
      a1 = 1.0f/(1.0f + resonance * c + c * c); 
      a2 = 2f * a1; 
      a3 = a1; 
      b1 = 2.0f * (1.0f - c * c) * a1; 
      b2 = (1.0f - resonance * c + c * c) * a1; 
      break; 
     case Highpass: 
      c = (float)Math.tan(Math.PI * frequency/sampleRate); 
      a1 = 1.0f/(1.0f + resonance * c + c * c); 
      a2 = -2f * a1; 
      a3 = a1; 
      b1 = 2.0f * (c * c - 1.0f) * a1; 
      b2 = (1.0f - resonance * c + c * c) * a1; 
      break; 
    } 
} 

public enum PassType 
{ 
    Highpass, 
    Lowpass, 
} 

public void Update(float newInput) 
{ 
    float newOutput = a1 * newInput + a2 * this.inputHistory[0] + a3 * this.inputHistory[1] - b1 * this.outputHistory[0] - b2 * this.outputHistory[1]; 

    this.inputHistory[1] = this.inputHistory[0]; 
    this.inputHistory[0] = newInput; 

    this.outputHistory[2] = this.outputHistory[1]; 
    this.outputHistory[1] = this.outputHistory[0]; 
    this.outputHistory[0] = newOutput; 
} 


public float getValue() 
{ 
    return this.outputHistory[0]; 
} 


} 

이 클래스를 사용할 수 있습니다이있다. 희망 하시겠습니까?

+0

그것은 작동하지만 우리는 이것을 ECG에 어떻게 적용할까요? 어떤 아이디어 –

관련 문제