Manually import Java library, JDSP, and cannot use JDSP built-in functions

The purpose of this code is to test whether the jdsp function can be called.
I manually added the third-party library jdsp according to the method provided by the official.
How to Install a Contributed Library · processing/processing Wiki
Here’s my test code, but it prompts after running

ClassNotFoundException: uk.me.berndporr.iirj.Butterworth

import com.github.psambit9791.jdsp.misc.*;
import com.github.psambit9791.jdsp.io.*;
import com.github.psambit9791.jdsp.speech.*;
import com.github.psambit9791.jdsp.splines.*;
import com.github.psambit9791.jdsp.filter.*;
import com.github.psambit9791.jdsp.filter.adaptive.*;
import com.github.psambit9791.jdsp.windows.*;
import com.github.psambit9791.jdsp.transform.*;
import com.github.psambit9791.jdsp.signal.*;
import com.github.psambit9791.jdsp.signal.peaks.*;

double[] signal;
double[] result;
double[] result2;
void setup() {
  size(800, 400);
  
  int signalLength = 1000;
  signal = new double[signalLength];
  for (int i = 0; i < signalLength; i++) {
    double t = (double)i / 100; 
    signal[i] = Math.sin(2 * Math.PI * 1 * t) + 0.5 * Math.sin(2 * Math.PI * 20 * t);
  }
  
  // 应用低通滤波器
  int Fs = 100; 
  int order = 4; 
  int cutOff = 9; 
  
  Butterworth flt = new Butterworth(Fs);
  result = flt.lowPassFilter(signal, order, cutOff); //get the result after filtering
  result2 = flt.highPassFilter(signal, order, cutOff); //get the result after filtering
}

When I added import uk.me.berndporr.iirj.*;The error message becomes The type Butterworth is ambiguous
I followed the official prompt to place the third-party library under thesketchlibrariesJDSPlibraryjdsp.jar

Hello @jodoro,

Please provide a link to the JDSP library you are using.

I did not find this in the Contribution manager for Processing 4.4.4

:)

ok.
This is the official address of the JDSP library, JDSP - Digital Signal Processing in Java
a Java library for digital signal processing.
Just a plain java library, not specifically designed for processing.
This is explained in the old version of the official GitHub repository
How to Install a Contributed Library · processing/processing Wiki

Non-Processing Libraries

Another example: you want to use the Apache Common Collections library, which is a plain Java library (ie. not designed for use with Processing). The zip file contains a folder named commons-collections-3.2.1 with various files in it, including one: commons-collections-3.2.1.jar

You have to create the libraries/ApacheCommonCollections/library folder (the middle name can vary, but must have only letters and numbers) where you put the jar file renamed along the folder name (here, ApacheCommonCollections.jar, then).

Alternatively, if you need this library for only one sketch, you can just drag’n’drop the jar file on the PDE, it will put it in a folder named code in the sketch folder (you can also create the folder manually and put the jar file there yourself). This also works, of course, for regular Processing libraries. This solution isn’t optimal if you plan to use the library in several sketches, as it will duplicate the library, taking up space and making difficult a possible upgrade.

I downloaded v3.1.0 from the link you provided and could not find any JAR files.

It appears to be the source code only.

GitHub link:

I rarely build from source and only if there are clear instructions.
One of the more experienced users may be able to assist.

:)

Oh, sorry, I sent the wrong message earlier. The .jar file of the JDSP library is placed in the Maven Central Repository, and here is the correct address.
Anyway, I really appreciate your response and help.
If you want to try importing the JDSP library, the .jar file’s name should not contain numbers or symbols, such as “jdsp.jar”.

jdsp.jar

JDSP website states:

JDSP is written purely in Java. It has dependencies on 3 core libraries: Apache Commons Math, IIRJ and SSJ , all of which are also open source projects.

You need (at least for you sketch) these additional JAR files in your code folder in your sketch:

I only needed the last import for your example:

//import com.github.psambit9791.jdsp.misc.*;
//import com.github.psambit9791.jdsp.io.*;
//import com.github.psambit9791.jdsp.speech.*;
//import com.github.psambit9791.jdsp.splines.*;
//import com.github.psambit9791.jdsp.filter.*;
//import com.github.psambit9791.jdsp.filter.adaptive.*;
//import com.github.psambit9791.jdsp.windows.*;
//import com.github.psambit9791.jdsp.transform.*;
//import com.github.psambit9791.jdsp.signal.*;
//import com.github.psambit9791.jdsp.signal.peaks.*;

import com.github.psambit9791.jdsp.filter.Butterworth; // Specific import for Butterworth

And voila!

You will have to add code to plot results:

This was with some modifications to your code:

I will leave it with you to find those jar files in here (I used these) or links on JDSP site:

This was a fun and worthwhile!

I learned a lot!

:)

(post deleted by author)

Yes, my problem has been solved.
Thank you, I am very touched by your warm help.
In addition, your optimism and positive learning have forced me to reflect on my own perceptions, and you are my teacher to me.
However, I still have a question. Why does using import all of jdsp prompt?

The type Butterworth is ambiguous

Like this.

import com.github.psambit9791.jdsp.misc.*;
import com.github.psambit9791.jdsp.io.*;
import com.github.psambit9791.jdsp.speech.*;
import com.github.psambit9791.jdsp.splines.*;
import com.github.psambit9791.jdsp.filter.*;
import com.github.psambit9791.jdsp.filter.adaptive.*;
import com.github.psambit9791.jdsp.windows.*;
import com.github.psambit9791.jdsp.transform.*;
import com.github.psambit9791.jdsp.signal.*;
import com.github.psambit9791.jdsp.signal.peaks.*;
//import com.github.psambit9791.jdsp.filter.Butterworth; // Specific import for Butterworth
1 Like

You are welcome! I enjoyed this topic and helping out. Keeps the brain active!

There is a Butterworth.class in both the jdsp and the iirj libraries.
You can look inside the JAR files with WinRAR.

The error “The type Butterworth is ambiguous” happens when two or more classes with the same name (Butterworth) are available and Java can’t tell which one to use.

Some of this is familiarity and experience in searching for answers and quickly iterating down to a solution.
Not a pro at this but can navigate my way through these challenges.
It is not always easy but gets easier and I enjoy the challenge.

All those imports may not be need for your example.
I like to experiment and commented these out and included the one that was needed.
Some of the gurus here may offer better insight.

:)

1 Like

Well, I see what you mean.
I found out that there was Butterworth in the IIRJ library,
it was my inexperience.
Thank you for helping me with this.
Some of your words and actions have left a deep impact on me.

1 Like

Hello again!

I came across this in the middle of the night:

https://stackoverflow.com/questions/35883253/how-to-use-jtransforms-library-with-processing-3

Quote from above:

Sometimes it helps to sleep on it! What seemed impossible last night was a breeze this morning.

That statement resonates with me and I often come back to a project the next day with solutions!

I remembered this in the middle of the night as well and this is why it all seemed so familiar to me:

Additional references for future:

This has all sparked my interest and I will certainly be exploring the topics in more depth in the future.

Thanks for all the kind words!

Have fun!

:)

The best cpu ever created is sitting on top of our shoulders.