0
$\begingroup$

Can any one suggest me a Bandpass filter in java which I would like to apply on generated sine wave of a particular frequency

$\endgroup$
  • $\begingroup$ Read about windowed Fourier transform. $\endgroup$ – Eddy_Em May 6 '13 at 5:24
  • $\begingroup$ I want that back as a wav file. wav file containing only bandpass filter output $\endgroup$ – user777121 May 6 '13 at 5:56
  • $\begingroup$ Just save result of FFT-filering to a wav-file. What's a problem? $\endgroup$ – Eddy_Em May 6 '13 at 6:06
  • 4
    $\begingroup$ A sine wave filtered by a linear filter is a sine wave of different phase/amplitude - which means you can directly skip the filtering and synthesize the sine wave at a different amplitude/phase, as modified by the filter frequency response. $\endgroup$ – pichenettes May 6 '13 at 7:44
  • $\begingroup$ In the absence of any meaningful specification of the filter, I'd try a Butterworth. $\endgroup$ – Hilmar May 6 '13 at 9:09
3
$\begingroup$

As someone suggested in the comments, filtering a sine wave is just a change in amplitude and possibly phase, although you will have some edge effects at the beginning. I assume this is not simply an excersize in changing amplitudes and that you really need a real filter.

I don't know of an open source library in Java, although this book contains some simple source for a few filters (not sure it has a bandpass, but lowpass + highpass = bandpass).

I don't recommend the suggestion in the comments of using an FFT, although if you can perform a transform on your entire input that is an option, and one that many people find very intuitive. Keep in mind it's an O(n log n) operation, so it may not be feasible for large or even moderately-sized audio files. I explain here more on why EQ is usually not done in the frequency domain. Some people design their filters in the frequency domain and use the IFFT to create a filter, but this results in a design that is inferior in many ways. There are some rules of thumb that make this better, but there are better techniques, so this is not a well developed art.

You haven't specified your filter in any meaningful way, but assuming a basic biquad will suffice, checkout RBJ's audio EQ cookbook. If you need help implementing those filters, I've written a tutorial.

Finally, someone else on StackOverflow just asked about a bandpass filter in Java, and offered some not yet working code. Their design is based on a blackman windowed sinc filter. This is a high-quality FIR filter.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.