Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

findpeakproblem #38

Closed
Yukuncn opened this issue Jun 7, 2022 · 5 comments
Closed

findpeakproblem #38

Yukuncn opened this issue Jun 7, 2022 · 5 comments
Assignees
Labels
improvements Although outputs are correct, potential improvements in time and memory are required.

Comments

@Yukuncn
Copy link

Yukuncn commented Jun 7, 2022

When I use your library jdsp for peak detection on android phone,It takes long time and can not get the result.
The data can be downloaded at https://drive.google.com/file/d/112almsqRELM5sE82I9QIfHjgazAOjLcT/view?usp=sharing
The code as follows:
readWavObj = new WAV();
readWavObj1 = new WAV();
try {
readWavObj.readWAV(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "audio/" + "singal.wav");
originSignal = readWavObj.getData("double");
readWavObj1.readWAV(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "reference.wav");
originrefSingal = readWavObj1.getData("double");
} catch (WavFileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//covert 1-D array
double[] Singal = utilAcObj.getArray(originSignal);
double[] refSingal = utilAcObj.getArray(originrefSingal);

                        String mode = "valid"; //Can be "valid", "same"
                        CrossCorrelation cc = new CrossCorrelation(Singal, refSingal);
                        double[] zout = cc.crossCorrelate(mode);
                        FindPeak fp = new FindPeak(zout);
                       Peak out = fp.detectPeaks();
                       int[] peaks = out.getPeaks();
@psambit9791
Copy link
Owner

psambit9791 commented Jun 7, 2022

The file you have attached is not accessible. Could you please attach it to a comment?

Few Questions :

  • What is the file size and how many channels does it have?
  • How many data points are there per channel?

@Yukuncn
Copy link
Author

Yukuncn commented Jun 7, 2022

Oh,Sorry,I forgot to open file permissions;This is a new file link: https://drive.google.com/file/d/112almsqRELM5sE82I9QIfHjgazAOjLcT/view?usp=sharing
1.The data size is about 100kb and each file has only one channel;
2.reference.wav has 2205 points and singal.wav has about 80000 points

@psambit9791 psambit9791 self-assigned this Jun 8, 2022
@psambit9791
Copy link
Owner

I simulated this code for both Python (using Scipy & Numpy) and Java (using JDSP).

Two things need to be noted:

  1. Scipy imports all data as int16. This has to be converted to int64 for computations to remain consistent to JDSP. This can be done using the .astype(numpy.int64) function.

  2. On executing both, the execution time came up as this:

For Python:

Execution Time: **231 ms**
Output:
array([10797, 10799, 10807, ..., 87370, 87378, 87394])

For Java:

Execution Time: **777682 ms**
Output: 
[10797, 10799, 10807, 10813, 10821, 10829, ... 87335, 87352, 87361, 87370, 87378, 87394]

The outputs for both Python and Java are the same. So, there are some inefficiencies in the code which need to be addressed. The testing code is attached as a ZIP file with this comment.

issue_38_code.zip

@psambit9791 psambit9791 added the improvements Although outputs are correct, potential improvements in time and memory are required. label Jun 11, 2022
@Yukuncn
Copy link
Author

Yukuncn commented Jun 12, 2022

Thanks a lot,!I know the data type problem.Another problem is that it takes long time to findpeaks on android phone.And i hope you can optimize this problem.I use android studio tool and java for programming language. For time problem,I use a library called TarsosDSP which can be founded at https://github.com/JorenSix/TarsosDSP. It takes about 10-20 seconds to find all the peaks.I think JDSP is a good library and fixing this will make it better.The last i hope you can check the time of Peak Detection and peak filters.Have a nice day!

@psambit9791 psambit9791 added this to Issues ❌ in Features List Jun 27, 2022
@psambit9791
Copy link
Owner

psambit9791 commented Jul 26, 2022

@Yukuncn

With Commit c882796, the execution speed has been reduced to match Python execution speed.

Execution Time: **294 ms**
Output: 
[10797, 10799, 10807, 10813, 10821, 10829, ... 87335, 87352, 87361, 87370, 87378, 87394]

To achieve this, Peak properties are now computed only when the specific property is called / filtered with; and not as a part of the detectPeak() function.

Currently in dev branch.

@psambit9791 psambit9791 moved this from Issues ❌ to New Features 💡 in Features List Aug 1, 2022
@psambit9791 psambit9791 moved this from New Features 💡 to Issues ❌ in Features List Aug 1, 2022
@psambit9791 psambit9791 moved this from Issues ❌ to Done ✔️ in Features List Aug 1, 2022
@psambit9791 psambit9791 moved this from Done ✔️ to Fixed in Features List Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvements Although outputs are correct, potential improvements in time and memory are required.
Projects
Features List
  
Fixed
Development

No branches or pull requests

2 participants