37

I'd like to compute power spectral density of time series; do some bandpass, lowpass, and highpass filtering; maybe some other basic stuff.

Is there a nice open-source Java library to do this?

I've hunted a bit without success (e.g., Googling "power spectral density java" or "signal processing java" and clicking through links, looking in Apache Commons, Sourceforge, java.net, etc.).

There are lots of applets, books, tutorials, commercial products, etc., that don't meet my needs.

Update: I found org.apache.commons.math.transform for Fourier transforms. This doesn't implement power spectral density, bandpass, etc., but it is something.

user
  • 5,335
  • 7
  • 47
  • 63
dfrankow
  • 20,191
  • 41
  • 152
  • 214
  • 1
    does anyone know of any similar libraries for C/C++? – devin Mar 12 '09 at 03:09
  • 1
    First, this question is about Java, not C. :) Second, FFTW looks like it has FFT. What about bandpass, lowpass, highpass filtering, power spectral density, etc? Clearly FFT forms the basis, but is not a high-level interface for those operations. – dfrankow Mar 13 '09 at 18:31
  • https://github.com/JorenSix/TarsosDSP – kervin May 15 '15 at 02:39
  • 1
    It is six years after the question is asked now. I am looking for a java library which can be used for digital signal processing(in my case music signal processing) for my study. @dfrankow did you find a java library for your task? Or do u know any new java libraries introduced after you asked the question? – vigamage Sep 05 '15 at 08:17
  • I fail to see why this question is 'off topic'. It seems very germane and given the on going commentary it is important to others as well. Should this question be re-opened for new answers? – Hephaestus Mar 05 '20 at 00:32

5 Answers5

25

My first suggestion is to not do your DSP implementation in Java. My second suggestion would be to roll your own simple DSP implementations yourself in Java.


Why not to use Java:

I have lots of experience writing DSP code over the last 10+ years... and almost none of the DSP code is in Java... so forgive me when I am hesitant to read about someone who wants to implement DSP in Java.

If you are going to be doing non-trivial DSP then you shouldn't be using Java. The reason that DSP is so painful to implement in Java is because all the good DSP implementations use low level memory management tricks, pointers (crazy amounts of pointers), large raw data arrays, etc.

Why to use Java:

If you are doing simple DSP stuff roll your own Java implementation. Simple DSP things like PSD and filtering are both relatively easy to implement (easy implementation but they won't be fast) because there is soo many implementation examples and well documented theory online.

In my case I implemented a PSD function in Java once because I was graphing the PSD in a Java GUI so it was easiest to just take the performance hit in Java and have the PSD computed in the java GUI and then plot it.


How to implement a PSD:

The PSD is usually just the magnitude of the FFT displayed in dB. There are many examples from academic, commercial and open-source showing how to compute the magnitude of the FFT in dB. For example Apache has a Java implementation that gives you the FFT output and then you just need to convert to magnitude and dB. Anything after the FFT should be tailored to what you need/want.


How to implement lowpass, bandpass filtering:

The easiest implementation (not the most computationally efficient) would in my opinion be using an FIR filter and doing time domain convolution.

Convolution is very easy to implement it is two nested for loops and there are literally millions of example code on the net.

The FIR filter will be the tricky part if you don't know anything about filter design. The easiest method would be to use Matlab to generate your FIR filter and then copy the coefficents into java. I suggest using firpmord() and firpm() from Matlab. Shoot for -30 to -50 dB attenuation in the stopband and 3 dB ripple in the passband.

Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177
  • 6
    I'm not working on this anymore, but it would not be appropriate to start from Numerical Recipes for a commercial app. Apache Commons Math has an FFT: http://commons.apache.org/math/userguide/transform.html. – dfrankow Jun 10 '09 at 15:13
  • 1
    @dfrankow https://github.com/JorenSix/TarsosDSP should be a better start – kervin May 15 '15 at 02:40
  • 1
    I am wondering on the statement that "do not do it in Java". Java has a great way of handling any memory management task, including amazing speedy memory mapped files. Although the Java itself makes not possible of using raw pointers, it does give you all the high level and safer constructs to manage memory buffers. Trivially, a simple array can be used as a circular buffer. Simply access to an element of the array, instead of using messy pointer arithmetic to figure out where is it actually stored in memory. – Gee Bee Jan 17 '17 at 11:24
10

I have written a collection of some Java DSP classes, e.g. IIR filters:

Java DSP collection

Christian d'Heureuse
  • 5,090
  • 1
  • 32
  • 28
10

I found the book Java Digital Signal Processing and its example source code. You might look through the code to see if it fits your needs.

You can also check out DSP Laboratory.

As duffymo and basszero mentioned in the comments, there have been changes to Java since the publication of Java DSP that may impact some of the code examples. In particular, the (relatively) new Concurrency Utilties package might prove useful.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
  • Wow, this book is vintage 1997. I'm not sure I'd recommend it. The signal processing ideas have not changed, but Java sure has. – duffymo Mar 12 '09 at 12:36
  • What changes have been made that you think will have an effect on digital signal processing? – Bill the Lizard Mar 12 '09 at 13:04
  • @duffymo: The ONLY advance in Java since then is some of the concurrency primitives (since dsp BEGS for multithreading). Generally dsp is math on primitive arrays. I'm w/ Bill. – basszero Mar 12 '09 at 13:14
  • I hadn't thought of that, and I should have. Concurrency is definitely worth mentioning. Thanks, guys. – Bill the Lizard Mar 12 '09 at 13:44
  • Good points both - I stand corrected. Thanks. – duffymo Mar 12 '09 at 14:18
  • 1
    More important for us, a book is unlikely to have open source licensing, so we won't be able to use it for our endeavors. – dfrankow Mar 12 '09 at 15:49
  • Of all the possibilities anyone has listed, thus far "DSP Laboratory" (a dead open source project) looks like it might have the right spirit, but I can't tell from the code. I don't understand its FOB, FTB, FTJ, etc. – dfrankow Mar 13 '09 at 18:34
  • 2
    My apologies, the book has GPL licensing on its source! – dfrankow Mar 13 '09 at 19:12
3

It looks pretty sparse. Try Signalgo or jein or the Intel Signal Processing Library, although I think the last one is just a JNI wrapper.

I saw a lot of those applets you were talking about. I think you may be able to get the JARs for them and use the class APIs inside. May have to use eclipse and jad to decompile and figure out what they do, though, due to lack of documentation. Try the source on this page for example.

John Ellinwood
  • 14,291
  • 7
  • 38
  • 48
  • Thanks for the refs. Honestly, I appreciate them. signalgo is "alpha (i.e. not tested at all!!)" jein has no source code that I can find. Intel won't be open source. – dfrankow Mar 12 '09 at 16:18
2

I found another resource, although it's not a library: http://www.dickbaldwin.com/tocdsp.htm. It's just a basic discussion of signal processing and Fourier transform, with some Java examples. See for example tutorials 1478, 1482, 1486. Not sure what the license on the code is.

dfrankow
  • 20,191
  • 41
  • 152
  • 214