Git Product home page Git Product logo

fcwt's Introduction

The fast Continuous Wavelet Transform (fCWT)

Stable version PyPI version

The fast Continuous Wavelet Transform (fCWT) is a highly optimized C++ library for very fast calculation of the CWT in C++, Matlab, and Python.

fCWT has been featured on the January 2022 cover of NATURE Computational Science. In this article, fCWT is compared against eight competitor algorithms, tested on noise resistance and validated on synthetic electroencephalography and in vivo extracellular local field potential data.

Please cite our research paper using the sidebar button when using fCWT in your research project.

Arts, L.P.A., van den Broek, E.L. The fast continuous wavelet transformation (fCWT) for real-time, high-quality, noise-resistant time–frequency analysis. Nat Comput Sci 2, 47–58 (2022). https://doi.org/10.1038/s43588-021-00183-z

UPDATE (12-01-2023)

New version available:

  • fCWT can be seamlessly used in Python (see Jupyter Notebook)
  • Interface upgrade: Use frequencies instead of scales and octaves!
  • Fixed small memory allignment bugs

Features

  • Calculating CWT 34-120x faster than all competitors*
  • Very high time-frequency resolution (i.e., it does not rely on wavelet estimation)
  • Real-time CWT for signals having sample frequencies of up to 200kHz
  • Applicable in many applications ranging from audio and speech to engine vibration analysis
  • Easy Python integration via pip
  • Easy MATLAB integration via MEX-files
fCWT for real-time audio and speech analysis fCWT for high-resolution in-vivo Neuropixel data analysis
fcwtaudio fcwteeg
fCWT for real-time Electroencephalography (EEG) analysis fCWT for real-time engine diagnostics
fcwteeg2 fcwtengine

*Based on C++ performance. fCWT is the fastest CWT library in C++, Python and Matlab! Please see the benchmark section for more details. Raise an issue if you found a new/faster implementation. I will try to add it to benchmark!

Quickstart

fCWT's implementation can be used to accelerate your C++, Python, and Matlab projects! Build the C++ library to achieve the highest efficiency or use the Matlab and Python packages to maximize integration possibilities.

Python

Install the Python package using pip:

$ pip install fcwt

or if you want to install from source:

$ git clone https://github.com/fastlib/fCWT.git
$ cd fCWT
$ pip install .

See this Jupyter Notebook for documentation.

Matlab

Build MEX-files from source:

$ git clone https://github.com/fastlib/fCWT.git
$ cd fCWT
$ mkdir -p build
$ cd build
$ cmake ../ -DBUILD_MATLAB=ON
$ make 

Two .mex files should now have been created in the MATLAB folder. Run the example.mlx live script to see how to use fCWT in Matlab. fCWT has been tested in R2022b on an Intel Apple Macbook Pro.

C++

Build fCWT from source:

$ git clone https://github.com/fastlib/fCWT.git
$ cd fCWT
$ mkdir -p build
$ cd build
$ cmake ../ [-DBUILD_BENCHMARK=ON|OFF]
$ make 
$ sudo make install

See the Installation section for more details about building fCWT from source for both UNIX and Windows systems.

Benchmark

Columns are formatted as X-Y, where X is signal length in samples and Y the number of frequencies. The benchmark has been performed on a MacBook Pro 2019 having a 2,3 GHz Intel Core i9 4.5 Ghz Boost, 16 GB 2400 MHz DDR4. See the 'Usage: Benchmark' section for more details about the C++ benchmark. See the Benchmark Notebook for the fCWT Python benchmark.

Implementation 10k-300 10k-3000 100k-300 100k-3000 Speedup factor
fCWT (C++) 0.005s 0.04s 0.03s 0.32s -
fCWT (Python) 0.011s 0.089s 0.074s 0.66s -
fCWT (Matlab) 0.072s 0.44s 0.17s 1.55s -
CCWT (Python) 0.019s 0.11s 0.15s 3.40s 10.63x
PyWavelets (Python) 0.10s 1.17s 1.06s 12.69s 34.29x
Matlab 0.75s 0.86s 1.06s 13.26s 35.85x
SsqueezePy (Python) 0.04s 0.43s 1.16s 17.76s 48.00x
SciPy (Python) 0.19s 1.82s 2.11s 18.70s 50.54x
Rwave (C) 0.18s 1.84s 2.28s 23.22s 62.75x
Mathematica - - - 27.83s 75.20x
Wavelib (C++) 0.25s 2.55s 4.85s 45.04s 121.72x

Python Example

import fcwt
import numpy as np
import matplotlib.pyplot as plt

#Initialize
fs = 1000
n = fs*100 #100 seconds
ts = np.arange(n)

#Generate linear chirp
signal = np.sin(2*np.pi*((1+(20*ts)/n)*(ts/fs)))

f0 = 1 #lowest frequency
f1 = 101 #highest frequency
fn = 200 #number of frequencies

#Calculate CWT without plotting...
freqs, out = fcwt.cwt(signal, fs, f0, f1, fn)

#... or calculate and plot CWT
fcwt.plot(signal, fs, f0=f0, f1=f1, fn=fn)

Output:

C++ Example

#include <iostream>
#include <vector>
#include <math.h>
#include <fcwt.h>

int main(int argc, char * argv[]) {
    
    int n = 100000; //signal length
    const int fs = 1000; //sampling frequency
    float twopi = 2.0*3.1415;
    
    //3000 frequencies spread logartihmically between 1 and 32 Hz
    const float f0 = 1;
    const float f1 = 32;
    const int fn = 3000;

    //Define number of threads for multithreaded use
    const int nthreads = 8;

    //input: n real numbers
    std::vector<float> sig(n);
    
    //output: n x scales
    std::vector<complex<float>> tfm(n*fn);
    
    //initialize with 1 Hz cosine wave
    for(auto& el : sig) {
        el = cos(twopi*((float)(&el - &sig[0])/(float)fs));
    }
    
    //Create a wavelet object
    Wavelet *wavelet;
    
    //Initialize a Morlet wavelet having sigma=2.0;
    Morlet morl(2.0f);
    wavelet = &morl;

    //Create the continuous wavelet transform object
    //constructor(wavelet, nthreads, optplan)
    //
    //Arguments
    //wavelet   - pointer to wavelet object
    //nthreads  - number of threads to use
    //optplan   - use FFTW optimization plans if true
    //normalization - take extra time to normalize time-frequency matrix
    FCWT fcwt(wavelet, nthreads, true, false);

    //Generate frequencies
    //constructor(wavelet, dist, fs, f0, f1, fn)
    //
    //Arguments
    //wavelet   - pointer to wavelet object
    //dist      - FCWT_LOGSCALES | FCWT_LINFREQS for logarithmic or linear distribution frequency range
    //fs        - sample frequency
    //f0        - beginning of frequency range
    //f1        - end of frequency range
    //fn        - number of wavelets to generate across frequency range
    Scales scs(wavelet, FCWT_LINFREQS, fs, f0, f1, fn);

    //Perform a CWT
    //cwt(input, length, output, scales)
    //
    //Arguments:
    //input     - floating pointer to input array
    //length    - integer signal length
    //output    - floating pointer to output array
    //scales    - pointer to scales object
    fcwt.cwt(&sig[0], n, &tfm[0], &scs);
        
    return 0;
}

Installation

Dependencies

fCWT has been tested on Mac OSX Mojave 10.14.5, Big Sur 11.6 (both on Intel and Apple Silicon), Windows 10, and Ubutnu 20.04. Please raise an issue if you experience issues running fCWT on these systems! We are working very hard on getting fCWT to run on as many platforms as possible. The benchmark has been performed on a MacBook Pro 2019 having a 2,3 GHz Intel Core i9, 16 GB 2400 MHz DDR4.

Build time settings

Settings that may be specified at build time by using CMake variables are:

  1. the flag to build a shared library instead of static (default is on);
  2. whether or not you want to use your own FFTW installation*;
  3. whether or not you want to build the BENCHMARK target;
  4. whether or not you want to build the MEX files for MATLAB;
  5. installation directories.

Details:

CMake variable Possible values Default on Unix Default on Windows
The flag to build the shared library
BUILD_SHARED_LIBS On | Off On On
The flag to use own FFTW installation (e.g., via brew or apt-get)
USE_OWN_FFTW * On | Off Off Off
The flag to build benchmark target
BUILD_BENCHMARK On | Off Off Off
The flag to build MATLAB MEX files
BUILD_MATLAB On | Off Off Off
Installation directories
FCWT_MATLAB_DIR a path relative to build "../MATLAB" "../MATLAB"
CMAKE_INSTALL_PREFIX an absolute path "/usr/local" "%ProgramFiles (x86)%\fCWT"
FCWT_CMAKE_INSTALL_DIR a path relative to CMAKE_INSTALL_PREFIX "share/fcwt/cmake" "cmake"
FCWT_LIB_INSTALL_DIR a path relative to CMAKE_INSTALL_PREFIX "lib" "lib"
FCWT_INCLUDE_INSTALL_DIR a path relative to CMAKE_INSTALL_PREFIX "include" "include"
  • Please note that you'll need to configure FFTW to use OpenMP for multithreading and 256-bit vector instructions (e.g., AVX) to obtain comparable results to the benchmark. Standard configuration binaries obtained via brew or apt-get generally don't have AVX enabled.

Installation on Unix

$ git clone https://github.com/fastlib/fCWT.git
$ cd fCWT
$ mkdir -p build
$ cd build
$ cmake ../
$ make 
$ sudo make install

Installation on Microsoft Windows

Run the Developer Command Prompt for Visual Studio and type:

> git clone https://github.com/fastlib/fCWT.git
> cd fCWT
> mkdir -p build
> cd build
> cmake -G "Visual Studio 17 2022" ..
> cmake --build .

A Visual Studio .SLN file has now been created in the build-folder. This project includes several build targets. To build a shared/static library of fCWT, build the 'fCWT' target. To run the example code, set the 'fCWT_example' target as the start-up project and run the code as 'release'.

To install fCWT, run the Elevated Command Prompt (i.e. the command prompt with administrator privileges) in the build-folder and type:

> cmake -P cmake_install.cmake

To make the installed DLL available for any application that depends on it, the symbolic link to the fcwt.dll should be created:

  • in %SYSTEMROOT%\System32 for the 64-bit DLL on 64-bit host (or for 32-bit DLL on 32-bit host);
  • in %SYSTEMROOT%\SysWOW64 for the 32-bit DLL on 64-bit host.

Benchmark target build

If you want to replicate the benchmark as presented in the paper, you can build the benchmark target from source using the BUILD_BENCHMARK flag. Additionally, you need Rafat's Wavelib library (https://github.com/rafat/wavelib). Follow its instructions to build a static library file and install the library on your system's header and library paths (/usr/local/include and /usr/local/lib for UNIX systems).

Usage

Benchmark code

There are several commands to use the benchmark build:

$ ./fCWT_benchmark -h Get information about fCWT usage

$ ./fCWT_benchmark -fcwtoptimize [Length=100000] [Number of threads=8] [Optimization=estimate|measure|patient|exhaustive] Calculate all optimization schemes for all powers of two up to the maximal power of two that is calculated based on the [Length] argument, using [Number of threads] threads and using the optimization method specified. If no optimization method is defined it will use the measure method. Estimate is the fastest but lowest quality optimization, exhaustive is the slowest but highest quality optimization. Warning: Exhaustive will take some time!

$ ./fCWT_benchmark -fcwt [Length=100000] [Number of threads=8] Calculate the CWT using fCWT for three signals with length=[Length]. The signals are generated by a dynamic sine wave function, random function and non-smooth function generator, respectively. Depending on optimization usage and system hardware, a run-time in the order of seconds is expected for lengths up to 100.000. Furthermore, one will see that signal content is independent of performance. See the source code for more information.

$ ./fCWT_benchmark -wavelib [Length=100000] [Number of threads=8] Calculate the CWT using Wavelib`s C implementation [1] for a signal with length=[Length]. Depending on system hardware, a run-time in the order of several minutes is expected for lengths up to 100.000.

$ ./fCWT_benchmark -rwave [Length=100000] [Number of threads=8] Calculate the CWT using Rwave's C implementation [2] for a signal with length=[Length]. Depending on system hardware, a run-time in the order of several minutes is expected for lengths up to 100.000.

Benchmark reproduction

If one wants to reproduce the benchmark results as stated in the article, one has to use a signal length of 100000, 8 threads and calculate optimization plans with the exhaustive method: $ ./fCWT_example -fcwtoptimize 100000 8 exhaustive After that:

  1. Run fCWT with: $ ./fCWT_example -fcwt 100000 8,
  2. Run RWave with: $ ./fCWT_example -rwave 100000 8,
  3. Run Wavelib with: $ ./fCWT_example -wavelib 100000 8,
  4. Run additional Python, Matlab and Mathematica scripts found in /src/benchmark

By default, the source code performs 10 runs for demonstration purposes. To match the number of runs in the paper, adjust the runs variable in benchmark.cpp:132. It is recommended to close any background processes.

MATLAB

In the MATLAB-folder, we provided an example live-script titled example.mlx. The example includes basic MATLAB-implementation on how to generate fCWT optimization plans and calculate time-frequency matrices using fCWT. To use fCWT with MATLAB, make sure you generate the MEX-files using the commands listed in the quickstart section.

Note: Expect a decrease in performance when using fCWT via MATLAB. The official benchmark tests MATLAB's CWT implementation via the MATLAB interface and fCWT via the command line. We advice to use fCWT's MATLAB interface solely for plotting purposes.

License

fCWT is distributed under Apache 2.0 license. For conditions of distribution and use, see file LICENSE.TXT

References

[1] Rafat. Wavelib. https://github.com/rafat/wavelib. Accessed: 2020-04-22.
[2] R. Carmona, W.-L. Hwang, and B. Torresani.Practical Time-Frequency Analysis: Gabor and wavelettransforms, with an implementation in S. Academic Press, 1998. [p1, 7, 10]

fcwt's People

Contributors

fastlib avatar felixdollack avatar lschneiderbauer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fcwt's Issues

Reducing artefacts for short time spans

The integer truncation of the index into the mother wavelet causes some artefacts for short time spans. Those can be reduced without performance penalty by generating the mother data at a multiple of size for sizes below some threshold and passing that multiple to the daughter wavelet multiplication to scale the step.

Error installing on Ubuntu 20.04

Hello and thank you for sharing the package.
I just edited the CMakelist line 43 as follows:

set(CMAKE_C_COMPILER "gcc-9")
set(CMAKE_CXX_COMPILER "g++-9")

and I got the following error for making :

[ 12%] Building CXX object CMakeFiles/fCWT_example.dir/src/fcwt.cpp.o
[ 25%] Building CXX object CMakeFiles/fCWT_example.dir/src/main.cpp.o
[ 37%] Building CXX object CMakeFiles/fCWT_example.dir/src/rwave.cpp.o
[ 50%] Building CXX object CMakeFiles/fCWT_example.dir/src/wavelib.cpp.o
[ 62%] Linking CXX executable fCWT_example
/usr/bin/ld: CMakeFiles/fCWT_example.dir/src/fcwt.cpp.o: in function `fcwt::create_optimization_schemes(int, int, int)':
fcwt.cpp:(.text+0x303): undefined reference to `fftwf_init_threads'
/usr/bin/ld: fcwt.cpp:(.text+0x30f): undefined reference to `fftwf_plan_with_nthreads'
/usr/bin/ld: fcwt.cpp:(.text+0x3a2): undefined reference to `fftwf_plan_dft_r2c_1d'
/usr/bin/ld: fcwt.cpp:(.text+0x418): undefined reference to `fftwf_plan_dft_1d'
/usr/bin/ld: fcwt.cpp:(.text+0x420): undefined reference to `fftwf_export_wisdom_to_filename'
/usr/bin/ld: fcwt.cpp:(.text+0x430): undefined reference to `fftwf_free'
/usr/bin/ld: fcwt.cpp:(.text+0x438): undefined reference to `fftwf_free'
/usr/bin/ld: fcwt.cpp:(.text+0x4e3): undefined reference to `fftwf_alloc_complex'
/usr/bin/ld: fcwt.cpp:(.text+0x4ee): undefined reference to `fftwf_alloc_complex'
/usr/bin/ld: CMakeFiles/fCWT_example.dir/src/fcwt.cpp.o: in function `fcwt::load_optimization_schemes(bool, int, int)':
fcwt.cpp:(.text+0x76e): undefined reference to `fftwf_import_wisdom_from_filename'
/usr/bin/ld: CMakeFiles/fCWT_example.dir/src/fcwt.cpp.o: in function `fcwt::main(float*, float*, int*, int*, int*, int*, float*, int, bool)':
fcwt.cpp:(.text.startup+0xcf): undefined reference to `fftwf_alloc_complex'
/usr/bin/ld: fcwt.cpp:(.text.startup+0xdf): undefined reference to `fftwf_alloc_complex'
/usr/bin/ld: fcwt.cpp:(.text.startup+0x139): undefined reference to `fftwf_init_threads'
/usr/bin/ld: fcwt.cpp:(.text.startup+0x145): undefined reference to `fftwf_plan_with_nthreads'
/usr/bin/ld: fcwt.cpp:(.text.startup+0x16a): undefined reference to `fftwf_plan_dft_r2c_1d'
/usr/bin/ld: fcwt.cpp:(.text.startup+0x176): undefined reference to `fftwf_execute'
/usr/bin/ld: fcwt.cpp:(.text.startup+0x17f): undefined reference to `fftwf_destroy_plan'
/usr/bin/ld: fcwt.cpp:(.text.startup+0x198): undefined reference to `fftwf_plan_dft_1d'
/usr/bin/ld: fcwt.cpp:(.text.startup+0x2e1): undefined reference to `fftwf_execute_dft'
/usr/bin/ld: fcwt.cpp:(.text.startup+0x329): undefined reference to `fftwf_destroy_plan'
/usr/bin/ld: fcwt.cpp:(.text.startup+0x331): undefined reference to `fftwf_free'
/usr/bin/ld: fcwt.cpp:(.text.startup+0x339): undefined reference to `fftwf_free'
/usr/bin/ld: fcwt.cpp:(.text.startup+0x33e): undefined reference to `fftwf_cleanup_threads'
/usr/bin/ld: CMakeFiles/fCWT_example.dir/src/wavelib.cpp.o: in function `wavelib::cwt(double*, int, int, int)':
wavelib.cpp:(.text+0x2e): undefined reference to `cwt_init'
/usr/bin/ld: wavelib.cpp:(.text+0x61): undefined reference to `setCWTScales'
/usr/bin/ld: wavelib.cpp:(.text+0x6c): undefined reference to `cwt'
/usr/bin/ld: wavelib.cpp:(.text+0x78): undefined reference to `cwt_free'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/fCWT_example.dir/build.make:132: fCWT_example] Error 1
make[1]: *** [CMakeFiles/Makefile2:106: CMakeFiles/fCWT_example.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Do I need to use gcc 10?

Can not run with numpy 1.22.4

environment: win11 numpy installed with mambaforge, numpy version 1.22.4

RuntimeError Traceback (most recent call last)
RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf . Check the section C-API incompatibility at the Troubleshooting ImportError section at https://numpy.org/devdocs/user/troubleshooting-importerror.html#c-api-incompatibility for indications on how to solve this problem .


ImportError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_29484\3900396640.py in
----> 1 import fcwt

c:\Users\Administrator\mambaforge\lib\site-packages\fcwt_init_.py in
----> 1 from .fcwt import Morlet, Scales, FCWT, FCWT_LINSCALES, FCWT_LOGSCALES, FCWT_LINFREQS
2 from .boilerplate import cwt, plot
3

c:\Users\Administrator\mambaforge\lib\site-packages\fcwt\fcwt.py in
11 # Import the low-level C/C++ module
12 if package or "." in name:
---> 13 from . import _fcwt
14 else:
15 import _fcwt

ImportError: numpy.core.multiarray failed to import

can you please update the API version?

Template for `double`

I'm guessing there may be a reason linked deeply into the algorithm to use single-precision floats, instead of doubles, which are often the default in many applications and libraries today.

Would it be possible to template the algorithm's fundamental storage type in order to be able to use single- or double-precision floating-point numbers (or perhaps, even some more exotic types should there be a reason for these)?

Thanks

fCWT vs STFT in CNN-based EEG emotion recognition

          Understood. Thanks a lot for the clarification. Furthermore, I have a few more confusion that I would also like to ask for your expert opinions, 

Currently, I'm trying to build CNN-based eeg emotion recognition model with CWT, STFT, and fCWT respectively, and compare the performance of each model with different methods. However, I found that the performance of STFT is better than CWT (the parameters of both methods have been tuned to the highest performance on CNN). Therefore, would like to ask, if it is possible that using STFT on a narrow band frequency signal such as the Alpha band of an eeg signal will provide better performance than CWT ?

Originally posted by @whip123 in #40 (comment)

Other mother wavelets

Hi,

Great repository and speed. This is a request, not an issue.

Is there any way to add other wavelet types? For instance, a Gaussian wavelet where we can define a variance is quite common in spectroscopy.

AG.

Morlet wavelets with fixed temporal window length

Hello!
Thank you for the implementation!

I'm working with EEG data and want to replace method from mne library with your implementation to speed up my computations

With mne I perform CWT with following code:

freqs = np.arange(1, 40.01, 0.1)
power_spectrum = mne.time_frequency.tfr_array_morlet(
        samples,  # samples.shape = [number_of_samples, number_of_eeg_channels, temporal_dim]
        sfreq=128,
        freqs=freqs,
        n_cycles=freqs,
        output='power',
        n_jobs=-1
)

I tried to implement the exact same behaviour with fCWT but failed:

morl = fcwt.Morlet(2.0)  # The problem is here I suppose

scales = fcwt.Scales(
        morl,
        fcwt.FCWT_LINFREQS,
        fs=int(raw_data.info['sfreq']),
        f0=freqs[0],
        f1=freqs[-1],
       fn=len(freqs),
)

nthreads = 4
use_optimization_plan = False
use_normalization = False
fcwt_obj = fcwt.FCWT(morl, nthreads, use_optimization_plan, use_normalization)

signal = samples[0, 0]  # for example
output = np.zeros((len(freqs), signal.size), dtype=np.complex64)
fcwt_obj.cwt(
        signal,
        scales,
        output,
)
power = np.abs(output) ** 2

Could you give some recommendations on how to choose the right sigma parameter of fcwt.Morlet to create Morlet wavelets with temporal window with fixed length? Is it possible to get the same behaviour as mne with the current implementation of fCWT?

Scalograms generation

I have recently downloaded this library to use it, I would like to know how would be the implementation in c++ for image generation based on color maps with time, frequency and abs(coefficients).

building for python

fyi i had to add 'libs' to library_dirs and include_dirs in setup.py in order for this to build for python.

#!/usr/bin/env python

"""
setup.py file for SWIG
"""

from setuptools import Extension, setup, find_packages
import distutils.command.build
import sysconfig
import numpy
import os
import shutil


# Obtain the numpy include directory.  This logic works across numpy versions.
try:
   numpy_include = numpy.get_include()
except AttributeError:
   numpy_include = numpy.get_numpy_include()

libraries = ['fftw3f']
comp_args = ["/arch:AVX", "/O2", "/openmp"]
link_args = []
files2 = ["omp.h",
          "fftw3.h",
          "fftw3f.dll",
          "fftw3f.lib",
          "libfftw3fmac.a",
          "libfftw3f_ompmac.a",
          "libfftw3fl.so",
          "libfftw3f_ompl.so",
          "libomp.a"
          ]
files = [
    "fcwt.h",
    "fcwt.cpp"
]

files = files + files2

if "macosx" in sysconfig.get_platform() or "darwin" in sysconfig.get_platform():
   libraries = ['fftw3fmac', 'fftw3f_ompmac']
   comp_args = ["-mavx", "-O3"]
   link_args = ["-lomp"]

if "linux" in sysconfig.get_platform():
   libraries = ['fftw3fl', 'fftw3f_ompl']
   comp_args = ["-mavx", "-O3"]
   link_args = ["-lomp"]


setup(ext_modules=[
    Extension('fcwt._fcwt',
              sources=[
                  'src/fcwt/fcwt.cpp',
                  'src/fcwt/fcwt_wrap.cxx'
              ],
              library_dirs=['src/fcwt', 'src', 'libs'],
              include_dirs=['src/fcwt', 'src', 'libs', numpy_include],
              libraries=libraries,
              extra_compile_args=comp_args,
              extra_link_args=link_args
              )
],
    packages=find_packages(where='src'),
    package_dir={'fcwt': 'src/fcwt'},
    package_data={'fcwt': files}
)

MacBook M1 "zsh: illegal hardware instruction"

When I try to run the python example code it does not execute and I get the warning: zsh: illegal hardware instruction

Specs:

Mac M1
Ventura 13.4
cmake 3.26.4
numpy 1.24.3
linbomp 16.0.5
clang 14.0.3

how to use fCWT to generate pictures for EEG

I tried to run some cwt generating code but it took me 7 days to finish, too slow, I want to use fCWT instead, although installed, I didn't see specific examples for how to use fCWT to generate pictures just as cwt does, I affiliated the cwt MATLAB code, I'm not so sure how to use fCWT, I will be very grateful if you can help me out, thank you
final_cwt.txt
.

Included libfftw3.a and libewavelet.a static libs are macOS only

libfftw3.a and libwavelet.a are Mach-O objects, so practically only compatible with MacOS and not UNIX... Probably worth noting this in the readme and adding links to the source (+hash for reproducibility).

fCWT/src/libwavelib on  main [!] via C v12.2.0-gcc 🔋⚡ 42% ❯ ar x libwavelib.a 

fCWT/src/libwavelib on  main [!?] via C v12.2.0-gcc 🔋⚡ 42% ❯ ls
conv.o  cwt.o  cwtmath.o  hsfft.o  libwavelib.a  real.o  wavefilt.o  wavefunc.o  wavelib.h  wavelib.lib  wavelib.o  wtmath.o

fCWT/src/libwavelib on  main [!?] via C v12.2.0-gcc 🔋⚡ 42% ❯ file *.o
conv.o:     Mach-O 64-bit x86_64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>
cwt.o:      Mach-O 64-bit x86_64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>
cwtmath.o:  Mach-O 64-bit x86_64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>
hsfft.o:    Mach-O 64-bit x86_64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>
real.o:     Mach-O 64-bit x86_64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>
wavefilt.o: Mach-O 64-bit x86_64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>
wavefunc.o: Mach-O 64-bit x86_64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>
wavelib.o:  Mach-O 64-bit x86_64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>
wtmath.o:   Mach-O 64-bit x86_64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>

Installation issues on Apple M1

I tried installation using pip, but resulted in the following error

root ➜ /com.docker.devenvironments.code $ pip install fcwt
Collecting fcwt
  Downloading fCWT-0.1.18.tar.gz (4.6 MB)
     |████████████████████████████████| 4.6 MB 4.6 MB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
    Preparing wheel metadata ... done
Collecting numpy>=1.14.5
  Using cached numpy-1.26.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (14.2 MB)
Building wheels for collected packages: fcwt
  Building wheel for fcwt (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 /tmp/tmpusb54r2k_in_process.py build_wheel /tmp/tmpkufqj71t
       cwd: /tmp/pip-install-4d9xmcij/fcwt_7b0325aac4424ab2bb629c22b7a61965
  Complete output (37 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-aarch64-cpython-39
  creating build/lib.linux-aarch64-cpython-39/fcwt
  copying src/fcwt/fcwt.py -> build/lib.linux-aarch64-cpython-39/fcwt
  copying src/fcwt/boilerplate.py -> build/lib.linux-aarch64-cpython-39/fcwt
  copying src/fcwt/__init__.py -> build/lib.linux-aarch64-cpython-39/fcwt
  running egg_info
  writing fCWT.egg-info/PKG-INFO
  writing dependency_links to fCWT.egg-info/dependency_links.txt
  writing requirements to fCWT.egg-info/requires.txt
  writing top-level names to fCWT.egg-info/top_level.txt
  reading manifest file 'fCWT.egg-info/SOURCES.txt'
  adding license file 'LICENSE.txt'
  writing manifest file 'fCWT.egg-info/SOURCES.txt'
  copying src/fcwt/fcwt.cpp -> build/lib.linux-aarch64-cpython-39/fcwt
  copying src/fcwt/fcwt.h -> build/lib.linux-aarch64-cpython-39/fcwt
  copying src/fcwt/fcwt_wrap.cxx -> build/lib.linux-aarch64-cpython-39/fcwt
  copying src/fcwt/fftw3.h -> build/lib.linux-aarch64-cpython-39/fcwt
  copying src/fcwt/fftw3f.dll -> build/lib.linux-aarch64-cpython-39/fcwt
  copying src/fcwt/fftw3f.lib -> build/lib.linux-aarch64-cpython-39/fcwt
  copying src/fcwt/libfftw3f_ompl.so -> build/lib.linux-aarch64-cpython-39/fcwt
  copying src/fcwt/libfftw3f_ompmac.a -> build/lib.linux-aarch64-cpython-39/fcwt
  copying src/fcwt/libfftw3fl.so -> build/lib.linux-aarch64-cpython-39/fcwt
  copying src/fcwt/libfftw3fmac.a -> build/lib.linux-aarch64-cpython-39/fcwt
  copying src/fcwt/libomp.a -> build/lib.linux-aarch64-cpython-39/fcwt
  copying src/fcwt/omp.h -> build/lib.linux-aarch64-cpython-39/fcwt
  running build_ext
  building 'fcwt._fcwt' extension
  creating build/temp.linux-aarch64-cpython-39
  creating build/temp.linux-aarch64-cpython-39/src
  creating build/temp.linux-aarch64-cpython-39/src/fcwt
  aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/build/python3.9-PN012d/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Isrc/fcwt -Isrc -Ilibs -I/tmp/pip-build-env-supkdnf8/overlay/lib/python3.9/site-packages/numpy/core/include -I/usr/include/python3.9 -c src/fcwt/fcwt.cpp -o build/temp.linux-aarch64-cpython-39/src/fcwt/fcwt.o -std=c++17 -mavx -O3
  aarch64-linux-gnu-gcc: error: unrecognized command-line option ‘-mavx’
  error: command '/usr/bin/aarch64-linux-gnu-gcc' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for fcwt
Failed to build fcwt
ERROR: Could not build wheels for fcwt which use PEP 517 and cannot be installed directly

I added some changes in the cmake file
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -march=native -O2")
instead of "-mavx"

And I tried to install and use the C++ endpoint but I am getting segmentation faults on FCWT::cwt.

int main(){
    std::cout << "The server started." << std::endl;
    
    std::string filepath = "../static/sample.csv";
    int nchannels = 6;

    std::vector<std::vector<float>> data = readCSV(filepath, 6); // this part will be replaced with an active socket connection received
    std::cout << "File read successfully. Size " << data.size() <<","<<data[0].size() << std::endl;

    int sampling_rate = 44100;
    int nframe = 128;
    int nsamples = data[0].size();
    int fstart = 1, fend = 64;


    Morlet morlet(2.0f);
    Wavelet *wavelet = &morlet;
    int nthreads = 8;

    FCWT fcwt(wavelet, nthreads, true, false);

    Scales scales(wavelet,  FCWT_LOGSCALES, sampling_rate, fstart, fend, nframe);


    std::vector<MatrixXcf> spectrum(nframe, MatrixXcf::Zero(nchannels, nsamples));

    std::cout << nchannels << std::endl;
    std::vector<complex<float>> spec(data.size()*data[0].size() + 5, 0);
    std::cout << spec[0] << std::endl;

    for (int i = 0; i < nchannels; i++)
    {
        std::cout << i << std::endl;
        fcwt.cwt(&data[i][0], nsamples, &spec[0], &scales);
        std::cout << "good" << std::endl;
        std::cout << spec[0] << std::endl;
    }
    

}
[100%] Linking CXX executable server
[100%] Built target server
The server started.
File read successfully. Size 6,8000
6
(0,0)
0
WARNING: Optimization scheme 'n8192_t8.wis' was not found, fallback to calculation without optimization.
Segmentation fault

How should I rectify this?

Questions about the library

Hi ! Thanks for taking the time on doing this!

I would like to ask if I can calculate the coeffs and frequency of a signal, like I do with the CWT pywavelets lib : https://pywavelets.readthedocs.io/en/latest/ref/cwt.html

I have been doing experiments with this library but now I need to do CWT on a signal real time, or at least attempt to efficiently calculate this signal and get coeffs / frequency opposed to doing it with Python which has problems saturating a single thread and cumbersome multiproc.

If you could kindly answer to my questions I'd very much appreciated

Thank you !

Sample frequency limitation

The README states:
Real-time CWT for signals having sample frequencies of up to 200kHz

Does this just mean higher sample frequencies won't run in real-time? Is there any indication of how bad it might get for RF frequencies, e.g., 10-50 MHz? I'm assuming (hoping) this is a complex-valued sample rate, i.e., the BW is the sample rate vs half.

CMake function find_package() does not find fCWT-config.cmake configuration files

Thanks to the authors for the opportunity to use this library!

I have a little problem: i installed the fCWT library following the instructions from this official repository, And in the Ubuntu default path /usr/local/share/fcwt/cmake the configuration files fCWT-config.cmake and fCWT-config-release.cmake are present. However, when using the find_package(fCWT REQUIRED)` function in a QT Creator build together with CMakeLists.txt, CMake gives an error:

CMakeLists.txt:14: error: By not providing "FindfCWT.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "fCWT", but CMake did not find one. Could not find a package configuration file provided by "fCWT" with any of the following names:

fCWTConfig.cmake
fcwt-config.cmake

Add the installation prefix of "fCWT" to CMAKE_PREFIX_PATH or set "fCWT_DIR" to a directory containing one of the above files. If "fCWT" provides a separate development package or SDK, be sure it has been installed.

I've tried specifying the path to the configuration files using CMake commands but they don't bring success:

set (CMAKE_MODULE_PATH fCWT-config.cmake REQUIRED)
set (CMAKE_PREFIX_PATH /usr/local/share/fcwt/cmake/fCWT-config.cmake REQUIRED)
set (fCWT-config.cmake_DIR = /usr/local/share/fcwt/cmake/ REQUIRED)
list(APPEND CMAKE_SYSTEM_PREFIX_PATH /usr/local/share/fcwt/cmake)

listing them before find_package(fCWT REQUIRED)

This seems strange to me because it finds the other library (GSL) I use in my small project. My CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 3.22)

project(fft LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(GSL REQUIRED)
find_package(fCWT REQUIRED)

include_directories(${GSL_INCLUDE_DIR})
include_directories(${fCWT_INCLUDE_DIR})
include_directories(/lib/include)
include_directories(/usr/local/include)

add_executable(fft main.cpp)
target_link_libraries(fft PRIVATE ${GSL_LIBRARY})
target_link_libraries(fft PRIVATE ${fCWT_LIBRARY})

Thank you for paying attention to my question. I will be glad to receive any advice on how to fix this error.

fCWT matlab for window

Hi

I'm trying to build MEX-file from source but I'm stuck on a problem
I installed Cmake and GCC, so I made it through until [$ cmake ../ -DBUILD_MATLAB=ON]
But when I type [make] after that, it says this and I cannot find MEX file
make: *** No targets specified and no makefile found. Stop.

Can you spot the problem in this situation?

image
These are the contents in 'build' file

C interface

@fastlib do you have plans on providing (or accepting contributions for) a C interface?
I am trying to embed this project as library but since the header file is written in c++ I am getting a lot of compile errors.

How to get the output time–frequency array?

Hi, your work is excellent. I have some questions about how to get the output time-frequency arrays? Because I want to plot the time-frequency plot obtained by fCWT. Can you give me some specific advice or specific examples? Thanks.

Linking problem while doing make

Greetings,

I am unable to compile the code. After CMake if I do the Make then I am getting following errors [OpenSuse Tumbleweed, g++11]. Please help to get is started. I already modified the CMakeList.txt file to include g++11.

[ 14%] Building CXX object CMakeFiles/fCWT.dir/src/fcwt.cpp.o
[ 28%] Linking CXX shared library libfCWT.so
[ 28%] Built target fCWT
[ 42%] Building CXX object CMakeFiles/fCWT_example.dir/src/fcwt.cpp.o
[ 57%] Building CXX object CMakeFiles/fCWT_example.dir/src/main.cpp.o
[ 71%] Building CXX object CMakeFiles/fCWT_example.dir/src/rwave.cpp.o
[ 85%] Building CXX object CMakeFiles/fCWT_example.dir/src/wavelib.cpp.o
[100%] Linking CXX executable fCWT_example
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: CMakeFiles/fCWT_example.dir/src/fcwt.cpp.o: in function fcwt::create_optimization_schemes(int, int, int)': fcwt.cpp:(.text+0x2b5): undefined reference to fftwf_init_threads'
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text+0x2c1): undefined reference to fftwf_plan_with_nthreads' /usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text+0x341): undefined reference to fftwf_plan_dft_r2c_1d'
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text+0x3b1): undefined reference to fftwf_plan_dft_1d' /usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text+0x3bb): undefined reference to fftwf_export_wisdom_to_filename'
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text+0x3cb): undefined reference to fftwf_free' /usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text+0x3d3): undefined reference to fftwf_free'
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text+0x476): undefined reference to fftwf_alloc_complex' /usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text+0x481): undefined reference to fftwf_alloc_complex'
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: CMakeFiles/fCWT_example.dir/src/fcwt.cpp.o: in function fcwt::load_optimization_schemes(bool, int, int)': fcwt.cpp:(.text+0x6b4): undefined reference to fftwf_import_wisdom_from_filename'
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: CMakeFiles/fCWT_example.dir/src/fcwt.cpp.o: in function fcwt::main(float*, float*, int*, int*, int*, int*, float*, int, bool)': fcwt.cpp:(.text.startup+0xc1): undefined reference to fftwf_alloc_complex'
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text.startup+0xce): undefined reference to fftwf_alloc_complex' /usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text.startup+0x121): undefined reference to fftwf_init_threads'
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text.startup+0x12d): undefined reference to fftwf_plan_with_nthreads' /usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text.startup+0x15b): undefined reference to fftwf_plan_dft_r2c_1d'
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text.startup+0x166): undefined reference to fftwf_execute' /usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text.startup+0x16e): undefined reference to fftwf_destroy_plan'
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text.startup+0x18c): undefined reference to fftwf_plan_dft_1d' /usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text.startup+0x2a8): undefined reference to fftwf_execute_dft'
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text.startup+0x2e4): undefined reference to fftwf_destroy_plan' /usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text.startup+0x2ec): undefined reference to fftwf_free'
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text.startup+0x2f4): undefined reference to fftwf_free' /usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: fcwt.cpp:(.text.startup+0x2f9): undefined reference to fftwf_cleanup_threads'
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: CMakeFiles/fCWT_example.dir/src/wavelib.cpp.o: in function wavelib::cwt(double*, int, int, int)': wavelib.cpp:(.text+0x28): undefined reference to cwt_init'
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: wavelib.cpp:(.text+0x59): undefined reference to setCWTScales' /usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: wavelib.cpp:(.text+0x64): undefined reference to cwt'
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: wavelib.cpp:(.text+0x70): undefined reference to `cwt_free'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/fCWT_example.dir/build.make:148: fCWT_example] Error 1
make[1]: *** [CMakeFiles/Makefile2:112: CMakeFiles/fCWT_example.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

If fCWT suppose 2D wavelet?

I'm going to use fCWT to process picture. But I don't know if fCWT suppose 2D wavelet. Can you give me a suggestion?

Support for Custom Frequency Array Input

Currently, your interfaces in both C and Python only support creating scales using an f0, f1, and either log or linear scaling. However, for some applications, it would be much easier if the user could simply specify an array of frequencies they would like to generate waveforms for. In my case, I would like to analyze specifically the frequencies that correspond to notes on the piano, so a linear or log step isn't practical.

can't compiled the .mexwin64 (WIN) files

Hi:
I change the 'BUILD_MATLAB' = ON in 'CMakeCache.txt',I get fCWT_example.exe.But nothing has changed in the Matlab folder.May I ask what adjustments I need to make to get .mexwin64 (WIN) files.

undefined reference on ubuntu

Unfortunately, when I try to build, I get undefined references (same errors as other people). I have ubuntu 22.10. So far it is not possible to solve these problems, even following the methods that were discussed earlier in closed issues. What other options might be available to solve this problem?

Reconstruction from coefficients i.e. inverse fCWT

Hi,
Thanks for the great tool..

Is there anyway to reconstruct the signal from the coefficients ?

For example

        #Initialize
        fs = 1000
        n = fs*100 #100 seconds
        ts = np.arange(n)

        #Generate linear chirp
        signal = np.sin(2*np.pi*((1+(20*ts)/n)*(ts/fs)))
        f0 = 1 #lowest frequency
        f1 = 101 #highest frequency
        fn = 200 #number of frequencies

        #Calculate CWT without plotting...
        freqs, out = fcwt.cwt(signal, fs, f0, f1, fn)
       
        # now reconstruct signal from coeff ?
       signal = fcwt.icwt(freqs,out)...or something along these lines ? 


Optimization scheme 'n2048_t1.wis' was not found

I installed fCWT via pypi -> pip install fcwt and I get the following warning when 'fast' is enabled (true). I am on Ubuntu 22.04.

WARNING: Optimization scheme 'n2048_t1.wis' was not found, fallback to calculation without optimization.

I am dealing with some data that could benefit a great deal from optimization and speed. How can I fix this issue?

Thanks very much in advance.

fCWT matlab crash on Mac

Dear fastlib

Hi,
I try to do fCWT on matlab, but it crashed at line 55 in the following picture sentence.

Mac PC spec is here,
processor: 2.3 GHz 8core Intel Core i9
memory: 32 GB 2667 MHz DDR4
macOS 13.1(22C65)

Are there any solution ?
I would be happy if you could solve it by adding some code.

Thank you.

problem

Dose it can be used for real-time application in processing low frequency signal?

First, I would like to express my sincere gratitude and respect for the contributions of the authors of this project.

Below is my question.

When I tried to use the output of fcwt input to my model, I found that to obtain a clear spectrum on low frequency, the signal input to fcwt should long enough. For example, if the target frequency is 20 Hz, the duration of the input signal should larger than 1/20Hz=0.05 s. Otherwise, lower frequency spectrum will blur. Dose this means that the conflict between frequency resolution and time resolution still exist?

Or is that mean, for the processing low frequency(f) signal, the input segment duration delta_t should always satisfy that delta_t>1/f. And the high efficient of fcwt only ensure real time processing of with frequency satisfy f>1/delta_t. (Because Heisenberg uncertainty principle?). From what I know, one of the advantage of cwt above stft is it high frequency resolution at low frequency, if limitation of Heisenberg uncertainty still hold, what the advantage of fcwt above stft for real-time using, especially for the processing of low frequency signal.

My question may seems weird, but it is what confuse me now. Any one familiar with are welcome to share your opinion.

How to extract actual periods or frequencies used in Python version? Normalization?

I'd like to be able to plot the actual frequencies or actual periods on my scaleograms. I'm using code based on the advanced Python examples so that I can use the optimization. But fcwt returns scales as a SWIG object and I'm not sure what to do with that. (<fcwt.fcwt.Scales; proxy of <Swig Object of type 'Scales *' at 0x000002154D2B70F0> >) Is there a way get to some approximation of the actual periods or frequencies used?

Also what does the normalization option do? Normalized to what?

Python Import Errors

I installed fCWT using pip, but when I try to run the tutorial Jupyter notebook I get an import error. This is on Python 3.10.4.

image

Example Code giving Segmentation Fault

Greetings,

I was able to successfully install the fCWT but the example given on the home page was compiled using

$ g++ -mavx2 -fopenmp -lfCWT ./example.cpp

compilation successful but,

$ ./a.out
Segmentation fault (core dumped)

Please help.

FR: Benchmarking against IRCAM "wavelet" Library

Personally, I'm almost exclusively looking to do online time-frequency space conversions - as such the situation is a bit different from optimising performing a whole transformation in one go on (assumed) previously-unseen data.

I have just come across this repository by the Institute for Research and Coordination in Acoustics/Music that provides an implementation of the CWT suitable for online use (but that can also be used for offline processing). It seems that each sample is pushed back, and so the transform is updated one sample at a time.

I think this would be good to add to the implementations against which fCWT is benchmarked - especially interesting would be how it compares in online/offline use.

Does this work on m1 processor too?

I am working with m1 iMac.
When I run the python example code, I get the following error:

"Process finished with exit code 132 (interrupted by signal 4: SIGILL)"

Here are the specs and package versions I'm working on:

  • M1 iMac, Ventura 13.1
  • cmake 3.26.3
  • gcc(clang) 14.0.0
  • numpy 1.23
  • python 3.9.13
  • conda 22.9.0

Thank you.

Wavelet coherence

Dear Authors

I don't see this as an issue, but was wondering if there is a way going about doing coherence analysis with your library (python).

Also, thank you for this great software.

Kind regards
Armand

Linking problem: undefined reference to log@GLIBC_2.29

After running CMake followed by make, I get the following error:
../libs/libfftw3fl.so undefined reference to 'log@GLIBC_2.29'
I'm on a RHEL 7 machine using RedHat's devtoolset-11 (gcc 11.2)
FFTW3 exists on the system, but I only have libfftw3.so, libfftw3f.so and libfftw3l.so not 'fl'. I'd build that library myself, but there isn't a configure/make that does that. Or perhaps there's an easier solution?

fCWT application question

Hi - I read your paper in Nature, and I'm hoping you might be able to answer a few quick questions about the real-time aspect of fCWT.

  • When calculating the power of specific frequency bands in your EEG data, for example, how did you mimic a real-time, streaming application? Did you use fCWT to analyze chunks of data (i.e. 0.5s) so that the time-resolution of the power spectrum was actually 0.5s? Or did you build the time-frequency analysis in real time by computing the WT on incoming samples?
  • Have you used fCWT for real-time, on-line applications to get instantaneous psd's?

Thanks!

installing the fCWT on python

Dear @felixdollack

I hope you're doing well. When I try to install the package with pip command I get the following error. Should I download the 17 GB software?!

Best regards,
Mohammad

Screenshot 2023-08-30 110750

I can't install fCWT

I want to install fCWT in Ubuntu 20.04 for C++, but when I "make" the library, I get

[ 60%] Linking CXX executable fCWT_example
/usr/bin/ld: attempted static link of dynamic object `../libs/libfftw3fl.so'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/fCWT_example.dir/build.make:101: fCWT_example] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/fCWT_example.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

The file "../libs/libfftw3fl.so" exists, so I am clueless about this.

Thank you for writing this library!

I am not able to run the code in C++

Screenshot 1
Screenshot 2
What should I do after that command? And In what folder I should save C++ Example and it runs easily?
Screenshot 3

Screenshot 4
Screenshot 5
When I run C++ code, the above error shows in visual studio code.

Benchmark against CCWT

Hi, seems like you kind of reinvented CCWT. Same idea: Transform signal to frequency domain using FFT, do a convolution with a wavelet per frequency band via element wise multiplication, and transform each frequency band back using iFFT.

More implementations are nice, and so would be to have a comparison between the two.

_mm256_mul_ps segfaults w/ linker options -Wl,-O1 -Wl,--as-needed

Hi,

I have no idea why this is happening, but when compiling your code w/ the linker options -Wl,-O1 -Wl,--as-needed the program segfaults when executing line 85 in fcwt.cpp:
O8[q4] = _mm256_mul_ps(I8[q4],tmp[0]);.

When omitting those options the code runs fine.

I am on linux 5.15, using gcc 12.2; fftw version 3.3.10.
Any idea what's going on here?

Frequency to scale conversion

To accommodate wavelets which do not have the basic fs/f conversion from frequency to scale it may be helpful to have a frequencyToScale(fs, f) method in the wavelet and for Scales to be generated with a wavelet parameter to call the wavelet's frequencyToScale method.

Generate fCWT for a short signal to be used as feature

Hello,
At present, I'm using MFCC as a feature in my CNN project. I'm also trying several other features to improve the prediction
factor. The input data is a mono, 16Hz wave file. The data is extracted for 0.1 seconds.

signal, sr = librosa.load("test.wav", sr=None)
fs = 1600
f0 = 1 # lowest frequency
f1 = 101 # highest frequency
fn = 20 # number of frequencies
# Calculate CWT without plotting...
freqs, out = fcwt.cwt(signal[0:1600], fs, f0, f1, fn)
print(freqs)

The above code is generating freqs with 20 points but I'm a bit confused about fs, f0, and f1. The plot looks blurry and I believe that I haven't used correct values. How do I improve the freqs to have good noise for better predictions?

Complex morelet wavelet of the eeg experiment in the article

Hi @fastlib @felixdollack @lschneiderbauer

I am a newbie in signal processing. Based on the article, the cwt and fcwt in the eeg experiments are using complex morlet wavelet with a sigma value of 20 and I understand that the sigma parameters or number of cycles of a morlet wavelet is used to tune the time-frequency resolution tradeoff. Therefore, im currently trying to tune the parameters of sigma for morlet wavelet in CWT. However, i found that the cwt function in matlab 2023b only support the default analytical morelet wavelet "amor" and is unable to tune the sigma value. Hence, would like to ask how did u guys tune the sigma parameters of the morlet wavelet in cwt function of matlab and how do i set the fCWT in matlab to use complex morelet wavelet.

Could you show me the Matlab code of the eeg experiment in the article if possible?

Thanks in advance and sorry if this is a dumb quetion

fCWT in C++

This error comes when we run C++ code of fCWT.
Screenshot 2023-06-23 001013

OMP dependencies

Hello,

I am interested in fCWT. I noticed an hardcoded path "/usr/local/opt/libomp/lib" using this library on apple computer.
My libomp is installed into : /opt/homebrew/Cellar/libomp/16.0.1

Would you consider providing a customizable variable to twik this hardcoded path and make a smoother path detection.. ?

libomp ubuntu build issues

While building fcwt, I encountered OPENMP issues, I installed libomp-dev using apt but is shows fopenmp version 4.5 in every tag present on the ubuntu libomp package list

#9 0.144 Cloning into 'fCWT'...                                                                                               
#9 2.066 Build type is Release                                                                                                
#9 2.101 -- The C compiler identification is GNU 11.4.0                                                                       
#9 2.143 -- The CXX compiler identification is GNU 11.4.0
#9 2.148 -- Detecting C compiler ABI info
#9 2.203 -- Detecting C compiler ABI info - done
#9 2.208 -- Check for working C compiler: /usr/bin/cc - skipped
#9 2.208 -- Detecting C compile features
#9 2.208 -- Detecting C compile features - done
#9 2.210 -- Detecting CXX compiler ABI info
#9 2.272 -- Detecting CXX compiler ABI info - done
#9 2.277 -- Check for working CXX compiler: /usr/bin/c++ - skipped
#9 2.277 -- Detecting CXX compile features
#9 2.278 -- Detecting CXX compile features - done
#9 2.278 Building of shared library is enabled.
#9 2.410 -- Found OpenMP_C: -fopenmp (found version "4.5") 
#9 2.410 CMake Error at /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
#9 2.410   Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
#9 2.410 Call Stack (most recent call first):
#9 2.410   /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
#9 2.410   /usr/share/cmake-3.22/Modules/FindOpenMP.cmake:544 (find_package_handle_standard_args)
#9 2.410   CMakeLists.txt:141 (find_package)
#9 2.410 
#9 2.410 
#9 2.410 -- Configuring incomplete, errors occurred!
#9 2.410 See also "/app/fCWT/build/CMakeFiles/CMakeOutput.log".
#9 2.410 See also "/app/fCWT/build/CMakeFiles/CMakeError.log".
------
executor failed running [/bin/sh -c git clone https://github.com/fastlib/fCWT.git &&     cd fCWT &&     mkdir -p build && cd build &&     cmake .. && make && make install]: exit code: 1

(using ubuntu:latest)
How should I go about fixing this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.