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
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 thesketch → libraries → JDSP → library → jdsp.jar
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.
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 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:
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?
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.
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.