berndporr / iirj Goto Github PK
View Code? Open in Web Editor NEWAn efficient IIR filter library written in JAVA
License: Apache License 2.0
An efficient IIR filter library written in JAVA
License: Apache License 2.0
We've observed that the results from IIRJ align closely with Scipy for most filters. However, for Bessel Filters of order greater than 1, there are significant differences. Visually, the Bessel results from IIRJ appear inconsistent. Given that other filters produce similar results to Scipy, we suspect this isn't a configuration issue, though we can't be entirely certain. Any insights or guidance on this matter would be highly appreciated.
Great implementation! I've been trying to compare the results with those obtained using Scipy.
With an example of low-pass Butterworth filter, I'm getting the same results as what sosfilt
produces.
I'm trying to get the same behaviour as sosfiltfilt
("A forward-backward digital filter using cascaded second-order sections").
As far as I can tell, sosfiltfilt
:
sosfilt_zi
) and set those initial values in the filter.Using some examples and looking at iirj
's m_biquads
values and Scipy's sos
coefficients seem to be the same values (arranged differently).
Is there a way to compute and set the initial zi
values required for forward-backward processing with iirj
?
Thank you.
Hello, I think you may have forgotten to comment out this debug print statement:
Is the Java version on par with the C++ version, please ?
Hello,is a great library. and now I need to implement " y = filter(b,a,x,zi)" like this in matlab,Do you know how to do it or have any library exists.Thank you very much
https://cn.mathworks.com/help/matlab/ref/filter.html#bt_vs4t-2_1
I am doing a project which needs butterworth filtering, and can't seem to find libraries for DSP in android.
Do you have any directions as to how I can use this in my project?
java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
at uk.me.berndporr.iirj.LayoutBase.add(LayoutBase.java:57)
at uk.me.berndporr.iirj.Butterworth$AnalogLowPass.design(Butterworth.java:58)
at uk.me.berndporr.iirj.Butterworth.setupLowPass(Butterworth.java:66)
at uk.me.berndporr.iirj.Butterworth.lowPass(Butterworth.java:87)
at sg.edu.sutd.syncbeat.utilities.Adaptiv.<init>(Adaptiv.java:17)
at sg.edu.sutd.syncbeat.MainActivity.onCreate(MainActivity.java:56)
at android.app.Activity.performCreate(Activity.java:5411)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Looking at https://github.com/berndporr/iirj/blob/master/src/main/java/uk/me/berndporr/iirj/LayoutBase.java#L45 and https://github.com/berndporr/iirj/blob/master/src/main/java/uk/me/berndporr/iirj/LayoutBase.java#L57, it seems like there will always be an array out of bounds error. Is this a bug?
I have an array of audio signal ranging from nearly -5000 to 5000 and I want to apply a bandpass filter on it. Its a heartbeat audio but I have to filter it .
The array when plotted on a graph looks something like this
When I apply filter on this , the result comes out distorted and the frequencies are not filtered. I am suspecting that the array range should be in range of -1 to 1 instead of -5000 to 5000.
Can anyone tell me what should be the input on the butterworth algo!?
I want to filter an already saved audio in the form of wav file. I know that the filter needs a double array for filtering. So, I have read the audio in a byte array and then converted that byte array to a double array. After applying the filter on the double array with a for loop, I have converted the double array to bytes and then wav file again but the resulting audio file is choppy and doesn't look filtered in a audio spectrum analyzer.
I can provide the code if anyone interested!
Hello,
Are you familiar with Matlab by any change?
If so, would you mind helping me convert a few lines of Matlab code to Java using IIRJ.
This is the code in question:
tempo = 100
fs = 44100
% Butterworth 3rd order bandpass
[b_but, a_but] = butter(3, [20 140+tempo]/(0.5*fs), 'bandpass');
filtered_pulse = filter(b_but, a_but, pulse);
% Peaking filter
[b_peak, a_peak] = iirpeak(110/(fs/2), 120/(0.5*fs));
filtered_pulse = filter(b_peak, a_peak, filtered_pulse);
For the 1st part I already have this:
private int fs = 44100;
private int temp = 100;
public double[] applyBandpass(double[] pulse) {
double filteredPulse = new double[pulse.length];
Butterworth butter = new Butterworth();
butter.bandPass(3, 44100, ?centerFrequency?, ?widthFrequency?);
for(int i = 0; i < pulse.length; i++)
filteredPulse[i] = filter.filter(pulse[i]);
return filteredPulse;
}
I'm not sure how to compute the centerFrequency
and widthFrequency
.
In the Matlab code there is just [20 140+tempo]/(0.5*fs)
, and sample rate is not passed separately.
For the 2nd part I don't have any java code yet because I'm not sure which class of your library to use for the iirpeak()
filter.
Thanks in advance for any help.
Hi! This library is very useful for my android project, thank you for doing this! My project actually does not need real-time filtering, but I can't find any reliable array filtering library. May I know the difference in result between real-time filtering vs array filtering?
I'm new to signal processing and I'm working on a Health App project which uses your Butterworth filter implementation. I don't know how to get an equivalent implementation of this line in scipy
and/or numpy
:
https://github.com/YahyaOdeh/HealthWatcher/blob/635b3118235f2e6927968edb4d9190bf808d6c71/app/src/main/java/com/example/yo7a/healthwatcher/Math/Fft2.java#L11
Could you kindly take a look and give me an advice? Thanks in advance.
Hi and thanks for this wonderful library - I am learning a lot!
I wanted to run this by you to see if you had any thoughts. Perhaps I am doing something wrong - would not be the first time in history =). I am trying to filter seismic time series data so we generally work in the sub-100 Hz realm. Much of the time, 20 samples per sec.
For a low-pass Butterworth filter order 4, sampling rate 20/sec and cutoff frequencies 1 through 10, all is fine.
For the high-pass case however, I run into trouble right at the Nyquist barrier with cutoff = 10.
Stepping thru the call to filter(), with a breakpoint in the Cascade class, ~line 70, I can see that the m_biquads array (index 0) has NaN for the 3 "b" coefficients (m_b0, m_b1, m_b2). This leads to all NaNs for my data after the filter call.
So then I had a go at stepping into the initialization of the filter:
butterworth.highPass(4, rate, freqCutoff); // 4, 20.0, 10.0
and to me things seem OK in highPass() and setupHighPass(). I did manage to step a little further, into the Biquad initialization. But in the setCoefficients() method, I don't detect any NaNs or div by zero or anything really obvious a mortal like me might spot.
So finally my question to you: Are there particular cases where I might need to make additional checks of my web service user's inputs in which I can predict that things are going to get unstable, or catch the exception and return no data?
Thanks for your patience and have a wonderful day!
Mick Van Fossen
Seattle
I have setup a filter with the parameters (4, 30, 140, 200) for heartbeat filtering from camera brightness variation. However the returned value is NaN for each of the numbers I feed into it.
Butterworth butter = new Butterworth(); butter.bandPass(2, 29, 140, 200); for (Double val: brightness){ processed.add(butter.filter(val)); }
On the v1.0.5 release page (https://github.com/berndporr/iirj/releases/tag/1.0.5) you mention this is the first version release to maven central, but over there I can only find version 1.0 (https://search.maven.org/#artifactdetails%7Cuk.me.berndporr%7Ciirj%7C1.0%7Cjar).
Is this the same one?
Perhaps you could re-release it to maven central as 1.0.5 to avoid confusion?
Thanks.
Is the sample rate the same as the frequency which the signal was sampled or is it something else?
The frequencies specified are normalized (Nyquist frequency) or raw?
It looks as if the Bandpass Filter sets upper and lower frequencies symmetrically (arithmetic mean) around the centre frequency, width defined by the widthFrequency - is that correct?
For an Octave Band Filter I need a Geometric Mean centre frequency - the upper frequency cut-off to be further away from the centre frequency than the lower frequency cut-off
Does the IIRS filter library allow for this type of bandpass filter? Thank you, Michael
It would be beneficial to include support for the Cauer / Elliptic filter. A potential reference for the implementation can be found in Vinnie Falco's work at https://github.com/vinniefalco/DSPFilters/blob/master/shared/DSPFilters/source/Elliptic.cpp
I plan to implement this in Q4/2023.
Hi!
I have a .csv file containing target frequencies that need to be filtered out with a band stop filter.
These frequencies change over time. Is it possible to do that? Because I tried it the obvious way by calling the butterworth.bandStop function with the new frequency before feeding the next sample, but that doesn't seem to work.
Thanks
Bastian
Hello!
I've tried to use your library to filter voice using bandPass(2, 16000, 1850, 1550) and it seems not working. Voice has a freqency from 300 up to 3000 and it should exclute music or with bandStop( same args ) exclude voice. But non of it seems working.
It is a bug, or voice filtering way more complicated?
BTW it is open-source android audio recrorder https://gitlab.com/axet/android-audio-recorder
After introducing new tests, it was observed that highpass filters of odd order produce incorrect results. This issue has already been reported in the original library, as seen in this issue.
The proposed fix appears to be effective. Both tbrunsch and I have tested the fix, and it seems to work without introducing any other issues. Additionally, upon reviewing the code, we've verified that the changes exclusively affect the highpass filter and do so correctly.
We will be submitting a PR that includes both the unit tests and the fix for this problem.
I'm trying to transform a java UDF from python code. In python, it use scipy.signal as highpass filter, i'm searching a lot time and found this project. But i can't get the same result, so i wanna know what's difference between Butterworth.highpass() and scipy.signal.butter?
I can't seem to install it from Mven Central.
Hi,
I am trying to understand the library for EEG plotting. I am not a signal processing student by any means and was trying to understand it for my needs.
In EEG these are the recommendations:
https://sapienlabs.org/pitfalls-of-filtering-the-eeg-signal/
In the first paragraph, I need "to apply a high-pass filter to filter out slow frequencies less than 0.1 Hz or often even 1 Hz". My sampling frequency is 250Hz.
Does this mean I use
butterworth.highPass(order: 3, sampling frequency: 250, cutoff: 1);
Would appreciate some clarification.
Hi! Great work and very helpful.I want to use it but i don't know what to give for sampling rate and cut off frequency.i measure the Brightness of Frame and i what to use it to find the heart rate but first i want a low-pass filter.
what i want in Matlab is this
BPM_L = 40; % Heart rate lower limit [beats per minute]
BPM_H = 230; % Heart rate higher limit [beats per minute]
v.Framerte=30;
f1=((BPM_L / 60) / v.FrameRate * 2); // f1=0.01
f2=((BPM_H / 60) / v.FrameRate * 2) ;// f2=0.06
[b, a] = butter(2, [f1 f2]);
//the two-element vector [f1 f2], where f1 < f2, then butter designs a bandpass filter with lower cutoff frequency f1 and higher cutoff frequency f2
filtBrightness = filter(b, a, brightness);
what i have to give for sampling rate (?1) and cut off frequency (?2) in the filter you wrote?
butterworth.lowPass(2,?1,?2);
double butterDouble = butterworth.filter(imgAvg); // this is ok
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.