kfrlib / kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
https://www.kfrlib.com
GNU General Public License v2.0
1.62k stars 248 forks source link

I can't make the examples work #189

Closed dpieve closed 10 months ago

dpieve commented 10 months ago

When I try the example:

#include "kfr/all.hpp"
int main() {
    const std::string options = "phaseresp=True";
    kfr::univector<kfr::fbase, 128> output;
    kfr::biquad_params<kfr::fbase> bq[] = { kfr::biquad_notch(0.1, 0.5), kfr::biquad_notch(0.2, 0.5), kfr::biquad_notch(0.3, 0.5),
                                    kfr::biquad_notch(0.4, 0.5) };
    output = biquad(bq, kfr::unitimpulse());
    plot_save("biquad_notch", output, options + ", title='Four Biquad Notch filters'");
    return 0;
}

I get that ModuleNotFoundError 'dspplotting':

biquad_notch...Traceback (most recent call last):
  File "E:\cpp\KfrTests\KfrTests\biquad_notch.py", line 6, in <module>
    import dspplotting as dspplot
ModuleNotFoundError: No module named 'dspplotting'
done

If I copy the dspplotting.py file from the kfr\dsplot\ folder to my project's directory, it's where the biquad_notch.py is, then I receive the following error:

 File "E:\cpp\KfrTests\KfrTests\biquad_notch.py", line 138, in <module>
    dspplot.plot(data, phaseresp=True, title='Four Biquad Notch filters', file='../svg/biquad_notch.svg')
  File "E:\cpp\KfrTests\KfrTests\dspplotting.py", line 231, in plot
    plt.savefig(file)
  File "C:\Users\will\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\pyplot.py", line 1119, in savefig
    res = fig.savefig(*args, **kwargs)  # type: ignore[func-returns-value]

Setup steps:

(1) Clone kfr: https://github.com/kfrlib/kfr.git (2) Install python requirements.txt from kfr directory: pip install -r requirements.txt (3) Create empty C++ project on Visual Studio. (4) Set toolset to LVVM (clang-cl) (5) Set C++ Language Standard to ISO C++20 Standard (/std:c++20) (6) Add path to kfr: Properties > VC++ Directories > Include Directories > E:\cpp\kfr\include;

-Windows 11 Pro, 22H2. -Python 3.11.5 (it's added to the path) -Visual Studio 17.7.4.

-I have added to Visual Studio the Python development and clang/LVVM tools. -matplotlib, numpy and scipy are installed. -I also have LLVM win64 17.0.0 installed.

In the directory kfr/dspplot, I also tried:

pip install .
python setup.py install

What am I missing? Any help would be greatly appreciated.

dancazarin commented 10 months ago

plot_save is a utility function that works out-of-the box in original KFR directory. For it to work from anywhere (for example in KfrTests directory) a simple setup is required.

Please provide the full error details for the case after moving dspplotting.py (in the text you posted there is no actual error details, only traceback).

dpieve commented 10 months ago

@dancazarin oh ok. Here's the full message I get after I copied the dspplotting.py to my project directory.

biquad_notch...Traceback(most recent call last) :
    File "E:\cpp\KfrTests\KfrTests\biquad_notch.py", line 138, in <module>
    dspplot.plot(data, phaseresp = True, title = 'Four Biquad Notch filters', file = '../svg/biquad_notch.svg')
    File "E:\cpp\KfrTests\KfrTests\dspplotting.py", line 231, in plot
    plt.savefig(file)
    File "C:\Users\will\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\pyplot.py", line 1119, in savefig
    res = fig.savefig(*args, **kwargs)  # type: ignore[func - returns - value]
    ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\will\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\figure.py", line 3390, in savefig
    self.canvas.print_figure(fname, **kwargs)
    File "C:\Users\will\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\backend_bases.py", line 2187, in print_figure
    result = print_method(
        ^ ^^^^^^^^^^^^
        File "C:\Users\will\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\backend_bases.py", line 2043, in <lambda>
        print_method = functools.wraps(meth)(lambda * args, **kwargs: meth(
            ^ ^^^^
            File "C:\Users\will\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\backends\backend_svg.py", line 1328, in print_svg
            with cbook.open_file_cm(filename, "w", encoding = "utf-8") as fh :
^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\will\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\cbook.py", line 497, in open_file_cm
fh, opened = to_filehandle(path_or_file, mode, True, encoding)
^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\will\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\cbook.py", line 483, in to_filehandle
fh = open(fname, flag, encoding = encoding)
^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory : '../svg/biquad_notch.svg'
done
dpieve commented 10 months ago

I also tried to have my project inside the kfr directory or kfr/examples. I had kfr/main.cpp and kfr/examples/main.cpp, with and without the dspplotting.py file. It's still not finding the directory '../svg/biquad_notch.svg'. I don't know how to fix this

dancazarin commented 10 months ago

Where is your executable file (.exe) located?

dpieve commented 10 months ago

Initially they were inside a x64/Debug, but I moved every file inside it to the kfr folder to execute the .exe. Same errors.

dancazarin commented 10 months ago
  1. Leave the executable where it is created after building, in x64/Debug
  2. Place dspplotting.py to x64/Debug.
  3. Create a svg directory under x64 directory.
  4. Run your executable by (double-)clicking the .exe file from x64/Debug directory.
dpieve commented 10 months ago

@dancazarin thank you. It works if I follow your instructions. However, is there a way for me to build/run from VS? If I try directly from VS it fails

dancazarin commented 10 months ago

Visual Studio launches your executable file with the working directory set to the project root. To support this case dspplotting.py should be placed in the project root and svg directory should be created in the parent directory of your project root (your project root and svg directory should be located at the same directory).

dpieve commented 10 months ago

So, all this time, I just have to add a svg folder to the project's directory. @dancazarin Thank you so much, it works now.