├── .gitignore ├── COPYING ├── Changelog ├── README.md ├── comp ├── comp_gsrtisilaupdate.m ├── comp_gsrtisilawins.m ├── comp_leglaupdatereal.m ├── comp_overlayframes.m ├── comp_pghiphasegrad.m ├── comp_rtisilaupdate.m ├── comp_rtisilawins.m ├── comp_spsireal.m └── compinit.m ├── demos ├── Contents.m ├── demo_blockproc_phaseret.m ├── demo_blockproc_phaseret2.m ├── demo_blockproc_phaseretmix.m ├── demo_pghioverlaps.m ├── demo_phasevocoder.m └── demosinit.m ├── gabor ├── Contents.m ├── decolbfgs.m ├── gaborinit.m ├── gla.m ├── gsrtisila.m ├── legla.m ├── lertisila.m ├── magnitudeerr.m ├── magnitudeerrdb.m ├── pghi.m ├── pghi_findgamma.m ├── plotdgtrealphasediff.m ├── rtisila.m ├── rtpghi.m └── spsi.m ├── libltfat ├── .gitattributes ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── Makefile ├── README.md ├── comptarget.mk ├── copyrightplate ├── examples │ ├── CMakeLists.txt │ ├── Makefile │ ├── example_dgtprocessor.cpp │ ├── example_gabanasyn.c │ ├── multigabormp │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ └── multigabormpd.cpp │ └── utils │ │ ├── cxxopts.hpp │ │ ├── dr_wav.h │ │ ├── ltfathelper.h │ │ └── wavhandler.h ├── modules │ ├── libltfat │ │ ├── doc │ │ │ ├── DoxygenLayout.xml │ │ │ ├── dgt.md │ │ │ ├── doxyconfig │ │ │ ├── doxymain.md │ │ │ ├── htmltemplate │ │ │ │ ├── customdoxygen.css │ │ │ │ ├── footer.html │ │ │ │ └── header.html │ │ │ ├── mathjaxinclude │ │ │ │ └── macros.js │ │ │ ├── project.bib │ │ │ └── texinclude │ │ │ │ └── macros.tex │ │ ├── include │ │ │ ├── ltfat.h │ │ │ └── ltfat │ │ │ │ ├── basicmacros.h │ │ │ │ ├── blaslapack.h │ │ │ │ ├── ci_memalloc.h │ │ │ │ ├── ci_windows.h │ │ │ │ ├── circularbuf.h │ │ │ │ ├── ciutils.h │ │ │ │ ├── dct.h │ │ │ │ ├── dgt_common.h │ │ │ │ ├── dgt_fb.h │ │ │ │ ├── dgt_long.h │ │ │ │ ├── dgt_multi.h │ │ │ │ ├── dgt_shear.h │ │ │ │ ├── dgtreal_fb.h │ │ │ │ ├── dgtreal_long.h │ │ │ │ ├── dgtrealmp.h │ │ │ │ ├── dgtrealwrapper.h │ │ │ │ ├── dgtwrapper.h │ │ │ │ ├── dgtwrapper_typeconstant.h │ │ │ │ ├── dst.h │ │ │ │ ├── errno.h │ │ │ │ ├── fftw_wrappers.h │ │ │ │ ├── gabdual_painless.h │ │ │ │ ├── goertzel.h │ │ │ │ ├── heap.h │ │ │ │ ├── heapint.h │ │ │ │ ├── idgt_fb.h │ │ │ │ ├── idgt_long.h │ │ │ │ ├── idgtreal_fb.h │ │ │ │ ├── idgtreal_long.h │ │ │ │ ├── linalg.h │ │ │ │ ├── macros.h │ │ │ │ ├── maxtree.h │ │ │ │ ├── memalloc.h │ │ │ │ ├── reassign_typeconstant.h │ │ │ │ ├── rtdgtreal.h │ │ │ │ ├── slicingbuf.h │ │ │ │ ├── slidgtrealmp.h │ │ │ │ ├── thirdparty │ │ │ │ ├── cblas.h │ │ │ │ ├── f77-fcn.h │ │ │ │ ├── fftw3.h │ │ │ │ └── kiss_fft.h │ │ │ │ ├── ti_windows.h │ │ │ │ ├── tiutils.h │ │ │ │ ├── typecomplexindependent.h │ │ │ │ ├── typeconstant.h │ │ │ │ ├── typeindependent.h │ │ │ │ ├── types.h │ │ │ │ ├── version.h │ │ │ │ └── wavelets.h │ │ ├── src │ │ │ ├── CMakeLists.txt │ │ │ ├── argchecks.c │ │ │ ├── ci_memalloc.c │ │ │ ├── ci_utils.c │ │ │ ├── ci_windows.c │ │ │ ├── circularbuf.c │ │ │ ├── circularbuf_private.h │ │ │ ├── dct.c │ │ │ ├── dgt.c │ │ │ ├── dgt_fb.c │ │ │ ├── dgt_long.c │ │ │ ├── dgt_long_private.h │ │ │ ├── dgt_multi.c │ │ │ ├── dgt_ola.c │ │ │ ├── dgt_shear.c │ │ │ ├── dgt_shearola.c │ │ │ ├── dgtreal_fb.c │ │ │ ├── dgtreal_long.c │ │ │ ├── dgtreal_long_private.h │ │ │ ├── dgtrealmp.c │ │ │ ├── dgtrealmp_guts.c │ │ │ ├── dgtrealmp_kernel.c │ │ │ ├── dgtrealmp_parbuf.c │ │ │ ├── dgtrealmp_private.h │ │ │ ├── dgtrealmp_typeconstant.c │ │ │ ├── dgtrealwrapper.c │ │ │ ├── dgtrealwrapper_private.h │ │ │ ├── dgtwrapper.c │ │ │ ├── dgtwrapper_private.h │ │ │ ├── dgtwrapper_typeconstant.c │ │ │ ├── dst.c │ │ │ ├── dwilt.c │ │ │ ├── error.c │ │ │ ├── fftw_wrappers.c │ │ │ ├── filedefs.mk │ │ │ ├── filterbank.c │ │ │ ├── firwin_typeconstant.c │ │ │ ├── gabdual.c │ │ │ ├── gabdual_fac.c │ │ │ ├── gabdual_painless.c │ │ │ ├── gabtight.c │ │ │ ├── gabtight_fac.c │ │ │ ├── goertzel.c │ │ │ ├── heap.c │ │ │ ├── heapint.c │ │ │ ├── idgt_fb.c │ │ │ ├── idgt_long.c │ │ │ ├── idgtreal_fb.c │ │ │ ├── idgtreal_long.c │ │ │ ├── idwilt.c │ │ │ ├── ifilterbank.c │ │ │ ├── integer_manip.c │ │ │ ├── ippfft_wrappers.c │ │ │ ├── iwfac.c │ │ │ ├── iwfacreal.c │ │ │ ├── iwmdct.c │ │ │ ├── kissfft_wrappers.c │ │ │ ├── ltfat_blaslapack.c │ │ │ ├── maxtree.c │ │ │ ├── memalloc.c │ │ │ ├── pfilt.c │ │ │ ├── reassign.c │ │ │ ├── reassign_ti.c │ │ │ ├── reassign_typeconstant.c │ │ │ ├── rtdgtreal.c │ │ │ ├── slicingbuf.c │ │ │ ├── slicingbuf_private.h │ │ │ ├── slidgtrealmp.c │ │ │ ├── slidgtrealmp_private.h │ │ │ ├── spread.c │ │ │ ├── utils.c │ │ │ ├── version.c │ │ │ ├── wavelets.c │ │ │ ├── wavelets_typeconstant.c │ │ │ ├── wfac.c │ │ │ ├── wfacreal.c │ │ │ ├── windows.c │ │ │ └── wmdct.c │ │ ├── testing │ │ │ ├── cUnit │ │ │ │ ├── Makefile │ │ │ │ ├── README │ │ │ │ ├── minunit.h │ │ │ │ ├── multiinclude.h │ │ │ │ ├── runner_multiinclude.h │ │ │ │ ├── runner_template.c │ │ │ │ ├── test_all_libltfat.c │ │ │ │ ├── test_circshift.c │ │ │ │ ├── test_dgt_fb.c │ │ │ │ ├── test_dgt_long.c │ │ │ │ ├── test_dgtreal_fb.c │ │ │ │ ├── test_dgtreal_long.c │ │ │ │ ├── test_fftcircshift.c │ │ │ │ ├── test_fftfftshift.c │ │ │ │ ├── test_fftifftshift.c │ │ │ │ ├── test_fftrealcircshift.c │ │ │ │ ├── test_fftrealfftshift.c │ │ │ │ ├── test_fftrealifftshift.c │ │ │ │ ├── test_fftshift.c │ │ │ │ ├── test_fir2long.c │ │ │ │ ├── test_firwin.c │ │ │ │ ├── test_gabdual_long.c │ │ │ │ ├── test_gabdual_painless.c │ │ │ │ ├── test_idgt_fb.c │ │ │ │ ├── test_idgt_long.c │ │ │ │ ├── test_idgtreal_fb.c │ │ │ │ ├── test_idgtreal_long.c │ │ │ │ ├── test_ifftshift.c │ │ │ │ ├── test_long2fir.c │ │ │ │ ├── test_maxtree.c │ │ │ │ ├── test_normalize.c │ │ │ │ ├── test_pgauss.c │ │ │ │ ├── test_typecomplexindependent.c │ │ │ │ └── test_typeindependent.c │ │ │ ├── mUnit │ │ │ │ ├── complex2interleaved.m │ │ │ │ ├── interleaved2complex.m │ │ │ │ ├── loadlibltfat.m │ │ │ │ ├── ltfatdiditfail.m │ │ │ │ ├── ltfatstatusstring.m │ │ │ │ ├── makelibraryname.m │ │ │ │ ├── oldtest_libltfat_maxtree.m │ │ │ │ ├── test_all_libltfat.m │ │ │ │ ├── test_fifo.m │ │ │ │ ├── test_gabframediag.m │ │ │ │ ├── test_libltfat_circshift.m │ │ │ │ ├── test_libltfat_circshift2.m │ │ │ │ ├── test_libltfat_dgt_fb.m │ │ │ │ ├── test_libltfat_dgt_long.m │ │ │ │ ├── test_libltfat_dgtreal2dgt.m │ │ │ │ ├── test_libltfat_dgtreal_fb.m │ │ │ │ ├── test_libltfat_dgtreal_long.m │ │ │ │ ├── test_libltfat_dgtrealmp.m │ │ │ │ ├── test_libltfat_dgtrealwrapper.m │ │ │ │ ├── test_libltfat_dgtwrapper.m │ │ │ │ ├── test_libltfat_fft.m │ │ │ │ ├── test_libltfat_fftcircshift.m │ │ │ │ ├── test_libltfat_fftfftshift.m │ │ │ │ ├── test_libltfat_fftifftshift.m │ │ │ │ ├── test_libltfat_fftreal.m │ │ │ │ ├── test_libltfat_fftshift.m │ │ │ │ ├── test_libltfat_fir2long.m │ │ │ │ ├── test_libltfat_firwin.m │ │ │ │ ├── test_libltfat_fold.m │ │ │ │ ├── test_libltfat_gabdual.m │ │ │ │ ├── test_libltfat_gabtight.m │ │ │ │ ├── test_libltfat_heap.m │ │ │ │ ├── test_libltfat_idgt_fb.m │ │ │ │ ├── test_libltfat_idgt_long.m │ │ │ │ ├── test_libltfat_idgtreal_fb.m │ │ │ │ ├── test_libltfat_idgtreal_long.m │ │ │ │ ├── test_libltfat_ifft.m │ │ │ │ ├── test_libltfat_ifftreal.m │ │ │ │ ├── test_libltfat_ifftshift.m │ │ │ │ ├── test_libltfat_long2fir.m │ │ │ │ ├── test_libltfat_middlepad.m │ │ │ │ ├── test_libltfat_normalize.m │ │ │ │ ├── test_libltfat_pgauss.m │ │ │ │ ├── test_libltfat_phaselock.m │ │ │ │ ├── test_libltfat_phaseunlock.m │ │ │ │ ├── test_libltfat_rtdgtreal.m │ │ │ │ ├── test_libltfat_rtdgtrealprocessor.m │ │ │ │ ├── test_libltfat_slicingprocessor.m │ │ │ │ ├── test_libltfat_slidgtrealmp.m │ │ │ │ └── test_libltfat_solvehermitiansystem.m │ │ │ └── pyUnit │ │ │ │ ├── test_libltfat_fftshift.py │ │ │ │ └── testhelper.py │ │ └── thirdparty │ │ │ └── kissfft │ │ │ ├── CHANGELOG │ │ │ ├── COPYING │ │ │ ├── Makefile │ │ │ ├── README │ │ │ ├── README.simd │ │ │ ├── TIPS │ │ │ ├── _kiss_fft_guts.h │ │ │ └── fft.c │ └── libphaseret │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── doc │ │ ├── DoxygenLayout.xml │ │ ├── doxyconfig │ │ ├── doxymain.md │ │ ├── gla.md │ │ ├── htmltemplate │ │ │ ├── customdoxygen.css │ │ │ ├── footer.html │ │ │ └── header.html │ │ ├── legla.md │ │ ├── mathjaxinclude │ │ │ └── macros.js │ │ ├── pghi.md │ │ ├── rtisila.md │ │ ├── rtpghi.md │ │ ├── spsi.md │ │ └── texinclude │ │ │ └── macros.tex │ │ ├── include │ │ ├── phaseret.h │ │ └── phaseret │ │ │ ├── api.h │ │ │ ├── basicmacros.h │ │ │ ├── generic.h │ │ │ ├── gla.h │ │ │ ├── gsrtisila.h │ │ │ ├── gsrtisilapghi.h │ │ │ ├── legla.h │ │ │ ├── pghi.h │ │ │ ├── rtisila.h │ │ │ ├── rtpghi.h │ │ │ ├── rtpghifb.h │ │ │ ├── spsi.h │ │ │ ├── types.h │ │ │ └── utils.h │ │ ├── src │ │ ├── CMakeLists.txt │ │ ├── filedefs.mk │ │ ├── gla.c │ │ ├── gsrtisila.c │ │ ├── gsrtisila_private.h │ │ ├── gsrtisilapghi.c │ │ ├── legla.c │ │ ├── legla_private.h │ │ ├── legla_typeconstant.c │ │ ├── pghi.c │ │ ├── pghi_typeconstant.c │ │ ├── rtisila.c │ │ ├── rtpghi.c │ │ ├── rtpghi_private.h │ │ ├── rtpghifb.c │ │ ├── rtpghifb_private.h │ │ ├── spsi.c │ │ └── utils.c │ │ └── testing │ │ └── mUnit │ │ ├── complex2interleaved.m │ │ ├── interleaved2complex.m │ │ ├── loadlibphaseret.m │ │ ├── test_all_libphaseret.m │ │ ├── test_libphaseret_gla.m │ │ ├── test_libphaseret_gsrtisila.m │ │ ├── test_libphaseret_gsrtisilapghi.m │ │ ├── test_libphaseret_legla.m │ │ ├── test_libphaseret_overlaynthframe.m │ │ ├── test_libphaseret_pghi.m │ │ ├── test_libphaseret_rtisila.m │ │ ├── test_libphaseret_rtpghi.m │ │ └── test_libphaseret_spsi.m └── ostools.mk ├── mat2doc ├── conf.py ├── copyrightplate ├── generatetitle.m ├── html │ ├── conf.py │ ├── highlight.css │ ├── include │ │ ├── docnav.html │ │ ├── jumplist.js │ │ └── macros.js │ └── template.html ├── images │ ├── phaseret2_common.png │ ├── phaseret2_gsrtisila.png │ ├── phaseret2_proposed.png │ ├── phaseret2_rtisila.png │ ├── phaseret2_rtpghi.png │ ├── phaseret_rtisi.png │ ├── phaseret_rtpghi.png │ ├── phaseret_spsi.png │ ├── phaseretmix_default.png │ ├── phaseretmix_pghi.png │ ├── phaseretmix_rtisi.png │ ├── phaseretmix_spsi.png │ ├── title_greasy.png │ └── title_greasy_diff.png ├── make_packages.sh ├── mat │ ├── DESCRIPTION │ ├── conf.py │ ├── header.m │ └── release.py ├── nodocs ├── project.bib └── startup.m ├── mex ├── Makefile ├── Makefile_crossmingw ├── Makefile_mingw ├── comp_gsrtisilaupdate.c ├── comp_leglaupdate.c ├── comp_leglaupdatesinglecol.c ├── comp_maskedspsi.c ├── comp_rtisilaupdate.c ├── comp_rtpghifbupdate.c ├── comp_rtpghiupdate.c ├── comp_spsi.c ├── mex_helper.h ├── mexinit.m └── phaseret_dummymex.c ├── phaseret_version ├── phaseretmex.m ├── phaseretstart.m ├── sigproc └── phasevocoder.m ├── test_rtpghifb.m ├── tests ├── test_all_phaseret.m ├── testphaseret_decolbfgs.m ├── testphaseret_gla.m ├── testphaseret_gsrtisila.m ├── testphaseret_legla.m ├── testphaseret_lertisila.m ├── testphaseret_pghi.m ├── testphaseret_phaseretdemos.m ├── testphaseret_rtisila.m ├── testphaseret_rtpghi.m ├── testphaseret_spsi.m └── testsinit.m └── wavelets └── rtpghifbwl.m /.gitignore: -------------------------------------------------------------------------------- 1 | libphaseret/testing/mUnit/libphaseretprotofile.m 2 | libltfat/testing/mUnit/libltfatprotofile.m 3 | libltfat/testing/pyUnit/__* 4 | libltfat/CMakeCache.txt 5 | libphaseret/CMakeCache.txt 6 | repr/Databases/* 7 | repr 8 | build 9 | mat2doc_* 10 | latex 11 | *.o 12 | *.a 13 | *.so 14 | *.wav 15 | *.mat 16 | *.mex* 17 | *.m~ 18 | .* 19 | libltfat/CMakeFiles/* 20 | libphaseret/CMakeFiles/* 21 | octave-workspace 22 | 23 | -------------------------------------------------------------------------------- /Changelog: -------------------------------------------------------------------------------- 1 | Version 0.2.3 2 | ------------- 3 | 4 | * Fixed compilation in Octave on Windows. 5 | 6 | Version 0.2.2 7 | ------------- 8 | 9 | * Compilation of the MEX files is now 2018a ready. 10 | * Updated libltfat. 11 | * Fixed some compilation issues in Matlab on OSX. 12 | 13 | Version 0.2.1 14 | ------------- 15 | 16 | * Fixed few doc bugs 17 | * Introduced pghi demo 18 | 19 | Version 0.2.0 20 | ------------- 21 | 22 | * Reorganized directory structure. 23 | 24 | Version 0.1.0 25 | ------------- 26 | 27 | Initial release. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## PhaseReT 2 | PhaseReT is a Matlab/GNU Octave toolbox collecting implementations of 3 | phase-reconstruction algorithms for complex time-frequency representations 4 | (like STFT). 5 | 6 | ## Requirements 7 | 8 | The toolbox depends on [LTFAT - Large Time-Frequency Analysis Toolbox](http://ltfat.github.io). 9 | LTFAT can be installed in various ways. Please follow instructions at the 10 | [LTFAT release page](https://github.com/ltfat/ltfat/releases/latest). 11 | 12 | Further, some functions require additional dependencies: 13 | 14 | * [decolbfgs](http://ltfat.github.io/phaseret/mat/decolbfgs.html) requires 15 | [minFunc](https://www.cs.ubc.ca/~schmidtm/Software/minFunc.html) 16 | 17 | ## Installation and usage (Matlab and GNU Octave) 18 | 19 | On Matlab in Windows, it is recommended to use the pre-compiled binary release package 20 | (phaseret-[version]-win64.zip) from 21 | [the GitHub release page](https://github.com/ltfat/phaseret/releases). 22 | 23 | For other configurations, download the source-only package (phaseret-[version]-src.tgz). 24 | 25 | In order to use the toolbox it is necessary to run 26 | ``` 27 | phaseretstart; 28 | ``` 29 | from the [path_to_phaseret] directory. The command checks whether LTFAT has 30 | already been started and whether phaseret MEX interfaces are already compiled. 31 | 32 | In order to compile the missing mex files 33 | run 34 | ``` 35 | phaseretmex; 36 | ``` 37 | from within Matlab/Octave command line. 38 | 39 | ## Documentation 40 | Online documentation is available [here](http://ltfat.github.io/phaseret/doc). 41 | 42 | ## References 43 | 44 | If you use this toolbox/library in your research, please cite 45 | 46 | > Z. Prusa: The Phase Retrieval Toolbox, AES Int. Conf. On 47 | > Semantic Audio, Erlangen, Germany, June, 2017 [preprint](http://ltfat.github.io/notes/ltfatnote045.pdf). 48 | 49 | ``` 50 | @inproceedings{ltfatnote045, 51 | year={2017}, 52 | month={June}, 53 | title={{The Phase Retrieval Toolbox}}, 54 | author={Zden\v{e}k Pr\r{u}\v{s}a}, 55 | booktitle = {{AES} International Conference On Semantic Audio}, 56 | address = {Erlangen, Germany}} 57 | ``` 58 | 59 | and/or relevant references found in help of the individual files. 60 | 61 | ## License 62 | PhaseReT is distributed under terms of 63 | [GPL3](http://www.gnu.org/licenses/gpl-3.0.en.html) 64 | -------------------------------------------------------------------------------- /comp/comp_gsrtisilawins.m: -------------------------------------------------------------------------------- 1 | function [gana,gd] = comp_gsrtisilawins(g,gd,a,M,lookahead) 2 | 3 | lookback = ceil(numel(g)/a) -1; 4 | 5 | % ... as array 6 | gd = gabwin(gd,a,M); 7 | % Create and overlay several scaled dual windows 8 | wins = repmat(g.*gd*M,1,lookback+1+lookahead); 9 | winsum = comp_overlayframes(wins,a,M); 10 | rellim = 1e-3; 11 | idx = abs(winsum) 0) = rellim; 14 | winsum(idx & winsum < 0) = -rellim; 15 | winsum(winsum == 0) = 1; 16 | 17 | gana = zeros(numel(g),lookahead+1); 18 | for la = 1:lookahead + 1 19 | idx = la + lookback - 1; 20 | gana(:,la) = fftshift(g)./winsum(a*idx+1:a*idx + M); 21 | end 22 | 23 | gd = fftshift(gd); 24 | % Reverse order of the windows such that gana(:,1) is analysis window for 25 | % the newest lookahead frame. 26 | gana = gana(:,end:-1:1); 27 | 28 | 29 | -------------------------------------------------------------------------------- /comp/comp_overlayframes.m: -------------------------------------------------------------------------------- 1 | function [partrec,nthframe] = comp_overlayframes(cframes,a,M,n) 2 | 3 | N = size(cframes,2); 4 | bufLen = N*a - (a-1) + M-1; 5 | partrec = zeros(bufLen,1); 6 | 7 | startidx = floor(M/2); 8 | idxrange = startidx + [0:ceil(M/2)-1,-floor(M/2):-1]; 9 | for ii=0:N-1 10 | idx = ii*a + idxrange + 1; 11 | partrec(idx) = partrec(idx) + cframes(:,ii+1); 12 | end 13 | 14 | if nargin > 3 15 | nthframe = partrec(a*n+1:a*n + M); 16 | end -------------------------------------------------------------------------------- /comp/comp_pghiphasegrad.m: -------------------------------------------------------------------------------- 1 | function [ tgrad, fgrad, logs ] = comp_pghiphasegrad( s, gamma, a, M, do_timeinv, do_causal ) 2 | 3 | [M2,N] = size(s); 4 | 5 | if do_timeinv 6 | fgradmul = @(fgrad) -gamma/(a*M)*fgrad; 7 | tgradmul = @(tgrad) bsxfun(@plus,a*M/gamma*tgrad, 2*pi*a*(0:M2-1)'/M); 8 | else 9 | fgradmul = @(fgrad) bsxfun(@plus,-gamma/(a*M)*fgrad, -2*pi*a*(0:N-1)/M); 10 | tgradmul = @(tgrad) a*M/gamma*tgrad; 11 | end 12 | 13 | logs=log(s + eps); 14 | % tt=-10; 15 | % logs(logssabs(m-1) && sabs(m)>sabs(m+1)) 20 | alpha=log(sabs(m-1)+eps); 21 | beta=log(sabs(m)+eps); 22 | gamma=log(sabs(m+1)+eps); 23 | % This is 2nd difference 24 | denom=alpha-2*beta+gamma; 25 | 26 | % initialize p 27 | if(denom~=0) 28 | % Peak offset from m 29 | p=0.5*(alpha-gamma)/denom; 30 | else 31 | % denom is zero only at inflection point (2nd deriv is zero) 32 | p=0; 33 | end 34 | 35 | % Peak is at m+p in Matlab indexing 36 | instf = (m-1+p); 37 | centno = centno + 1; 38 | peakPhase = m_phase(m) + 2*pi*a*instf/M; %phase accumulator for this peak bin 39 | 40 | % Explicitly assign the peak phase to three bins around the peak 41 | m_phase(m) = peakPhase; 42 | 43 | if (p>0) 44 | m_phase(m+1)=peakPhase; 45 | binup = m+2; 46 | bindown = m-1; 47 | end 48 | 49 | if (p<0) 50 | m_phase(m-1)=peakPhase; 51 | binup = m+1; 52 | bindown = m-2; 53 | end 54 | 55 | % Go down from the peak until valey 56 | bin=bindown; 57 | while(bin>1 && sabs(bin). 18 | */ 19 | -------------------------------------------------------------------------------- /libltfat/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.1) 2 | project (examples CXX C) 3 | 4 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/utils) 5 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../modules/libltfat/include) 6 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../modules/libphaseret/include) 7 | 8 | set (CMAKE_CXX_STANDARD 14) 9 | set(CMAKE_CXX_FLAGS ${OLD_CMAKE_CXX_FLAGS}) 10 | set(CMAKE_C_FLAGS ${OLD_CMAKE_C_FLAGS}) 11 | 12 | 13 | if(CMAKE_CROSSCOMPILING) 14 | SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++") 15 | endif(CMAKE_CROSSCOMPILING) 16 | 17 | add_subdirectory(multigabormp) 18 | -------------------------------------------------------------------------------- /libltfat/examples/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS+=-g -Wall -Wextra -std=c++11 2 | 3 | SRC=$(wildcard *.c) 4 | PROGS = $(patsubst %.c,%,$(SRC)) 5 | 6 | all: $(PROGS) 7 | 8 | %: %.c 9 | $(CXX) $(CFLAGS) -g -Ofast -I.. $< -o $@ ../build/libltfat.a -lblas -llapack -lfftw3 -lc -lm -lsndfile 10 | 11 | clean: 12 | -rm $(PROGS) 13 | -------------------------------------------------------------------------------- /libltfat/examples/example_dgtprocessor.cpp: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | 3 | class DGTProcessor 4 | { 5 | public: 6 | class Callback 7 | { 8 | public: 9 | virtual int callback(const std::complex in[], 10 | const int M2, const int W, 11 | std::complex out[]) noexcept = 0; 12 | }; 13 | 14 | DGTProcessor(LTFAT_FIRWIN win, int gl, int a, int M, int Wmax) 15 | { 16 | processor_struct = rtdgtreal_processor_wininit_s( g, gl, a, M, Wmax, nullptr, nullptr); 17 | if (!processor_struct) 18 | throw std::invalid_argument(); 19 | } 20 | 21 | DGTProcessor(LTFAT_FIRWIN win, int gl, int a, int M, int Wmax, DGTProcessor::Callback callback): 22 | DGTProcessor(win, gl, a, M, Wmax) 23 | { 24 | registerCallback(callback); 25 | } 26 | 27 | 28 | virtual ~DGTProcessor() 29 | { 30 | if (processor_struct) 31 | rtdgtreal_processor_done_s(processor_struct); 32 | } 33 | 34 | void registerCallback(DGTProcessor::Callback* callback) 35 | { 36 | rtdgtreal_processor_setcallback_s( processor_struct, DGTProcessor::callbackWrapper, static_cast(callback)); 37 | } 38 | 39 | int process(const float in[], int bufLen, float out[]) noexcept 40 | { 41 | rtdgtreal_processor_execute_s(processor_struct, in, bufLen, out); 42 | } 43 | 44 | private: 45 | rtdgtreal_processor_s* processor_struct{ nullptr }; 46 | 47 | static void callbackWrapper( 48 | void* userdata, const float in[][2], const int M2, const int W, float out[][2]) 49 | { 50 | static_cast(userdata)->callback( 51 | reinterpret_cast*>(in), M2, W, 52 | reinterpret_cast*>(out)); 53 | } 54 | }; 55 | 56 | class SimpleDGTProcessorCallback : public DGTProcessor::Callback 57 | { 58 | public: 59 | int callback( 60 | const std::complex in[], 61 | const int M2, const int W, 62 | std::complex out[]) noexcept 63 | { 64 | std::copy_n(in, M2 * W, out); 65 | } 66 | }; 67 | -------------------------------------------------------------------------------- /libltfat/examples/example_gabanasyn.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "ltfat.h" 6 | 7 | int main() 8 | { 9 | // Number of frequency channels 10 | ltfatInt M = 2048; 11 | // Hop factor 12 | ltfatInt a = 256; 13 | // Length of the signal. Must be an integer multiple of both a and M 14 | ltfatInt L = 100*2048; 15 | // Length of the window, I use a Gauss window here which is possibly 16 | // fully supported 17 | ltfatInt gl = L; 18 | // Number of channels 19 | ltfatInt W = 1; 20 | 21 | // Number of unique channels when the input is a real signal 22 | ltfatInt M2 = M / 2 + 1; 23 | // Number of time hops 24 | ltfatInt N = L / a; 25 | 26 | // Allocate space for a window 27 | double* g = ltfat_malloc(gl * sizeof * g); 28 | // Alocate space for the dual window 29 | double* gd = ltfat_malloc(gl * sizeof * gd); 30 | // Space for input signal 31 | double* f = ltfat_malloc(W * L * sizeof * f); 32 | // Space for reconstructed signal 33 | double* frec = ltfat_malloc(W * L * sizeof * f); 34 | // Space for coefficients 35 | double _Complex* c = ltfat_malloc(W * M2 * N * sizeof * c); 36 | 37 | // Generate some input 38 | srand(time(NULL)); 39 | for (ltfatInt l = 0; l < W * L; ++l) 40 | { 41 | f[l] = ((double)rand()) / RAND_MAX; 42 | } 43 | 44 | // Compute window. Using a*M/L for w makes the time-frequency support of the 45 | // Gaussion window to best fit the time-frequency sampling grid 46 | pgauss_d(L, a * M / L, 0, g); 47 | 48 | // Compute the dual window 49 | gabdual_long_d(g,L,1,a,M,gd); 50 | 51 | // Do the transform 52 | dgtreal_long_d(f, g, L, W, a, M, TIMEINV, c); 53 | 54 | // Do inverse transform 55 | idgtreal_long_d(c, gd, L, W, a, M, TIMEINV, frec); 56 | 57 | 58 | // Comute error of the reconstruction 59 | double err = 0.0; 60 | 61 | for (ltfatInt l = 0; l < L * W; ++l) 62 | { 63 | double dif = fabs( f[l] - frec[l] ); 64 | err += dif * dif; 65 | } 66 | 67 | printf("Error of the reconstruction is %e\n", err); 68 | 69 | LTFAT_SAFEFREEALL(g, gd, f, frec, c); 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /libltfat/examples/multigabormp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(multigabormpd multigabormpd.cpp) 2 | target_link_libraries(multigabormpd ltfat) 3 | 4 | -------------------------------------------------------------------------------- /libltfat/examples/multigabormp/Makefile: -------------------------------------------------------------------------------- 1 | CXXFLAGS+=-Ofast -Wall -Wextra -std=c++1z 2 | 3 | ifeq ($(TYPE),single) 4 | CXXFLAGS+=-DLTFAT_SINGLE 5 | else 6 | CXXFLAGS+=-DLTFAT_DOUBLE 7 | endif 8 | 9 | SRC=$(wildcard *.cpp) 10 | PROGS = $(patsubst %.cpp,%,$(SRC)) 11 | libltfat=../../build/libltfat.a 12 | 13 | all: $(PROGS) 14 | 15 | $(PROGS): %: %.cpp $(libltfat) 16 | $(CXX) $(CXXFLAGS) -I../utils -I../../modules/libltfat/include $< -o $@ $(libltfat) -lfftw3 -lfftw3f -lc -lm 17 | 18 | $(libltfat): 19 | make -C ../.. -j12 MODULE=libltfat NOBLASLAPACK=1 COMPTARGET=fulloptim static 20 | 21 | clean: cleanlib cleanexe 22 | 23 | cleanlib: 24 | make -C ../.. clean 25 | 26 | cleanexe: 27 | -rm $(PROGS) 28 | 29 | -------------------------------------------------------------------------------- /libltfat/examples/utils/ltfathelper.h: -------------------------------------------------------------------------------- 1 | #if !(defined(LTFAT_DOUBLE) || defined(LTFAT_SINGLE)) 2 | #define LTFAT_DOUBLE 3 | #endif 4 | 5 | #include "ltfat.h" 6 | #include "ltfat/types.h" 7 | #include "ltfat/macros.h" 8 | 9 | #ifdef __cplusplus 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | using Clock = std::chrono::high_resolution_clock; 16 | using namespace std; 17 | #else 18 | #endif 19 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/doc/dgt.md: -------------------------------------------------------------------------------- 1 | \page dgttheory Discrete Gabor transform (also called STFT) 2 | 3 | 4 | 5 | For more details please see 6 | \cite ltfatnote003 7 | \cite ltfatnote006 8 | \cite ltfatnote011 9 | 10 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/doc/htmltemplate/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/doc/htmltemplate/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | $projectname: $title 9 | $title 10 | 11 | 12 | 13 | $treeview 14 | $search 15 | $mathjax 16 | 17 | $extrastylesheet 18 | 19 | 20 |
21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |  $projectnumber --> 34 | 35 |
$projectbrief
--> 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 |
$searchbox
53 |
54 | 55 | 56 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/doc/mathjaxinclude/macros.js: -------------------------------------------------------------------------------- 1 | MathJax.Hub.Config({ 2 | TeX: { 3 | Macros: { 4 | stime: "t", 5 | sfreq: "\\omega", 6 | sfreqarg: "\\xi", 7 | stimearg: "\\tau", 8 | me: "\\mathrm{e}", 9 | mi: "\\mathrm{i}", 10 | } 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/doc/texinclude/macros.tex: -------------------------------------------------------------------------------- 1 | 2 | \DeclareMathOperator*{\argmax}{arg\,max} 3 | \DeclareMathOperator*{\supp}{supp} 4 | 5 | \newcommand{\stime}{t} 6 | \newcommand{\stimearg}{\tau} 7 | \newcommand{\sfreq}{\omega} 8 | \newcommand{\sfreqarg}{\xi} 9 | 10 | 11 | \newcommand{\Lspacen}[1]{\ensuremath{L^2\left\mathcal{R}^{#1}\right}} 12 | \newcommand{\Lspace}{\Lspacen{}} 13 | \newcommand{\Lspacetwod}{\Lspacen{2}} 14 | 15 | \newcommand{\barg}{\ensuremath{\mathcal{B}}} 16 | \newcommand{\dstimearg}{\ensuremath{\, \mathrm{d}\stimearg}} 17 | 18 | \newcommand{\modop}{\ensuremath{\mathcal{E}}} 19 | \newcommand{\tranop}{\ensuremath{\mathcal{T}}} 20 | \newcommand{\dilop}{\ensuremath{\mathcal{D}}} 21 | 22 | \newcommand{\modoparg}[1]{\ensuremath{\modop_{#1}}} 23 | \newcommand{\tranoparg}[1]{\ensuremath{\tranop_{#1}}} 24 | \newcommand{\diloparg}[1]{\ensuremath{\dilop_{#1}}} 25 | 26 | \newcommand{\modopsfreq}{\modoparg{\sfreq}} 27 | \newcommand{\tranopstime}{\tranoparg{\stime}} 28 | \newcommand{\diloplambda}{\diloparg{\lambda}} 29 | 30 | \newcommand{\stftphase}[2]{\ensuremath{\Phi_{#1}^{#2}}} 31 | \newcommand{\stftmodulus}[2]{\ensuremath{M_{#1}^{#2}}} 32 | 33 | \newcommand{\stftphasefvarphi}{\stftphase{\varphi}{f}} 34 | \newcommand{\stftmodulusfvarphi}{\stftmodulus{\varphi}{f}} 35 | 36 | \newcommand{\stftphasefg}{\stftphase{g}{f}} 37 | \newcommand{\stftmodulusfg}{\stftmodulus{g}{f}} 38 | 39 | \newcommand{\me}{\mathrm{e}} 40 | \newcommand{\mi}{\mathrm{i}} 41 | 42 | % \newcommand{\normm}[1]{\left\lVert#1\right\rVert} 43 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/include/ltfat/basicmacros.h: -------------------------------------------------------------------------------- 1 | #ifndef _LTFAT_BASICMACROS_H 2 | #define _LTFAT_BASICMACROS_H 3 | 4 | #ifndef LTFAT_API 5 | #if defined(_WIN32) || defined(__WIN32__) 6 | # if defined(LTFAT_BUILD_SHARED) 7 | # define LTFAT_API __declspec(dllexport) 8 | # elif !defined(LTFAT_BUILD_STATIC) 9 | # define LTFAT_API __declspec(dllimport) 10 | # else 11 | # define LTFAT_API 12 | # endif 13 | #else 14 | // # if __GNUC__ >= 4 15 | // # define LTFAT_API __attribute__((visibility("default"))) 16 | // # else 17 | # define LTFAT_API 18 | // # endif 19 | #endif 20 | #endif 21 | 22 | #define LTFAT_MAKENAME(prefix,name,suffix) prefix ## _ ## name ## suffix 23 | 24 | #define LTFAT_NAME_DOUBLE(name) LTFAT_MAKENAME(ltfat,name,_d) 25 | #define LTFAT_NAME_SINGLE(name) LTFAT_MAKENAME(ltfat,name,_s) 26 | #define LTFAT_NAME_COMPLEXDOUBLE(name) LTFAT_MAKENAME(ltfat,name,_dc) 27 | #define LTFAT_NAME_COMPLEXSINGLE(name) LTFAT_MAKENAME(ltfat,name,_sc) 28 | 29 | 30 | 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/include/ltfat/blaslapack.h: -------------------------------------------------------------------------------- 1 | #ifndef _ltfat_blaslapack 2 | #define _ltfat_blaslapack 3 | #include "ltfat.h" 4 | #include "ltfat/types.h" 5 | #include "ltfat/thirdparty/cblas.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" 9 | { 10 | #endif 11 | 12 | 13 | // LAPACK overwrites the input argument. 14 | ltfat_int 15 | LTFAT_NAME(posv)(const ptrdiff_t N, const ptrdiff_t NRHS, 16 | LTFAT_COMPLEX *A, const ptrdiff_t lda, 17 | LTFAT_COMPLEX *B, const ptrdiff_t ldb); 18 | 19 | // LAPACK overwrites the input argument. 20 | ltfat_int 21 | LTFAT_NAME(gesvd)(const ptrdiff_t M, const ptrdiff_t N, 22 | LTFAT_COMPLEX *A, const ptrdiff_t lda, 23 | LTFAT_REAL *S, LTFAT_COMPLEX *U, const ptrdiff_t ldu, 24 | LTFAT_COMPLEX *VT, const ptrdiff_t ldvt); 25 | 26 | void 27 | LTFAT_NAME(gemm)(const enum CBLAS_TRANSPOSE TransA, 28 | const enum CBLAS_TRANSPOSE TransB, 29 | const ptrdiff_t M, const ptrdiff_t N, const ptrdiff_t K, 30 | const LTFAT_COMPLEX *alpha, 31 | const LTFAT_COMPLEX *A, const ptrdiff_t lda, 32 | const LTFAT_COMPLEX *B, const ptrdiff_t ldb, 33 | const LTFAT_COMPLEX *beta, 34 | LTFAT_COMPLEX *C, const ptrdiff_t ldc); 35 | 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/include/ltfat/ci_memalloc.h: -------------------------------------------------------------------------------- 1 | LTFAT_API LTFAT_TYPE* 2 | LTFAT_NAME(malloc)(size_t n); 3 | 4 | LTFAT_API LTFAT_TYPE* 5 | LTFAT_NAME(calloc)(size_t n); 6 | 7 | LTFAT_API LTFAT_TYPE* 8 | LTFAT_NAME(realloc)(LTFAT_TYPE *ptr, size_t nold, size_t nnew); 9 | 10 | LTFAT_API LTFAT_TYPE* 11 | LTFAT_NAME(postpad) (LTFAT_TYPE* ptr, size_t nold, size_t nnew); 12 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/include/ltfat/dct.h: -------------------------------------------------------------------------------- 1 | #ifndef _LTFAT_DCT_H 2 | #define _LTFAT_DCT_H 3 | 4 | typedef enum 5 | { 6 | DCTI, DCTIII, DCTII, DCTIV 7 | } dct_kind; 8 | 9 | #endif 10 | 11 | typedef struct LTFAT_NAME(dct_plan) LTFAT_NAME(dct_plan); 12 | 13 | LTFAT_API LTFAT_NAME(dct_plan)* 14 | LTFAT_NAME(dct_init)( ltfat_int L, ltfat_int W, LTFAT_TYPE *cout, 15 | const dct_kind kind); 16 | 17 | LTFAT_API void 18 | LTFAT_NAME(dct)(const LTFAT_TYPE *f, ltfat_int L, ltfat_int W, 19 | LTFAT_TYPE *cout, const dct_kind kind); 20 | 21 | LTFAT_API void 22 | LTFAT_NAME(dct_execute)(const LTFAT_NAME(dct_plan)* p, const LTFAT_TYPE *f, 23 | ltfat_int L, ltfat_int W, 24 | LTFAT_TYPE *cout, const dct_kind kind); 25 | 26 | LTFAT_API void 27 | LTFAT_NAME(dct_done)( LTFAT_NAME(dct_plan)* p); 28 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/include/ltfat/dgt_common.h: -------------------------------------------------------------------------------- 1 | #ifndef _LTFAT_DGT_COMMON_H 2 | #define _LTFAT_DGT_COMMON_H 3 | #include "ltfat/basicmacros.h" 4 | /** \addtogroup dgt 5 | * @{ 6 | */ 7 | 8 | /** \name Phase convention 9 | * @{ */ 10 | 11 | /** Discrete Gabor Transform Phase convention 12 | * 13 | * There are two commonly used phase conventions. 14 | * 15 | * Frequency invariant: 16 | * \anchor dgtfreqinv 17 | * \f[ 18 | * c(m,n) 19 | * = \sum_{l=0}^{L-1}\! f(l) 20 | * \overline{g(l-na)} \me^{-\mi 2\pi l m/M } \, 21 | * \f] 22 | * This is commonly used by mathematicans. Effectivelly, each 23 | * frequency channel is demodulated to the baseband. 24 | * 25 | * Time invatiant: 26 | * \anchor dgttimeinv 27 | * \f[ 28 | * c(m,n) 29 | * = \sum_{l=0}^{L-1}\! f(l) 30 | * \overline{g(l-na)} \me^{-\mi 2\pi (l-na) m/M } \, 31 | * \f] 32 | * This is commonly used by engineers. This is equivalent to 33 | * a filterbank. 34 | * 35 | * \see dgt_phaselock dgtreal_phaselock dgt_phaseunlock dgtreal_phaseunlock 36 | * 37 | */ 38 | typedef enum 39 | { 40 | LTFAT_TIMEINV = 0, 41 | LTFAT_FREQINV = 1, 42 | LTFAT_POPULAR = 2 43 | } ltfat_phaseconvention; 44 | 45 | /** @}*/ 46 | /** @}*/ 47 | 48 | #ifdef __cplusplus 49 | extern "C" 50 | { 51 | #endif 52 | 53 | LTFAT_API int 54 | ltfat_phaseconvention_is_valid(ltfat_phaseconvention in); 55 | 56 | #ifdef __cplusplus 57 | } // extern "C" 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/include/ltfat/dgt_multi.h: -------------------------------------------------------------------------------- 1 | typedef struct LTFAT_NAME(dgt_multi_plan) LTFAT_NAME(dgt_multi_plan); 2 | 3 | // { 4 | // ltfat_int a; 5 | // ltfat_int M; 6 | // ltfat_int L; 7 | // ltfat_int Lg; 8 | // ltfat_int W; 9 | // ltfat_int lt1; 10 | // ltfat_int lt2; 11 | // 12 | // LTFAT_COMPLEX *f; 13 | // LTFAT_COMPLEX *c_scratch; 14 | // LTFAT_COMPLEX *cout; 15 | // 16 | // LTFAT_COMPLEX *mwin; 17 | // LTFAT_COMPLEX *c_rect; 18 | // 19 | // LTFAT_COMPLEX *mod; 20 | // 21 | // LTFAT_NAME(dgt_long_plan) *rect_plan_array; 22 | // 23 | // } LTFAT_NAME(dgt_multi_plan); 24 | 25 | struct LTFAT_NAME(dgt_multi_plan) 26 | { 27 | ltfat_int a; 28 | ltfat_int M; 29 | ltfat_int L; 30 | ltfat_int Lg; 31 | ltfat_int W; 32 | ltfat_int lt1; 33 | ltfat_int lt2; 34 | 35 | LTFAT_COMPLEX *f; 36 | LTFAT_COMPLEX *c_scratch; 37 | LTFAT_COMPLEX *cout; 38 | 39 | LTFAT_COMPLEX *mwin; 40 | LTFAT_COMPLEX *c_rect; 41 | 42 | LTFAT_COMPLEX *mod; 43 | 44 | LTFAT_NAME_COMPLEX(dgt_long_plan)** rect_plan_array; 45 | }; 46 | 47 | LTFAT_API LTFAT_NAME(dgt_multi_plan) 48 | LTFAT_NAME(dgt_multi_init)(const LTFAT_COMPLEX *f, const LTFAT_COMPLEX *g, 49 | ltfat_int L, ltfat_int Lg, ltfat_int W, ltfat_int a, ltfat_int M, 50 | ltfat_int lt1, ltfat_int lt2, 51 | LTFAT_COMPLEX *c,unsigned flags); 52 | 53 | LTFAT_API void 54 | LTFAT_NAME(dgt_multi_execute)(const LTFAT_NAME(dgt_multi_plan) plan); 55 | 56 | LTFAT_API void 57 | LTFAT_NAME(dgt_multi_done)(LTFAT_NAME(dgt_multi_plan) plan); 58 | 59 | LTFAT_API void 60 | LTFAT_NAME(nonsepwin2multi)(const LTFAT_COMPLEX *g, 61 | ltfat_int L, ltfat_int Lg, ltfat_int a, ltfat_int M, 62 | ltfat_int lt1, ltfat_int lt2, 63 | LTFAT_COMPLEX *mwin); 64 | 65 | LTFAT_API void 66 | LTFAT_NAME(dgt_multi)(const LTFAT_COMPLEX *f, const LTFAT_COMPLEX *g, 67 | ltfat_int L, ltfat_int Lg, ltfat_int W, ltfat_int a, ltfat_int M, 68 | ltfat_int lt1, ltfat_int lt2, 69 | LTFAT_COMPLEX *c); 70 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/include/ltfat/dgt_shear.h: -------------------------------------------------------------------------------- 1 | typedef struct 2 | { 3 | ltfat_int a; 4 | ltfat_int M; 5 | ltfat_int L; 6 | ltfat_int W; 7 | ltfat_int s0; 8 | ltfat_int s1; 9 | ltfat_int br; 10 | 11 | LTFAT_COMPLEX *p0; 12 | LTFAT_COMPLEX *p1; 13 | 14 | LTFAT_COMPLEX *fwork; 15 | LTFAT_COMPLEX *gwork; 16 | LTFAT_COMPLEX *c_rect; 17 | 18 | LTFAT_COMPLEX *finalmod; 19 | 20 | // LTFAT_FFTW(plan) f_plan; 21 | // LTFAT_FFTW(plan) g_plan; 22 | LTFAT_NAME_REAL(fft_plan)* f_plan; 23 | LTFAT_NAME_REAL(fft_plan)* g_plan; 24 | 25 | 26 | LTFAT_NAME_COMPLEX(dgt_long_plan)* rect_plan; 27 | 28 | const LTFAT_COMPLEX *f; 29 | LTFAT_COMPLEX *cout; 30 | 31 | } LTFAT_NAME(dgt_shear_plan); 32 | 33 | 34 | LTFAT_API LTFAT_NAME(dgt_shear_plan) 35 | LTFAT_NAME(dgt_shear_init)( 36 | const LTFAT_COMPLEX *f, const LTFAT_COMPLEX *g, 37 | ltfat_int L, ltfat_int W, ltfat_int a, 38 | ltfat_int M, ltfat_int s0, ltfat_int s1, ltfat_int br, 39 | LTFAT_COMPLEX *cout, 40 | unsigned flags); 41 | 42 | LTFAT_API void 43 | LTFAT_NAME(dgt_shear_execute)(const LTFAT_NAME(dgt_shear_plan) plan); 44 | 45 | LTFAT_API void 46 | LTFAT_NAME(dgt_shear_done)(LTFAT_NAME(dgt_shear_plan) plan); 47 | 48 | LTFAT_API void 49 | LTFAT_NAME(dgt_shear)(const LTFAT_COMPLEX *f, const LTFAT_COMPLEX *g, 50 | ltfat_int L, ltfat_int W, ltfat_int a, ltfat_int M, 51 | ltfat_int s0, ltfat_int s1, ltfat_int br, 52 | LTFAT_COMPLEX *c); 53 | 54 | LTFAT_API void 55 | LTFAT_NAME(pchirp)(const long long L, const long long n, LTFAT_COMPLEX *g); 56 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/include/ltfat/dst.h: -------------------------------------------------------------------------------- 1 | #ifndef _LTFAT_DST_H 2 | #define _LTFAT_DST_H 3 | 4 | typedef enum 5 | { 6 | DSTI , DSTIII , DSTII, DSTIV 7 | } dst_kind; 8 | 9 | #endif 10 | 11 | typedef struct LTFAT_NAME(dst_plan) LTFAT_NAME(dst_plan); 12 | 13 | LTFAT_API LTFAT_NAME(dst_plan)* 14 | LTFAT_NAME(dst_init)( ltfat_int L, ltfat_int W, LTFAT_TYPE *cout, 15 | const dst_kind kind); 16 | 17 | LTFAT_API void 18 | LTFAT_NAME(dst)(const LTFAT_TYPE *f, ltfat_int L, ltfat_int W, 19 | LTFAT_TYPE *cout, const dst_kind kind); 20 | 21 | LTFAT_API void 22 | LTFAT_NAME(dst_execute)(LTFAT_NAME(dst_plan)* p, const LTFAT_TYPE *f, 23 | ltfat_int L, ltfat_int W, LTFAT_TYPE *cout, 24 | const dst_kind kind); 25 | 26 | LTFAT_API void 27 | LTFAT_NAME(dst_done)( LTFAT_NAME(dst_plan)* p); 28 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/include/ltfat/heap.h: -------------------------------------------------------------------------------- 1 | typedef struct LTFAT_NAME(heap) LTFAT_NAME(heap); 2 | 3 | LTFAT_API LTFAT_NAME(heap)* 4 | LTFAT_NAME(heap_init)(ltfat_int initmaxsize, const LTFAT_REAL* s); 5 | 6 | LTFAT_API void 7 | LTFAT_NAME(heap_done)(LTFAT_NAME(heap)* h); 8 | 9 | LTFAT_API void 10 | LTFAT_NAME(heap_grow)(LTFAT_NAME(heap)* h, int factor); 11 | 12 | LTFAT_API void 13 | LTFAT_NAME(heap_reset)(LTFAT_NAME(heap)* h, const LTFAT_REAL* news); 14 | 15 | LTFAT_API ltfat_int 16 | LTFAT_NAME(heap_get)(LTFAT_NAME(heap) *h); 17 | 18 | LTFAT_API ltfat_int 19 | LTFAT_NAME(heap_delete)(LTFAT_NAME(heap) *h); 20 | 21 | LTFAT_API void 22 | LTFAT_NAME(heap_insert)(LTFAT_NAME(heap) *h, ltfat_int key); 23 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/include/ltfat/heapint.h: -------------------------------------------------------------------------------- 1 | /*This header file is suposed to be oncluded only from heapint.c */ 2 | 3 | /* 4 | * Heap is a dynamic array h of heapsize elements which are ordered according 5 | * to s such that s[h[0]] is the maximum. 6 | * 7 | * */ 8 | #include "ltfat.h" 9 | #include "ltfat/types.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" 13 | { 14 | #endif 15 | 16 | /* */ 17 | 18 | inline void 19 | LTFAT_NAME(trapezheap)(const LTFAT_NAME(heapinttask) *heaptask, 20 | const LTFAT_REAL* tgradw, const LTFAT_REAL* fgradw, 21 | ltfat_int w, LTFAT_REAL* phase); 22 | 23 | inline void 24 | LTFAT_NAME(trapezheapreal)(const LTFAT_NAME(heapinttask) *heaptask, 25 | const LTFAT_REAL* tgradw, const LTFAT_REAL* fgradw, 26 | ltfat_int w, LTFAT_REAL* phase); 27 | 28 | void 29 | LTFAT_NAME(gradsamptorad)(const LTFAT_REAL* tgrad, const LTFAT_REAL* fgrad, 30 | ltfat_int a, ltfat_int M, ltfat_int L, ltfat_int W, 31 | ltfat_phaseconvention phasetype, int do_real, 32 | LTFAT_REAL* tgradw, LTFAT_REAL* fgradw); 33 | 34 | void 35 | LTFAT_NAME(borderstoheap)(LTFAT_NAME(heap)* h, 36 | ltfat_int height, ltfat_int N, 37 | int * donemask); 38 | 39 | void 40 | LTFAT_NAME(borderstoheapreal)(LTFAT_NAME(heap)* h, 41 | ltfat_int height, ltfat_int N, 42 | int * donemask); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/include/ltfat/linalg.h: -------------------------------------------------------------------------------- 1 | typedef struct LTFAT_NAME_COMPLEX(hermsystemsolver_plan) LTFAT_NAME_COMPLEX(hermsystemsolver_plan); 2 | 3 | LTFAT_API int 4 | LTFAT_NAME_COMPLEX(hermsystemsolver_init)(ltfat_int M, 5 | LTFAT_NAME_COMPLEX(hermsystemsolver_plan)** p); 6 | 7 | 8 | LTFAT_API int 9 | LTFAT_NAME_COMPLEX(hermsystemsolver_execute)( 10 | LTFAT_NAME_COMPLEX(hermsystemsolver_plan)* p, 11 | const LTFAT_COMPLEX* A, ltfat_int M, LTFAT_COMPLEX* b); 12 | 13 | LTFAT_API int 14 | LTFAT_NAME_COMPLEX(hermsystemsolver_done)( 15 | LTFAT_NAME_COMPLEX(hermsystemsolver_plan)** p); 16 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/include/ltfat/maxtree.h: -------------------------------------------------------------------------------- 1 | // maxtree 2 | 3 | typedef struct LTFAT_NAME(maxtree) LTFAT_NAME(maxtree); 4 | typedef LTFAT_REAL 5 | LTFAT_NAME(maxtree_complexinput_callback)(void* userdata, LTFAT_COMPLEX cval, ltfat_int pos); 6 | 7 | LTFAT_API int 8 | LTFAT_NAME(maxtree_setcallback)(LTFAT_NAME(maxtree)* p, 9 | LTFAT_NAME(maxtree_complexinput_callback)* callback, 10 | void* userdata); 11 | 12 | LTFAT_API int 13 | LTFAT_NAME(maxtree_init)( 14 | ltfat_int L, ltfat_int Lstep, ltfat_int depth, 15 | LTFAT_NAME(maxtree)** p); 16 | 17 | 18 | LTFAT_API int 19 | LTFAT_NAME(maxtree_initwitharray)( 20 | ltfat_int L, ltfat_int depth, const LTFAT_REAL inarray[], 21 | LTFAT_NAME(maxtree)** p); 22 | 23 | LTFAT_API int 24 | LTFAT_NAME(maxtree_reset)( 25 | LTFAT_NAME(maxtree)* p, const LTFAT_REAL inarray[]); 26 | 27 | LTFAT_API int 28 | LTFAT_NAME(maxtree_reset_complex)( 29 | LTFAT_NAME(maxtree)* p, const LTFAT_COMPLEX inarray[]); 30 | 31 | LTFAT_API int 32 | LTFAT_NAME(maxtree_setdirty)( 33 | LTFAT_NAME(maxtree)* p, ltfat_int start, ltfat_int end); 34 | 35 | LTFAT_API int 36 | LTFAT_NAME(maxtree_getdirty)( 37 | LTFAT_NAME(maxtree)* p, ltfat_int* start, ltfat_int* end); 38 | 39 | LTFAT_API int 40 | LTFAT_NAME(maxtree_findmax)( 41 | LTFAT_NAME(maxtree)* p, LTFAT_REAL* max, ltfat_int* maxPos); 42 | 43 | LTFAT_API int 44 | LTFAT_NAME(maxtree_done)(LTFAT_NAME(maxtree)** p); 45 | 46 | int 47 | LTFAT_NAME(maxtree_updatedirty)(LTFAT_NAME(maxtree)* p); 48 | 49 | int 50 | LTFAT_NAME(maxtree_updaterange)( 51 | LTFAT_NAME(maxtree)* p, ltfat_int start, ltfat_int stop); 52 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/include/ltfat/reassign_typeconstant.h: -------------------------------------------------------------------------------- 1 | #ifndef _LTFAT_REASSIGN_TYPECONSTANT_H 2 | #define _LTFAT_REASSIGN_TYPECONSTANT_H 3 | 4 | #define fbreassOptOut_EXPANDRAT 2 5 | 6 | typedef enum 7 | { 8 | REASS_DEFAULT = 0, 9 | REASS_NOTIMEWRAPAROUND = 1 10 | } fbreassHints; 11 | 12 | typedef struct { 13 | ltfat_int** repos; 14 | ltfat_int* reposl; 15 | ltfat_int* reposlmax; 16 | ltfat_int l; 17 | } fbreassOptOut; 18 | 19 | LTFAT_API fbreassOptOut* 20 | fbreassOptOut_init(ltfat_int l,ltfat_int inital); 21 | 22 | LTFAT_API void 23 | fbreassOptOut_expand(fbreassOptOut* oo,ltfat_int ii); 24 | 25 | LTFAT_API void 26 | fbreassOptOut_destroy(fbreassOptOut* oo); 27 | 28 | 29 | #endif /* end of include guard: _REASSIGN_H */ 30 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/include/ltfat/ti_windows.h: -------------------------------------------------------------------------------- 1 | /** \addtogroup windows 2 | * @{ 3 | */ 4 | 5 | /** Compute real, periodized Gaussian window 6 | * 7 | * \param[in] L Window length 8 | * \param[in] w Time-freqency support ratio 9 | * \param[in] c_t Time center offset 10 | * \param[out] g Window 11 | * 12 | * #### Function versions # 13 | * 14 | * ltfat_pgauss_d(ltfat_int L,const double w, const double c_t, double* g); 15 | * 16 | * ltfat_pgauss_s(ltfat_int L,const double w, const double c_t, float* g); 17 | * 18 | * \returns 19 | * Status code | Description 20 | * ----------------------|------------ 21 | * LTFATERR_SUCCESS | Indicates no error 22 | * LTFATERR_NULLPOINTER | The output array is NULL. 23 | * LTFATERR_BADSIZE | Window length is less or equal to 0. 24 | * LTFATERR_NOTPOSARG | \a w is less or equal to zero. 25 | */ 26 | LTFAT_API int 27 | LTFAT_NAME(pgauss)(ltfat_int L, const double w, const double c_t, 28 | LTFAT_REAL *g); 29 | 30 | /** Compute complex, periodized Gaussian window 31 | * 32 | * \param[in] L Window length 33 | * \param[in] w Time-freqency support ratio 34 | * \param[in] c_t Time center offset 35 | * \param[in] c_f Frequency center offset 36 | * \param[out] g Window 37 | * 38 | * #### Function versions # 39 | * 40 | * 41 | * ltfat_pgauss_cd(ltfat_int L, const double w, const double c_t, 42 | * const double c_f, ltfat_complex_d* g); 43 | * 44 | * ltfat_pgauss_cs(ltfat_int L, const double w, const double c_t, 45 | * const double c_f, ltfat_complex_s* g); 46 | * 47 | * \returns 48 | * Status code | Description 49 | * ----------------------|------------ 50 | * LTFATERR_SUCCESS | Indicates no error 51 | * LTFATERR_NULLPOINTER | The output array is NULL. 52 | * LTFATERR_BADSIZE | Window length is less or equal to 0. 53 | * LTFATERR_NOTPOSARG | \a w is less or equal to zero. 54 | */ 55 | LTFAT_API int 56 | LTFAT_NAME_COMPLEX(pgauss)(ltfat_int L, const double w, const double c_t, 57 | const double c_f, LTFAT_COMPLEX *g); 58 | 59 | /** @} */ 60 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/include/ltfat/version.h: -------------------------------------------------------------------------------- 1 | /** \defgroup version Version 2 | * 3 | * Utility functions and constants for checking compatibility 4 | * of the library and the header. 5 | * 6 | * \addtogroup version 7 | * @{ 8 | */ 9 | #ifndef _LTFAT_VERSION_H 10 | #define _LTFAT_VERSION_H 11 | 12 | #define LTFAT_VERSION_MAJOR 0 13 | #define LTFAT_VERSION_MINOR 1 14 | #define LTFAT_VERSION_MICRO 0 15 | 16 | #ifdef __cplusplus 17 | extern "C" 18 | { 19 | #endif 20 | 21 | typedef struct 22 | { 23 | const char* version; 24 | const char* build_date; 25 | const unsigned int major; 26 | const unsigned int minor; 27 | const unsigned int micro; 28 | const int ltfat_int_size; 29 | } ltfat_library_version; 30 | 31 | /** \returns Pointer to an internal library version struct 32 | * (no memory allocation occurs). 33 | */ 34 | LTFAT_API const ltfat_library_version* 35 | ltfat_get_version(); 36 | 37 | /** \returns 0 if passed version number is not compatible with 38 | * the binary version. 39 | * To check the compatibility of your version of ltfat.h with the library 40 | * pass LTFAT_VERSION_MAJOR, LTFAT_VERSION_MINOR and LTFAT_VERSION_MICRO. 41 | */ 42 | LTFAT_API int 43 | ltfat_is_compatible_version(unsigned int your_major, 44 | unsigned int your_minor, 45 | unsigned int your_micro); 46 | 47 | /** \returns Size of ltfat_int used in compilation 48 | */ 49 | LTFAT_API int 50 | ltfat_int_size(); 51 | 52 | /** \returns 0 if \t sizeofyour_ltfat_int is not equal to 53 | * sizeof(ltfat_int) used in compilation. 54 | */ 55 | LTFAT_API int 56 | ltfat_int_is_compatible(int sizeofyour_ltfat_int); 57 | 58 | /** @} */ 59 | 60 | #ifdef __cplusplus 61 | } // extern "C" 62 | #endif 63 | 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/src/argchecks.c: -------------------------------------------------------------------------------- 1 | #include "ltfat/dgt_common.h" 2 | #include "ltfat/thirdparty/fftw3.h" 3 | 4 | LTFAT_API int 5 | ltfat_phaseconvention_is_valid(ltfat_phaseconvention in) 6 | { 7 | int isvalid = 0; 8 | 9 | switch (in) 10 | { 11 | case LTFAT_TIMEINV: 12 | case LTFAT_FREQINV: 13 | isvalid = 1; break; 14 | default: 15 | isvalid = 0; 16 | } 17 | 18 | return isvalid; 19 | } 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/src/ci_memalloc.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/types.h" 3 | 4 | LTFAT_API LTFAT_TYPE* 5 | LTFAT_NAME(malloc) (size_t n) 6 | { 7 | return (LTFAT_TYPE*)ltfat_malloc(n * sizeof(LTFAT_TYPE)); 8 | } 9 | 10 | LTFAT_API LTFAT_TYPE* 11 | LTFAT_NAME(realloc) (LTFAT_TYPE* ptr, size_t nold, size_t nnew) 12 | { 13 | return (LTFAT_TYPE*)ltfat_realloc(ptr, nold * sizeof(LTFAT_TYPE), nnew * sizeof(LTFAT_TYPE)); 14 | } 15 | 16 | LTFAT_API LTFAT_TYPE* 17 | LTFAT_NAME(postpad) (LTFAT_TYPE* ptr, size_t nold, size_t nnew) 18 | { 19 | return (LTFAT_TYPE*)ltfat_postpad(ptr, nold * sizeof(LTFAT_TYPE), nnew * sizeof(LTFAT_TYPE)); 20 | } 21 | 22 | LTFAT_API LTFAT_TYPE* 23 | LTFAT_NAME(calloc) (size_t n) 24 | { 25 | return (LTFAT_TYPE*) ltfat_calloc( n, sizeof(LTFAT_TYPE)); 26 | } 27 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/src/circularbuf_private.h: -------------------------------------------------------------------------------- 1 | #ifndef _circularbuf_private_h 2 | #define _circularbuf_private_h 3 | 4 | struct LTFAT_NAME(analysis_fifo_state) 5 | { 6 | ltfat_int winLen; //!< Window length 7 | ltfat_int readchanstride; //!< Window length 8 | ltfat_int hop; //!< Hop size 9 | LTFAT_REAL* buf; //!< Ring buffer array 10 | ltfat_int bufLen; //!< Length of the previous 11 | ltfat_int readIdx; //!< Read pos. 12 | ltfat_int writeIdx; //!< Write pos. 13 | ltfat_int numChans; 14 | }; 15 | 16 | struct LTFAT_NAME(synthesis_fifo_state) 17 | { 18 | ltfat_int winLen; //!< Window length 19 | ltfat_int writechanstride; //!< Window length 20 | ltfat_int hop; //!< Hop size 21 | LTFAT_REAL* buf; //!< Ring buffer array 22 | ltfat_int bufLen; //!< Length of the previous 23 | ltfat_int readIdx; //!< Read pos. 24 | ltfat_int writeIdx; //!< Write pos. 25 | ltfat_int numChans; 26 | }; 27 | 28 | struct LTFAT_NAME(block_processor_state) 29 | { 30 | LTFAT_NAME(block_processor_callback)* 31 | processorCallback; //!< Custom processor callback 32 | void* userdata; //!< Callback data 33 | LTFAT_NAME(analysis_fifo_state)* fwdfifo; 34 | LTFAT_NAME(synthesis_fifo_state)* backfifo; 35 | ltfat_int bufLenMax; 36 | LTFAT_REAL* prebuf; 37 | LTFAT_REAL* postbuf; 38 | LTFAT_REAL* prewin; 39 | LTFAT_REAL* postwin; 40 | int freeBuffers; 41 | const LTFAT_REAL** inTmp; 42 | LTFAT_REAL** outTmp; 43 | size_t in_pos; 44 | size_t out_pos; 45 | double in_in_out_offset; 46 | double out_in_in_offset; 47 | ltfat_int prehop; 48 | ltfat_int posthop; 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/src/dgt.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/types.h" 3 | #include "ltfat/macros.h" 4 | 5 | #include "ltfat/thirdparty/fftw3.h" 6 | 7 | LTFAT_API void 8 | LTFAT_NAME(dgt_ola)(const LTFAT_COMPLEX* f, const LTFAT_COMPLEX* g, 9 | ltfat_int L, ltfat_int gl, 10 | ltfat_int W, ltfat_int a, ltfat_int M, 11 | ltfat_int bl, const ltfat_phaseconvention ptype, 12 | LTFAT_COMPLEX* cout) 13 | { 14 | LTFAT_NAME(dgt_ola_plan) plan = 15 | LTFAT_NAME(dgt_ola_init)(g, gl, W, a, M, bl, ptype, FFTW_ESTIMATE); 16 | 17 | LTFAT_NAME(dgt_ola_execute)(plan, f, L, cout); 18 | 19 | LTFAT_NAME(dgt_ola_done)(plan); 20 | 21 | } 22 | 23 | 24 | LTFAT_API void 25 | LTFAT_NAME(dgtreal_ola)(const LTFAT_REAL* f, const LTFAT_REAL* g, 26 | ltfat_int L, ltfat_int gl, 27 | ltfat_int W, ltfat_int a, ltfat_int M, 28 | ltfat_int bl, const ltfat_phaseconvention ptype, 29 | LTFAT_COMPLEX* cout) 30 | { 31 | LTFAT_NAME(dgtreal_ola_plan) plan = 32 | LTFAT_NAME(dgtreal_ola_init)(g, gl, W, a, M, bl, ptype, FFTW_ESTIMATE); 33 | 34 | LTFAT_NAME(dgtreal_ola_execute)(plan, f, L, cout); 35 | 36 | LTFAT_NAME(dgtreal_ola_done)(plan); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/src/dgt_long_private.h: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/types.h" 3 | #include "ltfat/macros.h" 4 | 5 | #include "ltfat/thirdparty/fftw3.h" 6 | 7 | struct LTFAT_NAME_REAL(dgt_long_plan) 8 | { 9 | ltfat_int a; 10 | ltfat_int M; 11 | ltfat_int L; 12 | ltfat_int W; 13 | ltfat_int c; 14 | ltfat_int h_a; 15 | ltfat_phaseconvention ptype; 16 | LTFAT_NAME_REAL(fft_plan)* p_before; 17 | LTFAT_NAME_REAL(ifft_plan)* p_after; 18 | LTFAT_NAME_REAL(fft_plan)* p_veryend; 19 | LTFAT_REAL* sbuf; 20 | const LTFAT_REAL* f; 21 | LTFAT_COMPLEX* gf; 22 | LTFAT_COMPLEX* cout; 23 | LTFAT_REAL* ff, *cf; 24 | }; 25 | 26 | struct LTFAT_NAME_COMPLEX(dgt_long_plan) 27 | { 28 | ltfat_int a; 29 | ltfat_int M; 30 | ltfat_int L; 31 | ltfat_int W; 32 | ltfat_int c; 33 | ltfat_int h_a; 34 | ltfat_phaseconvention ptype; 35 | LTFAT_NAME_REAL(fft_plan)* p_before; 36 | LTFAT_NAME_REAL(ifft_plan)* p_after; 37 | LTFAT_NAME_REAL(fft_plan)* p_veryend; 38 | LTFAT_REAL* sbuf; 39 | const LTFAT_COMPLEX* f; 40 | LTFAT_COMPLEX* gf; 41 | LTFAT_COMPLEX* cout; 42 | LTFAT_REAL* ff, *cf; 43 | }; 44 | 45 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/src/dgtreal_long_private.h: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/types.h" 3 | #include "ltfat/macros.h" 4 | 5 | #include "ltfat/thirdparty/fftw3.h" 6 | 7 | struct LTFAT_NAME(dgtreal_long_plan) 8 | { 9 | ltfat_int a; 10 | ltfat_int M; 11 | ltfat_int L; 12 | ltfat_int W; 13 | ltfat_int c; 14 | ltfat_int h_a; 15 | ltfat_phaseconvention ptype; 16 | LTFAT_NAME(fftreal_plan)* p_before; 17 | LTFAT_NAME(ifftreal_plan)* p_after; 18 | LTFAT_NAME(fftreal_plan)* p_veryend; 19 | LTFAT_REAL* sbuf; 20 | LTFAT_COMPLEX* cbuf; 21 | const LTFAT_REAL* f; 22 | LTFAT_COMPLEX* gf; 23 | LTFAT_REAL* cwork; 24 | LTFAT_COMPLEX* cout; 25 | LTFAT_REAL* ff, *cf; 26 | }; 27 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/src/dgtrealwrapper_private.h: -------------------------------------------------------------------------------- 1 | #ifndef _ltfat_dgtrealwrapper_private_h 2 | #define _ltfat_dgtrealwrapper_private_h 3 | #include "dgtwrapper_private.h" 4 | 5 | typedef int LTFAT_NAME(complextorealtransform)(void* userdata, const LTFAT_COMPLEX* c, ltfat_int L, ltfat_int W, LTFAT_REAL* f); 6 | typedef int LTFAT_NAME(realtocomplextransform)(void* userdata, const LTFAT_REAL* f, ltfat_int L, ltfat_int W, LTFAT_COMPLEX* c); 7 | 8 | struct LTFAT_NAME(dgtreal_plan) 9 | { 10 | ltfat_int L; 11 | ltfat_int W; 12 | ltfat_int a; 13 | ltfat_int M; 14 | LTFAT_REAL* f; 15 | LTFAT_COMPLEX* c; 16 | ltfat_phaseconvention ptype; 17 | LTFAT_NAME(complextorealtransform)* backtra; 18 | void* backtra_userdata; 19 | LTFAT_NAME(donefunc)* backdonefunc; 20 | LTFAT_NAME(realtocomplextransform)* fwdtra; 21 | void* fwdtra_userdata; 22 | LTFAT_NAME(donefunc)* fwddonefunc; 23 | }; 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/src/dgtwrapper_private.h: -------------------------------------------------------------------------------- 1 | #ifndef _ltfat_dgtwrapper_private_h 2 | #define _ltfat_dgtwrapper_private_h 3 | 4 | 5 | struct ltfat_dgt_params 6 | { 7 | ltfat_phaseconvention ptype; 8 | unsigned fftw_flags; 9 | ltfat_dgt_hint hint; 10 | int do_synoverwrites; 11 | }; 12 | 13 | typedef int LTFAT_NAME(donefunc)(void** pla); 14 | 15 | typedef int LTFAT_NAME(complextocomplextransform)(void* userdata, const LTFAT_COMPLEX* c, ltfat_int L, ltfat_int W, LTFAT_COMPLEX* f); 16 | typedef int LTFAT_NAME(typetocomplextransform)(void* userdata, const LTFAT_TYPE* f, ltfat_int L, ltfat_int W, LTFAT_COMPLEX* c); 17 | 18 | struct LTFAT_NAME(dgt_plan) 19 | { 20 | ltfat_int L; 21 | ltfat_int W; 22 | ltfat_int a; 23 | ltfat_int M; 24 | LTFAT_COMPLEX* f; 25 | LTFAT_COMPLEX* c; 26 | ltfat_phaseconvention ptype; 27 | LTFAT_NAME(complextocomplextransform)* backtra; 28 | void* backtra_userdata; 29 | LTFAT_NAME(donefunc)* backdonefunc; 30 | LTFAT_NAME(typetocomplextransform)* fwdtra; 31 | void* fwdtra_userdata; 32 | LTFAT_NAME(donefunc)* fwddonefunc; 33 | }; 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/src/error.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/errno.h" 3 | #include "ltfat/macros.h" 4 | #include "stdarg.h" 5 | 6 | /* Global custom error handler */ 7 | ltfat_error_handler_t* ltfat_error_handler = NULL; 8 | 9 | static void 10 | no_error_handler ( int UNUSED(ltfat_errno), const char* UNUSED(file), 11 | int UNUSED(line), const char* UNUSED(funcname), 12 | const char* UNUSED(reason) ) {} 13 | 14 | LTFAT_API void 15 | ltfat_error (int ltfat_errno, const char* file, int line, 16 | const char* funcname, const char* format, ...) 17 | { 18 | // Shortcut when no_error_handler is used 19 | if (ltfat_error_handler && ltfat_error_handler == no_error_handler ) 20 | return; 21 | 22 | // Print to a string 23 | char reason[500] = {0}; 24 | 25 | va_list ap; 26 | va_start (ap, format); 27 | vsnprintf(reason, 500, format, ap ); 28 | va_end(ap); 29 | 30 | // Call the registered error handler or do the default behavior 31 | if (ltfat_error_handler) 32 | { 33 | (*ltfat_error_handler) (ltfat_errno, file, line, funcname, reason ); 34 | } 35 | else 36 | { 37 | fprintf (stderr, "[ERROR %d]: (%s:%d): [%s]: %s\n", -ltfat_errno, file, line, 38 | funcname, reason); 39 | 40 | fflush (stderr); 41 | } 42 | } 43 | 44 | LTFAT_API ltfat_error_handler_t* 45 | ltfat_set_error_handler (ltfat_error_handler_t* new_handler) 46 | { 47 | ltfat_error_handler_t* previous_handler = ltfat_error_handler; 48 | ltfat_error_handler = new_handler; 49 | return previous_handler; 50 | } 51 | 52 | LTFAT_API ltfat_error_handler_t* 53 | ltfat_set_error_handler_off (void) 54 | { 55 | ltfat_error_handler_t* previous_handler = ltfat_error_handler; 56 | ltfat_error_handler = no_error_handler; 57 | return previous_handler; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/src/filedefs.mk: -------------------------------------------------------------------------------- 1 | files = dgt.c dgtreal_fb.c dgt_multi.c dgt_ola.c dgt_shear.c \ 2 | dgtreal_long.c dwilt.c idwilt.c wmdct.c iwmdct.c \ 3 | filterbank.c ifilterbank.c heapint.c heap.c wfacreal.c \ 4 | idgtreal_long.c idgtreal_fb.c iwfacreal.c pfilt.c reassign_ti.c \ 5 | windows.c \ 6 | dgt_shearola.c utils.c rtdgtreal.c circularbuf.c slicingbuf.c \ 7 | dgtrealwrapper.c dgtrealmp.c dgtrealmp_parbuf.c dgtrealmp_kernel.c dgtrealmp_guts.c maxtree.c \ 8 | slidgtrealmp.c 9 | 10 | files_complextransp =\ 11 | ci_utils.c ci_windows.c spread.c wavelets.c goertzel.c \ 12 | reassign.c gabdual_painless.c wfac.c iwfac.c \ 13 | dgt_long.c idgt_long.c dgt_fb.c idgt_fb.c ci_memalloc.c \ 14 | dgtwrapper.c 15 | 16 | files_blaslapack = ltfat_blaslapack.c gabdual_fac.c gabtight_fac.c 17 | 18 | files_blaslapack_complextransp = gabdual.c gabtight.c 19 | 20 | files_fftw_complextransp = dct.c dst.c 21 | 22 | files_notypechange = memalloc.c error.c version.c argchecks.c \ 23 | dgtwrapper_typeconstant.c dgtrealmp_typeconstant.c \ 24 | reassign_typeconstant.c wavelets_typeconstant.c \ 25 | integer_manip.c firwin_typeconstant.c 26 | 27 | FFTBACKEND ?= FFTW 28 | 29 | ifneq ($(FFTBACKEND),FFTW) 30 | ifneq ($(FFTBACKEND),KISS) 31 | $(error FFTBACKEND must be either FFTW or KISS) 32 | endif 33 | endif 34 | 35 | ifeq ($(FFTBACKEND),FFTW) 36 | files += fftw_wrappers.c 37 | files_complextransp += $(files_fftw_complextransp) 38 | LFLAGS+= $(FFTWLIBS) 39 | CFLAGS+=-DFFTW 40 | endif 41 | 42 | ifeq ($(FFTBACKEND),KISS) 43 | files += kissfft_wrappers.c kiss_fft.c 44 | CFLAGS+=-DKISS 45 | endif 46 | 47 | ifndef NOBLASLAPACK 48 | files += $(files_blaslapack) 49 | files_complextransp += $(files_blaslapack_complextransp) 50 | LFLAGS+=$(BLASLAPACKLIBS) 51 | endif 52 | 53 | extradepincludes:=\#include \n 54 | 55 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/src/firwin_typeconstant.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/macros.h" 3 | 4 | LTFAT_API int 5 | ltfat_str2firwin(const char* win) 6 | { 7 | if( !strcmp("hann",win) || !strcmp("hanning",win) || !strcmp("nuttall10",win)) 8 | return LTFAT_HANN; 9 | if( !strcmp("hamming",win)) return LTFAT_HAMMING; 10 | else if( !strcmp("sqrthann",win) || !strcmp("cosine",win) || !strcmp("sine",win)) 11 | return LTFAT_SQRTHANN; 12 | else if( !strcmp("nuttall01",win)) return LTFAT_NUTTALL01; 13 | else if( !strcmp("square",win) || !strcmp("rect",win)) return LTFAT_SQUARE; 14 | else if( !strcmp("tria",win) || !strcmp("triangular",win) || !strcmp("bartlett",win)) 15 | return LTFAT_TRIA; 16 | else if( !strcmp("sqrttria",win)) return LTFAT_SQRTTRIA; 17 | else if( !strcmp("blackman",win)) return LTFAT_BLACKMAN; 18 | else if( !strcmp("blackman2",win)) return LTFAT_BLACKMAN2; 19 | else if( !strcmp("nuttall",win) || !strcmp("nuttall12",win)) return LTFAT_NUTTALL; 20 | else if( !strcmp("ogg",win) || !strcmp("itersine",win)) return LTFAT_OGG; 21 | else if( !strcmp("nuttall20",win)) return LTFAT_NUTTALL20; 22 | else if( !strcmp("nuttall11",win)) return LTFAT_NUTTALL11; 23 | else if( !strcmp("nuttall02",win)) return LTFAT_NUTTALL02; 24 | else if( !strcmp("nuttall30",win)) return LTFAT_NUTTALL30; 25 | else if( !strcmp("nuttall21",win)) return LTFAT_NUTTALL21; 26 | else if( !strcmp("nuttall03",win)) return LTFAT_NUTTALL03; 27 | else if( !strcmp("truncgauss01",win)) return LTFAT_TRUNCGAUSS01; 28 | else if( !strcmp("truncgauss005",win)) return LTFAT_TRUNCGAUSS005; 29 | 30 | return LTFATERR_BADARG; 31 | } 32 | 33 | LTFAT_API ltfat_int 34 | ltfat_mtgausslength(ltfat_int a, ltfat_int M, double thr) 35 | { 36 | int status = LTFATERR_FAILED; 37 | CHECK(LTFATERR_NOTPOSARG, a > 0, "a must be greater than 0 (passed %td)", a); 38 | CHECK(LTFATERR_NOTPOSARG, M > 0, "M must be greater than 0 (passed %td)", M); 39 | CHECK(LTFATERR_NOTPOSARG, thr > 0 && thr <= 1.0, "Thr must be in the range ]0,1]"); 40 | 41 | return 2*(ltfat_int) ltfat_round(sqrt(-a*M*log(thr)/M_PI)); 42 | error: 43 | return status; 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/src/reassign_ti.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/types.h" 3 | #include "ltfat/macros.h" 4 | 5 | 6 | 7 | LTFAT_API void 8 | LTFAT_NAME(filterbankphasegrad)(const LTFAT_COMPLEX* c [], 9 | const LTFAT_COMPLEX* ch[], 10 | const LTFAT_COMPLEX* cd[], 11 | ltfat_int M, 12 | ltfat_int N[], 13 | ltfat_int L, 14 | const LTFAT_REAL minlvl, 15 | LTFAT_REAL* tgrad[], 16 | LTFAT_REAL* fgrad[], 17 | LTFAT_REAL* cs[]) 18 | { 19 | #define FOREACHCOEF \ 20 | for(ltfat_int m=0;m minlvlAlt) 34 | minlvlAlt = en; 35 | ENDFOREACHCOEF 36 | 37 | // Adjust minlvl 38 | minlvlAlt *= minlvl; 39 | 40 | // Force spectrogram values less tha minLvlAlt to minlvlAlt 41 | FOREACHCOEF 42 | LTFAT_REAL csEl = ARRAYEL(cs); 43 | if (csEl < minlvlAlt) 44 | ARRAYEL(cs) = minlvlAlt; 45 | ENDFOREACHCOEF 46 | 47 | // Instantaneous frequency 48 | FOREACHCOEF 49 | LTFAT_REAL tgradEl = ltfat_real( ARRAYEL(cd) * conj(ARRAYEL(c)) / ARRAYEL(cs) 50 | ) / L * 2; 51 | ARRAYEL(tgrad) = fabs(tgradEl) <= 2 ? tgradEl : 0.0f; 52 | ENDFOREACHCOEF 53 | 54 | 55 | FOREACHCOEF 56 | ARRAYEL(fgrad) = ltfat_imag( ARRAYEL(ch) * conj(ARRAYEL(c)) / ARRAYEL(cs)); 57 | ENDFOREACHCOEF 58 | 59 | #undef FOREACHCOEF 60 | #undef ENDFOREACHCOEF 61 | #undef ARRAYEL 62 | } 63 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/src/reassign_typeconstant.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/macros.h" 3 | 4 | LTFAT_API fbreassOptOut* 5 | fbreassOptOut_init(ltfat_int l, ltfat_int inital) 6 | { 7 | fbreassOptOut* ret = (fbreassOptOut*) ltfat_calloc( 1, sizeof * ret); 8 | ret->l = l; 9 | // This is an array of pointers. 10 | ret->repos = (ltfat_int**) ltfat_malloc(l * sizeof * ret->repos); 11 | ret->reposl = (ltfat_int*) ltfat_calloc(l , sizeof * ret->reposl); 12 | ret->reposlmax = (ltfat_int*) ltfat_malloc(l * sizeof * ret->reposlmax); 13 | ltfat_int inital2 = ltfat_imax(1, inital); 14 | for (ltfat_int ii = 0; ii < l; ii++) 15 | { 16 | ret->repos[ii] = (ltfat_int*) ltfat_malloc( inital2 * sizeof * ret->repos[ii]); 17 | ret->reposlmax[ii] = inital2; 18 | } 19 | 20 | return ret; 21 | } 22 | 23 | LTFAT_API void 24 | fbreassOptOut_destroy(fbreassOptOut* oo) 25 | { 26 | 27 | for (ltfat_int ii = 0; ii < oo->l; ii++) 28 | { 29 | if (oo->repos[ii] && oo->reposlmax[ii] > 0) 30 | { 31 | ltfat_free(oo->repos[ii]); 32 | } 33 | } 34 | 35 | LTFAT_SAFEFREEALL(oo->repos, oo->reposl, oo->reposlmax, oo); 36 | oo = NULL; 37 | } 38 | 39 | LTFAT_API void 40 | fbreassOptOut_expand(fbreassOptOut* oo, ltfat_int ii) 41 | { 42 | ltfat_int explmax = (ltfat_int) (fbreassOptOut_EXPANDRAT * oo->reposlmax[ii]); 43 | oo->repos[ii] = (ltfat_int*) ltfat_realloc( (void*) oo->repos[ii], 44 | oo->reposlmax[ii] * sizeof * oo->repos[ii], 45 | explmax * sizeof * oo->repos[ii]); 46 | oo->reposlmax[ii] = explmax; 47 | } 48 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/src/slicingbuf_private.h: -------------------------------------------------------------------------------- 1 | struct LTFAT_NAME(slicing_processor_state) 2 | { 3 | LTFAT_NAME(slicing_processor_callback)* 4 | processorCallback; //!< Custom processor callback 5 | void* userdata; //!< Callback data 6 | LTFAT_NAME(block_processor_state)* block_processor; 7 | LTFAT_REAL* bufIn; 8 | LTFAT_REAL* bufOut; 9 | LTFAT_REAL* bufIn_start; 10 | LTFAT_REAL* bufOut_start; 11 | ltfat_int winLen; 12 | ltfat_int taperLen; 13 | ltfat_int zpadLen; 14 | LTFAT_REAL* ga; 15 | LTFAT_REAL* gs; 16 | 17 | }; 18 | 19 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/src/slidgtrealmp_private.h: -------------------------------------------------------------------------------- 1 | #ifndef _LTFAT_SLIDGTREALMP_PRIVATE_H 2 | #define _LTFAT_SLIDGTREALMP_PRIVATE_H 3 | 4 | 5 | #endif 6 | 7 | struct LTFAT_NAME(slidgtrealmp_state) 8 | { 9 | LTFAT_NAME(dgtrealmp_state)* mpstate; 10 | int owning_mpstate; 11 | LTFAT_NAME(slicing_processor_state)* slistate; 12 | int owning_slistate; 13 | LTFAT_COMPLEX** couttmp; 14 | ltfat_int P; 15 | void* userdata; 16 | LTFAT_NAME(slidgtrealmp_processor_callback)* callback; 17 | }; 18 | 19 | 20 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/src/spread.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/types.h" 3 | #include "ltfat/macros.h" 4 | 5 | LTFAT_API void 6 | LTFAT_NAME(col2diag)(const LTFAT_TYPE *cin, ltfat_int L, 7 | LTFAT_TYPE *cout) 8 | { 9 | ltfat_int ii; 10 | 11 | LTFAT_TYPE *pcout; 12 | const LTFAT_TYPE *pcin; 13 | 14 | pcout=cout; 15 | ltfat_int Lp1=L+1; 16 | for (ltfat_int jj=0; jjmajor == your_major); 28 | } 29 | 30 | LTFAT_API int 31 | ltfat_int_size() 32 | { 33 | return sizeof(ltfat_int); 34 | } 35 | 36 | LTFAT_API int 37 | ltfat_int_is_compatible(int sizeofyourint) 38 | { 39 | return ltfat_int_size() == sizeofyourint; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/src/wavelets_typeconstant.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | 3 | LTFAT_API ltfatExtType 4 | ltfatExtStringToEnum(const char* extType) 5 | { 6 | if (strcmp(extType, "per") == 0) 7 | { 8 | return PER; 9 | } 10 | else if (strcmp(extType, "perdec") == 0) 11 | { 12 | return PERDEC; 13 | } 14 | else if (strcmp(extType, "ppd") == 0) 15 | { 16 | return PPD; 17 | } 18 | else if (strcmp(extType, "sym") == 0) 19 | { 20 | return SYM; 21 | } 22 | else if (strcmp(extType, "even") == 0) 23 | { 24 | return EVEN; 25 | } 26 | else if (strcmp(extType, "symw") == 0) 27 | { 28 | return SYMW; 29 | } 30 | else if (strcmp(extType, "odd") == 0) 31 | { 32 | return ODD; 33 | } 34 | else if (strcmp(extType, "asymw") == 0) 35 | { 36 | return ASYMW; 37 | } 38 | else if (strcmp(extType, "sp0") == 0) 39 | { 40 | return SP0; 41 | } 42 | else if (strcmp(extType, "zpd") == 0) 43 | { 44 | return ZPD; 45 | } 46 | else if (strcmp(extType, "zero") == 0) 47 | { 48 | return ZERO; 49 | } 50 | else if (strcmp(extType, "valid") == 0) 51 | { 52 | return VALID; 53 | } 54 | else 55 | { 56 | return BAD_TYPE; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/Makefile: -------------------------------------------------------------------------------- 1 | CFILES = $(shell ls test_*.c) 2 | 3 | run_all: test_all_libltfat 4 | LD_LIBRARY_PATH=../../build ./test_all_libltfat 5 | 6 | test_all_libltfat: Makefile ../../build/libltfat.so $(CFILES) 7 | $(CC) -Wall -Wextra -pedantic -std=gnu99 -O0 -g -I../../include -I../../thirdparty test_all_libltfat.c -o test_all_libltfat -L../../build -lltfat -lfftw3 -lfftw3f -lm 8 | 9 | mem: test_all_libltfat 10 | LD_LIBRARY_PATH=../../build valgrind --leak-check=yes ./test_all_libltfat 11 | 12 | clean: 13 | -rm -f *.o 14 | find . -type f -executable -exec sh -c "file -i '{}' | grep -q 'x-executable; charset=binary'" \; -print | xargs rm -f 15 | 16 | test_%: test_%.c Makefile 17 | $(shell truncate -s 0 runner_test_typecomplexindependent.c) 18 | $(shell truncate -s 0 runner_test_typeindependent.c) 19 | $(shell echo 'int TEST_NAME($@)(){' >> runner_test_typeindependent.c) 20 | $(shell echo '#include "$<"' >> runner_test_typeindependent.c) 21 | $(shell echo 'return 0;}' >> runner_test_typeindependent.c) 22 | $(shell sed 's/%FUNCTIONNAME%/$@/g' runner_template.c > runner.c) 23 | $(CC) -Wall -Wextra -pedantic -std=c99 -O0 -g -I../../include -I../../thirdparty runner.c -o $@ -L../../build -lltfat -lfftw3 -lfftw3f -lm 24 | LD_LIBRARY_PATH=../../build ./$@ 25 | -rm -f ./$@ 26 | 27 | .PHONY: run_all 28 | 29 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/README: -------------------------------------------------------------------------------- 1 | The structure 2 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/multiinclude.h: -------------------------------------------------------------------------------- 1 | #define LTFAT_DOUBLE 2 | #include "ltfat/types.h" 3 | #define TEST_NAME(name) name##_d 4 | #define TEST_NAME_COMPLEX(name) name##_dc 5 | 6 | #include "test_typecomplexindependent.c" 7 | #include "test_typeindependent.c" 8 | 9 | #undef TEST_NAME 10 | #undef TEST_NAME_COMPLEX 11 | #undef LTFAT_DOUBLE 12 | 13 | #define LTFAT_SINGLE 14 | #include "ltfat/types.h" 15 | #define TEST_NAME(name) name##_s 16 | #define TEST_NAME_COMPLEX(name) name##_sc 17 | 18 | #include "test_typecomplexindependent.c" 19 | #include "test_typeindependent.c" 20 | 21 | 22 | #undef TEST_NAME 23 | #undef TEST_NAME_COMPLEX 24 | #undef LTFAT_SINGLE 25 | 26 | #define LTFAT_COMPLEXTYPE 27 | 28 | #define LTFAT_DOUBLE 29 | #include "ltfat/types.h" 30 | #define TEST_NAME(name) name##_dc 31 | #define TEST_NAME_COMPLEX(name) name##_dc 32 | 33 | #include "test_typecomplexindependent.c" 34 | 35 | #undef TEST_NAME 36 | #undef TEST_NAME_COMPLEX 37 | #undef LTFAT_DOUBLE 38 | 39 | #define LTFAT_SINGLE 40 | #include "ltfat/types.h" 41 | #define TEST_NAME(name) name##_sc 42 | #define TEST_NAME_COMPLEX(name) name##_sc 43 | 44 | 45 | #include "test_typecomplexindependent.c" 46 | 47 | #undef TEST_NAME 48 | #undef TEST_NAME_COMPLEX 49 | #undef LTFAT_SINGLE 50 | #undef LTFAT_COMPLEXTYPE 51 | 52 | // Unsets all the macros 53 | #include "ltfat/types.h" 54 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/runner_multiinclude.h: -------------------------------------------------------------------------------- 1 | #define LTFAT_DOUBLE 2 | #include "ltfat/types.h" 3 | #define TEST_NAME(name) name##_d 4 | #define TEST_NAME_COMPLEX(name) name##_dc 5 | 6 | #include "runner_test_typecomplexindependent.c" 7 | #include "runner_test_typeindependent.c" 8 | 9 | #undef TEST_NAME 10 | #undef TEST_NAME_COMPLEX 11 | #undef LTFAT_DOUBLE 12 | 13 | #define LTFAT_SINGLE 14 | #include "ltfat/types.h" 15 | #define TEST_NAME(name) name##_s 16 | #define TEST_NAME_COMPLEX(name) name##_sc 17 | 18 | #include "runner_test_typecomplexindependent.c" 19 | #include "runner_test_typeindependent.c" 20 | 21 | 22 | #undef TEST_NAME 23 | #undef TEST_NAME_COMPLEX 24 | #undef LTFAT_SINGLE 25 | 26 | #define LTFAT_COMPLEXTYPE 27 | 28 | #define LTFAT_DOUBLE 29 | #include "ltfat/types.h" 30 | #define TEST_NAME(name) name##_dc 31 | #define TEST_NAME_COMPLEX(name) name##_dc 32 | 33 | #include "runner_test_typecomplexindependent.c" 34 | 35 | #undef TEST_NAME 36 | #undef TEST_NAME_COMPLEX 37 | #undef LTFAT_DOUBLE 38 | 39 | #define LTFAT_SINGLE 40 | #include "ltfat/types.h" 41 | #define TEST_NAME(name) name##_sc 42 | #define TEST_NAME_COMPLEX(name) name##_sc 43 | 44 | 45 | #include "runner_test_typecomplexindependent.c" 46 | 47 | #undef TEST_NAME 48 | #undef TEST_NAME_COMPLEX 49 | #undef LTFAT_SINGLE 50 | #undef LTFAT_COMPLEXTYPE 51 | 52 | // Unsets all the macros 53 | #include "ltfat/types.h" 54 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/runner_template.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/errno.h" 3 | #include "ltfat/macros.h" 4 | #include "minunit.h" 5 | #include "runner_multiinclude.h" 6 | 7 | void all_tests() 8 | { 9 | mu_suite_start(); 10 | 11 | mu_run_test_singledouble(%FUNCTIONNAME%); 12 | 13 | mu_suite_stop(); 14 | } 15 | 16 | 17 | int main() 18 | { 19 | all_tests(); 20 | 21 | 22 | if (ft.noOfFailedTests > 0) 23 | { 24 | printf("\n----------------\nFAILED TESTS %d: \n\n", ft.noOfFailedTests); 25 | for (int ii = 0; ii < ft.noOfFailedTests; ii++) { printf(" %s\n", ft.failedTests[ii]); } 26 | ltfat_free(ft.failedTests); 27 | } 28 | else 29 | { 30 | printf("\n----------------\nALL TESTS PASSED\n"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/test_all_libltfat.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/errno.h" 3 | #include "ltfat/macros.h" 4 | #include "minunit.h" 5 | 6 | 7 | void all_tests() 8 | { 9 | mu_suite_start(); 10 | 11 | mu_run_test_singledoublecomplex(test_circshift); 12 | mu_run_test_singledoublecomplex(test_fftshift); 13 | mu_run_test_singledoublecomplex(test_ifftshift); 14 | mu_run_test_singledoublecomplex(test_fir2long); 15 | mu_run_test_singledoublecomplex(test_long2fir); 16 | mu_run_test_singledoublecomplex(test_normalize); 17 | mu_run_test_singledoublecomplex(test_firwin); 18 | mu_run_test_singledoublecomplex(test_gabdual_painless); 19 | mu_run_test_singledoublecomplex(test_gabdual_long); 20 | mu_run_test_singledoublecomplex(test_dgt_fb); 21 | mu_run_test_singledoublecomplex(test_idgt_fb); 22 | mu_run_test_singledoublecomplex(test_dgt_long); 23 | mu_run_test_singledoublecomplex(test_idgt_long); 24 | mu_run_test_singledouble(test_dgtreal_fb); 25 | mu_run_test_singledouble(test_idgtreal_fb); 26 | mu_run_test_singledouble(test_dgtreal_long); 27 | mu_run_test_singledouble(test_idgtreal_long); 28 | mu_run_test_singledouble(test_pgauss); 29 | mu_run_test_singledouble(test_fftcircshift); 30 | mu_run_test_singledouble(test_fftfftshift); 31 | mu_run_test_singledouble(test_fftifftshift); 32 | mu_run_test_singledouble(test_fftrealcircshift); 33 | mu_run_test_singledouble(test_fftrealfftshift); 34 | mu_run_test_singledouble(test_fftrealifftshift); 35 | 36 | mu_suite_stop(); 37 | } 38 | 39 | 40 | int main() 41 | { 42 | all_tests(); 43 | 44 | 45 | if (ft.noOfFailedTests > 0) 46 | { 47 | printf("\n----------------\nFAILED TESTS %d: \n\n", ft.noOfFailedTests); 48 | for (int ii = 0; ii < ft.noOfFailedTests; ii++) { printf(" %s\n", ft.failedTests[ii]); } 49 | ltfat_free(ft.failedTests); 50 | } 51 | else 52 | { 53 | printf("\n----------------\nALL TESTS PASSED\n"); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/test_circshift.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_circshift)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | ltfatInt shift[] = { -5, 0, 1, -1000, 10540, 5660}; 5 | 6 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 7 | { 8 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[lId]); 9 | TEST_NAME(fillRand)(fin, L[lId]); 10 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(L[lId]); 11 | TEST_NAME(fillRand)(fout, L[lId]); 12 | 13 | for (unsigned int shiftId = 0; shiftId < ARRAYLEN(shift); shiftId++) 14 | { 15 | mu_assert( LTFAT_NAME(circshift)(fin, L[lId], shift[shiftId], fout) == 0, 16 | "circshift"); 17 | mu_assert( LTFAT_NAME(circshift)(fin, L[lId], shift[shiftId], fin) == 0, 18 | "circshift inplace"); 19 | } 20 | ltfat_free(fin); 21 | ltfat_free(fout); 22 | } 23 | 24 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[0]); 25 | TEST_NAME(fillRand)(fin, L[0]); 26 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(L[0]); 27 | TEST_NAME(fillRand)(fout, L[0]); 28 | 29 | 30 | // Inputs can be checked only once 31 | mu_assert( LTFAT_NAME(circshift)(NULL, L[0], shift[0], fin) == LTFATERR_NULLPOINTER, 32 | "First is null"); 33 | mu_assert( LTFAT_NAME(circshift)(fin, L[0], shift[0], NULL) == LTFATERR_NULLPOINTER, 34 | "Last is null"); 35 | mu_assert( LTFAT_NAME(circshift)(fin, 0, shift[0], fout) == LTFATERR_BADSIZE, 36 | "Zero length"); 37 | mu_assert( LTFAT_NAME(circshift)(fin, -1, shift[0], fout) == LTFATERR_BADSIZE, 38 | "Negative length"); 39 | 40 | mu_assert( LTFAT_NAME(circshift)(NULL, -1, shift[0], fout) < LTFATERR_SUCCESS, 41 | "Multiple wrong inputs"); 42 | 43 | 44 | ltfat_free(fin); 45 | ltfat_free(fout); 46 | return 0; 47 | } 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/test_fftcircshift.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_fftcircshift)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | ltfatInt shift[] = { -5, 0, 1, -1000, 10540, 5660}; 5 | 6 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 7 | { 8 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 9 | TEST_NAME_COMPLEX(fillRand)(fin, L[lId]); 10 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 11 | TEST_NAME_COMPLEX(fillRand)(fout, L[lId]); 12 | 13 | for (unsigned int shiftId = 0; shiftId < ARRAYLEN(shift); shiftId++) 14 | { 15 | mu_assert( LTFAT_NAME_COMPLEX(fftcircshift)(fin, L[lId], shift[shiftId], 16 | fout) == 0, 17 | "fftcirschift"); 18 | mu_assert( LTFAT_NAME_COMPLEX(fftcircshift)(fin, L[lId], shift[shiftId], 19 | fin) == 0, 20 | "fftcirschift inplace"); 21 | } 22 | 23 | ltfat_free(fin); 24 | ltfat_free(fout); 25 | } 26 | 27 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[0]); 28 | TEST_NAME_COMPLEX(fillRand)(fin, L[0]); 29 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[0]); 30 | TEST_NAME_COMPLEX(fillRand)(fout, L[0]); 31 | 32 | 33 | // Inputs can be checked only once 34 | mu_assert( LTFAT_NAME_COMPLEX(fftcircshift)(NULL, L[0], shift[0], 35 | fin) == LTFATERR_NULLPOINTER, 36 | "First is null"); 37 | mu_assert( LTFAT_NAME_COMPLEX(fftcircshift)(fin, L[0], shift[0], 38 | NULL) == LTFATERR_NULLPOINTER, 39 | "Last is null"); 40 | mu_assert( LTFAT_NAME_COMPLEX(fftcircshift)(fin, 0, shift[0], 41 | fout) == LTFATERR_BADSIZE, 42 | "Zero length"); 43 | mu_assert( LTFAT_NAME_COMPLEX(fftcircshift)(fin, -1, shift[0], 44 | fout) == LTFATERR_BADSIZE, 45 | "Negative length"); 46 | 47 | mu_assert( LTFAT_NAME_COMPLEX(fftcircshift)(NULL, -1, shift[0], 48 | fout) < LTFATERR_SUCCESS, 49 | "Multiple wrong inputs"); 50 | 51 | 52 | ltfat_free(fin); 53 | ltfat_free(fout); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/test_fftfftshift.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_fftfftshift)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | 5 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 6 | { 7 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 8 | TEST_NAME_COMPLEX(fillRand)(fin, L[lId]); 9 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 10 | TEST_NAME_COMPLEX(fillRand)(fout, L[lId]); 11 | 12 | mu_assert( LTFAT_NAME_COMPLEX(fftfftshift)(fin, L[lId], fout) == 0, 13 | "fftfftshift"); 14 | mu_assert( LTFAT_NAME_COMPLEX(fftfftshift)(fin, L[lId], fin) == 0, 15 | "fftfftshift inplace"); 16 | 17 | ltfat_free(fin); 18 | ltfat_free(fout); 19 | } 20 | 21 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[0]); 22 | TEST_NAME_COMPLEX(fillRand)(fin, L[0]); 23 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[0]); 24 | TEST_NAME_COMPLEX(fillRand)(fout, L[0]); 25 | 26 | 27 | // Inputs can be checked only once 28 | mu_assert( LTFAT_NAME_COMPLEX(fftfftshift)(NULL, L[0], 29 | fin) == LTFATERR_NULLPOINTER, "First is null"); 30 | mu_assert( LTFAT_NAME_COMPLEX(fftfftshift)(fin, L[0], 31 | NULL) == LTFATERR_NULLPOINTER, "Last is null"); 32 | mu_assert( LTFAT_NAME_COMPLEX(fftfftshift)(fin, 0, fout) == LTFATERR_BADSIZE, 33 | "Zero length"); 34 | mu_assert( LTFAT_NAME_COMPLEX(fftfftshift)(fin, -1, fout) == LTFATERR_BADSIZE, 35 | "Negative length"); 36 | mu_assert( LTFAT_NAME_COMPLEX(fftfftshift)(NULL, -1, fout) < LTFATERR_SUCCESS, 37 | "Multiple wrong inputs"); 38 | 39 | 40 | ltfat_free(fin); 41 | ltfat_free(fout); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/test_fftifftshift.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_fftifftshift)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | 5 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 6 | { 7 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 8 | TEST_NAME_COMPLEX(fillRand)(fin, L[lId]); 9 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 10 | TEST_NAME_COMPLEX(fillRand)(fout, L[lId]); 11 | 12 | mu_assert( LTFAT_NAME_COMPLEX(fftifftshift)(fin, L[lId], fout) == 0, 13 | "fftifftshift"); 14 | mu_assert( LTFAT_NAME_COMPLEX(fftifftshift)(fin, L[lId], fin) == 0, 15 | "fftifftshift inplace"); 16 | 17 | ltfat_free(fin); 18 | ltfat_free(fout); 19 | } 20 | 21 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[0]); 22 | TEST_NAME_COMPLEX(fillRand)(fin, L[0]); 23 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[0]); 24 | TEST_NAME_COMPLEX(fillRand)(fout, L[0]); 25 | 26 | 27 | // Inputs can be checked only once 28 | mu_assert( LTFAT_NAME_COMPLEX(fftifftshift)(NULL, L[0], 29 | fin) == LTFATERR_NULLPOINTER, "First is null"); 30 | mu_assert( LTFAT_NAME_COMPLEX(fftifftshift)(fin, L[0], 31 | NULL) == LTFATERR_NULLPOINTER, "Last is null"); 32 | mu_assert( LTFAT_NAME_COMPLEX(fftifftshift)(fin, 0, fout) == LTFATERR_BADSIZE, 33 | "Zero length"); 34 | mu_assert( LTFAT_NAME_COMPLEX(fftifftshift)(fin, -1, fout) == LTFATERR_BADSIZE, 35 | "Negative length"); 36 | mu_assert( LTFAT_NAME_COMPLEX(fftifftshift)(NULL, -1, fout) < LTFATERR_SUCCESS, 37 | "Multiple wrong inputs"); 38 | 39 | 40 | ltfat_free(fin); 41 | ltfat_free(fout); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/test_fftrealcircshift.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_fftrealcircshift)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | ltfatInt shift[] = { -5, 0, 1, -1000, 10540, 5660}; 5 | 6 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 7 | { 8 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 9 | TEST_NAME_COMPLEX(fillRand)(fin, L[lId]); 10 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 11 | TEST_NAME_COMPLEX(fillRand)(fout, L[lId]); 12 | 13 | for (unsigned int shiftId = 0; shiftId < ARRAYLEN(shift); shiftId++) 14 | { 15 | mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(fin, L[lId], shift[shiftId], 16 | fout) == 0, 17 | "fftrealcirschift"); 18 | mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(fin, L[lId], shift[shiftId], 19 | fin) == 0, 20 | "fftrealcirschift inplace"); 21 | } 22 | 23 | ltfat_free(fin); 24 | ltfat_free(fout); 25 | } 26 | 27 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[0]); 28 | TEST_NAME_COMPLEX(fillRand)(fin, L[0]); 29 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[0]); 30 | TEST_NAME_COMPLEX(fillRand)(fout, L[0]); 31 | 32 | 33 | // Inputs can be checked only once 34 | mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(NULL, L[0], shift[0], 35 | fin) == LTFATERR_NULLPOINTER, 36 | "First is null"); 37 | mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(fin, L[0], shift[0], 38 | NULL) == LTFATERR_NULLPOINTER, 39 | "Last is null"); 40 | mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(fin, 0, shift[0], 41 | fout) == LTFATERR_BADSIZE, 42 | "Zero length"); 43 | mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(fin, -1, shift[0], 44 | fout) == LTFATERR_BADSIZE, 45 | "Negative length"); 46 | 47 | mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(NULL, -1, shift[0], 48 | fout) < LTFATERR_SUCCESS, 49 | "Multiple wrong inputs"); 50 | 51 | 52 | ltfat_free(fin); 53 | ltfat_free(fout); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/test_fftrealfftshift.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_fftrealfftshift)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | 5 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 6 | { 7 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 8 | TEST_NAME_COMPLEX(fillRand)(fin, L[lId]); 9 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 10 | TEST_NAME_COMPLEX(fillRand)(fout, L[lId]); 11 | 12 | mu_assert( LTFAT_NAME_COMPLEX(fftrealfftshift)(fin, L[lId], fout) == 0, 13 | "fftrealfftshift"); 14 | mu_assert( LTFAT_NAME_COMPLEX(fftrealfftshift)(fin, L[lId], fin) == 0, 15 | "fftrealfftshift inplace"); 16 | 17 | ltfat_free(fin); 18 | ltfat_free(fout); 19 | } 20 | 21 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[0]); 22 | TEST_NAME_COMPLEX(fillRand)(fin, L[0]); 23 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[0]); 24 | TEST_NAME_COMPLEX(fillRand)(fout, L[0]); 25 | 26 | 27 | // Inputs can be checked only once 28 | mu_assert( LTFAT_NAME_COMPLEX(fftrealfftshift)(NULL, L[0], 29 | fin) == LTFATERR_NULLPOINTER, "First is null"); 30 | mu_assert( LTFAT_NAME_COMPLEX(fftrealfftshift)(fin, L[0], 31 | NULL) == LTFATERR_NULLPOINTER, "Last is null"); 32 | mu_assert( LTFAT_NAME_COMPLEX(fftrealfftshift)(fin, 0, fout) == LTFATERR_BADSIZE, 33 | "Zero length"); 34 | mu_assert( LTFAT_NAME_COMPLEX(fftrealfftshift)(fin, -1, fout) == LTFATERR_BADSIZE, 35 | "Negative length"); 36 | mu_assert( LTFAT_NAME_COMPLEX(fftrealfftshift)(NULL, -1, fout) < LTFATERR_SUCCESS, 37 | "Multiple wrong inputs"); 38 | 39 | 40 | ltfat_free(fin); 41 | ltfat_free(fout); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/test_fftrealifftshift.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_fftrealifftshift)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | 5 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 6 | { 7 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 8 | TEST_NAME_COMPLEX(fillRand)(fin, L[lId]); 9 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 10 | TEST_NAME_COMPLEX(fillRand)(fout, L[lId]); 11 | 12 | mu_assert( LTFAT_NAME_COMPLEX(fftrealifftshift)(fin, L[lId], fout) == 0, 13 | "fftrealifftshift"); 14 | mu_assert( LTFAT_NAME_COMPLEX(fftrealifftshift)(fin, L[lId], fin) == 0, 15 | "fftrealifftshift inplace"); 16 | 17 | ltfat_free(fin); 18 | ltfat_free(fout); 19 | } 20 | 21 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[0]); 22 | TEST_NAME_COMPLEX(fillRand)(fin, L[0]); 23 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[0]); 24 | TEST_NAME_COMPLEX(fillRand)(fout, L[0]); 25 | 26 | 27 | // Inputs can be checked only once 28 | mu_assert( LTFAT_NAME_COMPLEX(fftrealifftshift)(NULL, L[0], 29 | fin) == LTFATERR_NULLPOINTER, "First is null"); 30 | mu_assert( LTFAT_NAME_COMPLEX(fftrealifftshift)(fin, L[0], 31 | NULL) == LTFATERR_NULLPOINTER, "Last is null"); 32 | mu_assert( LTFAT_NAME_COMPLEX(fftrealifftshift)(fin, 0, fout) == LTFATERR_BADSIZE, 33 | "Zero length"); 34 | mu_assert( LTFAT_NAME_COMPLEX(fftrealifftshift)(fin, -1, fout) == LTFATERR_BADSIZE, 35 | "Negative length"); 36 | mu_assert( LTFAT_NAME_COMPLEX(fftrealifftshift)(NULL, -1, fout) < LTFATERR_SUCCESS, 37 | "Multiple wrong inputs"); 38 | 39 | 40 | ltfat_free(fin); 41 | ltfat_free(fout); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/test_fftshift.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_fftshift)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | 5 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 6 | { 7 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[lId]); 8 | TEST_NAME(fillRand)(fin, L[lId]); 9 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(L[lId]); 10 | TEST_NAME(fillRand)(fout, L[lId]); 11 | 12 | mu_assert( LTFAT_NAME(fftshift)(fin, L[lId], fout) == 0, 13 | "fftshift"); 14 | mu_assert( LTFAT_NAME(fftshift)(fin, L[lId], fin) == 0, 15 | "fftshift inplace"); 16 | 17 | ltfat_free(fin); 18 | ltfat_free(fout); 19 | } 20 | 21 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[0]); 22 | TEST_NAME(fillRand)(fin, L[0]); 23 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(L[0]); 24 | TEST_NAME(fillRand)(fout, L[0]); 25 | 26 | 27 | // Inputs can be checked only once 28 | mu_assert( LTFAT_NAME(fftshift)(NULL, L[0], fin) == LTFATERR_NULLPOINTER, 29 | "First is null"); 30 | mu_assert( LTFAT_NAME(fftshift)(fin, L[0], NULL) == LTFATERR_NULLPOINTER, 31 | "Last is null"); 32 | mu_assert( LTFAT_NAME(fftshift)(fin, 0, fout) == LTFATERR_BADSIZE, 33 | "Zero length"); 34 | mu_assert( LTFAT_NAME(fftshift)(fin, -1, fout) == LTFATERR_BADSIZE, 35 | "Negative length"); 36 | 37 | mu_assert( LTFAT_NAME(fftshift)(NULL, -1, fout) < LTFATERR_SUCCESS, 38 | "Multiple wrong inputs"); 39 | 40 | 41 | ltfat_free(fin); 42 | ltfat_free(fout); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/test_fir2long.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_fir2long)() 2 | { 3 | ltfatInt Lfir[] = {111, 1, 100}; 4 | ltfatInt Llong[] = {111, 2, 102}; 5 | 6 | for (unsigned int lId = 0; lId < ARRAYLEN(Lfir); lId++) 7 | { 8 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(Lfir[lId]); 9 | TEST_NAME(fillRand)(fin, Lfir[lId]); 10 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(Llong[lId]); 11 | TEST_NAME(fillRand)(fout, Llong[lId]); 12 | 13 | mu_assert( LTFAT_NAME(fir2long)(fin, Lfir[lId], Llong[lId], fout) == 0, 14 | "fir2long"); 15 | mu_assert( LTFAT_NAME(fir2long)(fout, Lfir[lId], Llong[lId], fout) == 0, 16 | "fir2long inplace"); 17 | 18 | ltfat_free(fin); 19 | ltfat_free(fout); 20 | } 21 | 22 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(Lfir[0]); 23 | TEST_NAME(fillRand)(fin, Lfir[0]); 24 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(Llong[0]); 25 | TEST_NAME(fillRand)(fout, Llong[0]); 26 | 27 | 28 | // Inputs can be checked only once 29 | mu_assert( LTFAT_NAME(fir2long)(NULL, Lfir[0], Llong[0], 30 | fin) == LTFATERR_NULLPOINTER, 31 | "First is null"); 32 | mu_assert( LTFAT_NAME(fir2long)(fin, Lfir[0], Llong[0], 33 | NULL) == LTFATERR_NULLPOINTER, 34 | "Last is null"); 35 | mu_assert( LTFAT_NAME(fir2long)(fin, 0, Llong[0], fout) == LTFATERR_BADSIZE, 36 | "Zero length"); 37 | mu_assert( LTFAT_NAME(fir2long)(fin, -1, Llong[0], fout) == LTFATERR_BADSIZE, 38 | "Negative length"); 39 | 40 | mu_assert( LTFAT_NAME(fir2long)(fin, 10, 9 , fout) == LTFATERR_BADREQSIZE, 41 | "Output shorter than input"); 42 | 43 | mu_assert( LTFAT_NAME(fir2long)(NULL, -1, Llong[0], fout) < LTFATERR_SUCCESS, 44 | "Multiple wrong inputs"); 45 | 46 | 47 | ltfat_free(fin); 48 | ltfat_free(fout); 49 | return 0; 50 | } 51 | 52 | 53 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/test_firwin.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_firwin)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | LTFAT_FIRWIN win[] = { LTFAT_HANN, LTFAT_HANNING, LTFAT_NUTTALL10, LTFAT_SQRTHANN, 5 | LTFAT_COSINE, LTFAT_SINE, LTFAT_HAMMING, LTFAT_NUTTALL01, 6 | LTFAT_SQUARE, LTFAT_RECT, LTFAT_TRIA, LTFAT_TRIANGULAR, 7 | LTFAT_BARTLETT, LTFAT_SQRTTRIA, LTFAT_BLACKMAN, LTFAT_BLACKMAN2, 8 | LTFAT_NUTTALL, LTFAT_NUTTALL12, LTFAT_OGG, LTFAT_ITERSINE, 9 | LTFAT_NUTTALL20, LTFAT_NUTTALL11, LTFAT_NUTTALL02, LTFAT_NUTTALL30, 10 | LTFAT_NUTTALL21, LTFAT_NUTTALL03 11 | }; 12 | 13 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 14 | { 15 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[lId]); 16 | TEST_NAME(fillRand)(fin, L[lId]); 17 | 18 | 19 | for (unsigned int nId = 0; nId < ARRAYLEN(win); nId++) 20 | { 21 | mu_assert( LTFAT_NAME(firwin)( win[nId], L[lId], fin) == LTFATERR_SUCCESS, 22 | "firwin"); 23 | } 24 | 25 | ltfat_free(fin); 26 | } 27 | 28 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[0]); 29 | TEST_NAME(fillRand)(fin, L[0]); 30 | 31 | mu_assert( LTFAT_NAME(firwin)( win[0], L[0], NULL) == LTFATERR_NULLPOINTER, 32 | "Array is null"); 33 | 34 | mu_assert( LTFAT_NAME(firwin)( win[0], 0, fin) == LTFATERR_BADSIZE, 35 | "gl is wrong"); 36 | 37 | mu_assert( LTFAT_NAME(firwin)( 9999, L[0], fin) == LTFATERR_CANNOTHAPPEN, 38 | "Wrong enum value"); 39 | 40 | ltfat_free(fin); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/test_ifftshift.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_ifftshift)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | 5 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 6 | { 7 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[lId]); 8 | TEST_NAME(fillRand)(fin, L[lId]); 9 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(L[lId]); 10 | TEST_NAME(fillRand)(fout, L[lId]); 11 | 12 | mu_assert( LTFAT_NAME(ifftshift)(fin, L[lId], fout) == 0, 13 | "fftshift"); 14 | mu_assert( LTFAT_NAME(ifftshift)(fin, L[lId], fin) == 0, 15 | "fftshift inplace"); 16 | 17 | ltfat_free(fin); 18 | ltfat_free(fout); 19 | } 20 | 21 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[0]); 22 | TEST_NAME(fillRand)(fin, L[0]); 23 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(L[0]); 24 | TEST_NAME(fillRand)(fout, L[0]); 25 | 26 | 27 | // Inputs can be checked only once 28 | mu_assert( LTFAT_NAME(ifftshift)(NULL, L[0], fin) == LTFATERR_NULLPOINTER, 29 | "First is null"); 30 | mu_assert( LTFAT_NAME(ifftshift)(fin, L[0], NULL) == LTFATERR_NULLPOINTER, 31 | "Last is null"); 32 | mu_assert( LTFAT_NAME(ifftshift)(fin, 0, fout) == LTFATERR_BADSIZE, 33 | "Zero length"); 34 | mu_assert( LTFAT_NAME(ifftshift)(fin, -1, fout) == LTFATERR_BADSIZE, 35 | "Negative length"); 36 | 37 | mu_assert( LTFAT_NAME(ifftshift)(NULL, -1, fout) < LTFATERR_SUCCESS, 38 | "Multiple wrong inputs"); 39 | 40 | 41 | ltfat_free(fin); 42 | ltfat_free(fout); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/test_long2fir.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_long2fir)() 2 | { 3 | ltfatInt Lfir[] = {111, 1, 100}; 4 | ltfatInt Llong[] = {111, 2, 102}; 5 | 6 | for (unsigned int lId = 0; lId < ARRAYLEN(Lfir); lId++) 7 | { 8 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(Llong[lId]); 9 | TEST_NAME(fillRand)(fin, Llong[lId]); 10 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(Lfir[lId]); 11 | TEST_NAME(fillRand)(fout, Lfir[lId]); 12 | 13 | mu_assert( LTFAT_NAME(long2fir)(fin, Llong[lId], Lfir[lId], fout) == 0, 14 | "long2fir"); 15 | mu_assert( LTFAT_NAME(long2fir)(fin, Llong[lId], Lfir[lId], fin) == 0, 16 | "long2fir inplace"); 17 | 18 | ltfat_free(fin); 19 | ltfat_free(fout); 20 | } 21 | 22 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(Llong[0]); 23 | TEST_NAME(fillRand)(fin, Llong[0]); 24 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(Lfir[0]); 25 | TEST_NAME(fillRand)(fout, Lfir[0]); 26 | 27 | 28 | // Inputs can be checked only once 29 | mu_assert( LTFAT_NAME(long2fir)(NULL, Llong[0], Lfir[0], 30 | fin) == LTFATERR_NULLPOINTER, 31 | "First is null"); 32 | mu_assert( LTFAT_NAME(long2fir)(fin, Llong[0], Lfir[0], 33 | NULL) == LTFATERR_NULLPOINTER, 34 | "Last is null"); 35 | mu_assert( LTFAT_NAME(long2fir)(fin, 0, Lfir[0], fout) == LTFATERR_BADSIZE, 36 | "Zero length"); 37 | mu_assert( LTFAT_NAME(long2fir)(fin, -1, Lfir[0], fout) == LTFATERR_BADSIZE, 38 | "Negative length"); 39 | 40 | mu_assert( LTFAT_NAME(long2fir)(fin, 9, 10 , fout) == LTFATERR_BADREQSIZE, 41 | "Output longer than input"); 42 | 43 | mu_assert( LTFAT_NAME(long2fir)(NULL, -1, Lfir[0], fout) < LTFATERR_SUCCESS, 44 | "Multiple wrong inputs"); 45 | 46 | 47 | ltfat_free(fin); 48 | ltfat_free(fout); 49 | return 0; 50 | } 51 | 52 | 53 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/test_maxtree.c: -------------------------------------------------------------------------------- 1 | ltfat_int L[] = { 9 , 10, 100, 101 }; 2 | ltfat_int depth[] = { 1, 2, 3, 4, 5 }; 3 | ltfat_int rLen[] = { 1, 2, 3, 4, 7, 8, 10, 19, 21}; 4 | 5 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 6 | { 7 | LTFAT_REAL* fin = LTFAT_NAME_REAL(malloc)(L[lId]); 8 | TEST_NAME(fillRand)(fin, L[lId]); 9 | 10 | for (unsigned int dId = 0; dId < ARRAYLEN(depth); dId++) 11 | { 12 | ltfat_int maxPos; 13 | LTFAT_REAL max; 14 | ltfat_int maxPos2; 15 | LTFAT_REAL max2; 16 | /* fin[L[lId]-1] = 100; */ 17 | LTFAT_NAME(findmaxinarray)(fin, L[lId], &max, &maxPos); 18 | printf("max=%.2f, maxPos=%td\n", max, maxPos); 19 | 20 | LTFAT_NAME(maxtree)* p = NULL; 21 | LTFAT_NAME(maxtree_initwitharray)(L[lId], depth[dId], fin, &p); 22 | LTFAT_NAME(maxtree_findmax)(p, &max2, &maxPos2); 23 | printf("max=%.2f, maxPos=%td\n", max2, maxPos2); 24 | 25 | for (unsigned int idx = 0; idx < L[lId]; idx++) 26 | { 27 | for (unsigned int rIdx = 0; rIdx < ARRAYLEN(rLen); rIdx++) 28 | { 29 | 30 | max = -100; max2 = -101; maxPos = -1; maxPos2 = -1; 31 | TEST_NAME(fillRand)(fin, L[lId]); 32 | LTFAT_NAME(maxtree_reset)(p, fin); 33 | 34 | for (unsigned int ii = 0; ii < rLen[rIdx]; ii++) 35 | { 36 | ltfat_int pos = idx + ii; 37 | if (pos >= L[lId]) 38 | pos = pos%L[lId]; 39 | 40 | fin[pos] = 100 + ii; 41 | } 42 | 43 | LTFAT_NAME(findmaxinarray)(fin, L[lId], &max, &maxPos); 44 | /* printf("max=%.2f, maxPos=%td\n",max,maxPos); */ 45 | 46 | LTFAT_NAME(maxtree_setdirty)(p, idx, idx + rLen[rIdx]); 47 | LTFAT_NAME(maxtree_findmax)(p, &max2, &maxPos2); 48 | 49 | /* printf("max=%.2f, maxPos=%td\n",max2,maxPos2); */ 50 | mu_assert( max == max2 && maxPos == maxPos2 , 51 | "TREEMAX L=%td, d=%td, idx=%d, r=%td", 52 | L[lId], depth[dId], idx, rLen[rIdx] ); 53 | } 54 | } 55 | 56 | 57 | LTFAT_NAME(maxtree_done)(&p); 58 | } 59 | 60 | ltfat_free(fin); 61 | } 62 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/test_normalize.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_normalize)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | ltfat_normalize_t norm[] = { LTFAT_NORM_NULL, LTFAT_NORM_AREA, 5 | LTFAT_NORM_1, LTFAT_NORM_ENERGY, 6 | LTFAT_NORM_2, LTFAT_NORM_INF, LTFAT_NORM_PEAK 7 | }; 8 | 9 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 10 | { 11 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[lId]); 12 | TEST_NAME(fillRand)(fin, L[lId]); 13 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(L[lId]); 14 | TEST_NAME(fillRand)(fout, L[lId]); 15 | 16 | 17 | for (unsigned int nId = 0; nId < ARRAYLEN(norm); nId++) 18 | { 19 | 20 | mu_assert( LTFAT_NAME(normalize)(fin, L[lId], norm[nId], fout) == 0, 21 | "normalize"); 22 | mu_assert( LTFAT_NAME(normalize)(fin, L[lId], norm[nId], fin) == 0, 23 | "normalize inplace"); 24 | } 25 | 26 | ltfat_free(fin); 27 | ltfat_free(fout); 28 | } 29 | 30 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[0]); 31 | TEST_NAME(fillRand)(fin, L[0]); 32 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(L[0]); 33 | TEST_NAME(fillRand)(fout, L[0]); 34 | 35 | 36 | // Inputs can be checked only once 37 | mu_assert( LTFAT_NAME(normalize)(NULL, L[0], norm[0], 38 | fin) == LTFATERR_NULLPOINTER, 39 | "First is null"); 40 | mu_assert( LTFAT_NAME(normalize)(fin, L[0], norm[0], 41 | NULL) == LTFATERR_NULLPOINTER, 42 | "Last is null"); 43 | mu_assert( LTFAT_NAME(normalize)(fin, 0, norm[0], fout) == LTFATERR_BADSIZE, 44 | "Zero length"); 45 | mu_assert( LTFAT_NAME(normalize)(fin, -1, norm[0], fout) == LTFATERR_BADSIZE, 46 | "Negative length"); 47 | 48 | mu_assert( LTFAT_NAME(normalize)(NULL, -1, norm[0], fout) < LTFATERR_SUCCESS, 49 | "Multiple wrong inputs"); 50 | 51 | mu_assert( LTFAT_NAME(normalize)(fin, L[0], 10000, 52 | fout) == LTFATERR_CANNOTHAPPEN, 53 | "Wrong flag"); 54 | 55 | 56 | ltfat_free(fin); 57 | ltfat_free(fout); 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/test_typecomplexindependent.c: -------------------------------------------------------------------------------- 1 | #include "test_circshift.c" 2 | #include "test_dgt_fb.c" 3 | #include "test_idgt_fb.c" 4 | #include "test_dgt_long.c" 5 | #include "test_idgt_long.c" 6 | #include "test_fftshift.c" 7 | #include "test_ifftshift.c" 8 | #include "test_fir2long.c" 9 | #include "test_long2fir.c" 10 | #include "test_normalize.c" 11 | #include "test_firwin.c" 12 | #include "test_gabdual_painless.c" 13 | #include "test_gabdual_long.c" 14 | 15 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/cUnit/test_typeindependent.c: -------------------------------------------------------------------------------- 1 | #include "test_fftcircshift.c" 2 | #include "test_fftfftshift.c" 3 | #include "test_fftifftshift.c" 4 | #include "test_fftrealcircshift.c" 5 | #include "test_fftrealfftshift.c" 6 | #include "test_fftrealifftshift.c" 7 | #include "test_pgauss.c" 8 | #include "test_dgtreal_fb.c" 9 | #include "test_idgtreal_fb.c" 10 | #include "test_dgtreal_long.c" 11 | #include "test_idgtreal_long.c" 12 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/mUnit/complex2interleaved.m: -------------------------------------------------------------------------------- 1 | function fi = complex2interleaved(fc) 2 | 3 | if ~isnumeric(fc) 4 | error('%s: Input must be numeric.',upper(mfilename)) 5 | end 6 | 7 | fsize = size(fc); 8 | fsize(1)=fsize(1)*2; 9 | 10 | fi = zeros(fsize,'like',fc); 11 | 12 | fi(1:2:end,:,:) = real(fc); 13 | 14 | if ~isreal(fc) 15 | fi(2:2:end,:,:) = imag(fc); 16 | end -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/mUnit/interleaved2complex.m: -------------------------------------------------------------------------------- 1 | function fc = interleaved2complex(fi) 2 | 3 | if ~isreal(fi) 4 | error('%s: Input must be real.',upper(mfilename)) 5 | end 6 | 7 | fsize = size(fi); 8 | fsize(1)=fsize(1)/2; 9 | 10 | if rem(fsize(1),1)~=0 11 | error('%s: Wrong dimension.',upper(mfilename)) 12 | end 13 | 14 | 15 | fc=fi(1:2:end,:,:) + 1i*fi(2:2:end,:,:); 16 | 17 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/mUnit/loadlibltfat.m: -------------------------------------------------------------------------------- 1 | function loadlibltfat(varargin) 2 | global libltfat_intptrstr; 3 | 4 | definput.keyvals.lib='libltfat.so'; 5 | definput.flags.phase={'load','reload','recompile'}; 6 | definput.flags.comptarget={'fulloptim','release','debug'}; 7 | definput.flags.verbosity={'quiet','verbose'}; 8 | definput.flags.corcpp={'c','cpp'}; 9 | definput.keyvals.compiler = []; 10 | 11 | [flags,kv,lib]=ltfatarghelper({'lib'},definput,varargin); 12 | 13 | [~,libname]=fileparts(lib); 14 | currdir = fileparts(mfilename('fullpath')); 15 | libltfatpath = [currdir, filesep, '..', filesep,'..',filesep,'..',filesep,'..',filesep]; 16 | libpath = [libltfatpath, filesep,'build',filesep,lib]; 17 | iscompiled = exist(libpath,'file'); 18 | 19 | makecmd = ['make -C ',libltfatpath]; 20 | if ~iscompiled || flags.do_recompile 21 | [status,result] = system([makecmd, ' clean']); 22 | if status ~=0, error(result); end 23 | 24 | makecmd = [makecmd, ' MODULE=libltfat']; 25 | makecmd = [makecmd, ' munit -j12']; 26 | makecmd = [makecmd, ' MATLABROOT=', matlabroot]; 27 | makecmd = [makecmd, sprintf(' COMPTARGET=%s',flags.comptarget)]; 28 | 29 | if flags.do_cpp 30 | makecmd = [makecmd, ' USECPP=1']; 31 | end 32 | 33 | if kv.compiler 34 | makecmd = [makecmd, sprintf(' CC=%s',kv.compiler)]; 35 | end 36 | 37 | if flags.do_verbose 38 | disp(makecmd); 39 | system(makecmd); 40 | else 41 | [status,result] = system(makecmd); 42 | if status ~=0, error(result); end 43 | end 44 | end 45 | 46 | if libisloaded(libname) 47 | if flags.do_reload || flags.do_recompile 48 | unloadlibrary(libname); 49 | else 50 | error('%s: libltfat is already loaded. Use ''reload'' to force reload.',upper(mfilename)); 51 | end 52 | end 53 | 54 | warning('off'); 55 | headerpath = [libltfatpath,'build',filesep,'ltfat.h']; 56 | loadlibrary(libpath,headerpath,'mfilename','libltfatprotofile.m'); 57 | warning('on'); 58 | 59 | intbitsize = 8*calllib('libltfat','ltfat_int_size'); 60 | libltfat_intptrstr = sprintf('int%dPtr',intbitsize); 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/mUnit/ltfatdiditfail.m: -------------------------------------------------------------------------------- 1 | function [test_failed,fail]=ltfatdiditfail(res,test_failed,tolerance); 2 | %LTFATDIDITFAIL Did a test fail 3 | % 4 | % [test_fail,fail]=LTFATDIDITFAIL(res,test_fail) updates test_fail if 5 | % res is above threshhold and outputs the word FAIL in the variable 6 | % fail. Use only in testing scripts. 7 | if nargin<3 8 | tolerance=1e-10; 9 | if isa(res,'single') 10 | tolerance=5e-4; 11 | end 12 | end; 13 | 14 | fail=''; 15 | if (abs(res)>tolerance) || isnan(res) 16 | fail='FAILED'; 17 | test_failed=test_failed+1; 18 | end; 19 | 20 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/mUnit/ltfatstatusstring.m: -------------------------------------------------------------------------------- 1 | function sstring=ltfatstatusstring(status) 2 | 3 | [~,~,enuminfo]=libltfatprotofile; 4 | 5 | map = structfun(@(a) a==status ,enuminfo.ltfaterr_status); 6 | names = fieldnames(enuminfo.ltfaterr_status); 7 | sstring = names{map}; 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/mUnit/makelibraryname.m: -------------------------------------------------------------------------------- 1 | function lname = makelibraryname(fname,complexity,is_complex) 2 | 3 | suffix = ''; 4 | 5 | if strcmp(complexity,'double') 6 | suffix = [suffix,'_d']; 7 | elseif strcmp(complexity,'single') 8 | suffix = [suffix,'_s']; 9 | end 10 | 11 | if is_complex 12 | suffix = [suffix,'c']; 13 | end 14 | 15 | lname = ['ltfat_',fname,suffix]; -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/mUnit/oldtest_libltfat_maxtree.m: -------------------------------------------------------------------------------- 1 | function test_failed = test_libltfat_maxtree(varargin) 2 | test_failed = 0; 3 | 4 | fprintf(' =============== %s ================ \n',upper(mfilename)); 5 | 6 | definput.flags.complexity={'double','single'}; 7 | [flags]=ltfatarghelper({},definput,varargin); 8 | dataPtr = [flags.complexity, 'Ptr']; 9 | 10 | Larr = [100,101,500,501,1025]; 11 | darr = 0; 12 | 13 | for repeat = 1:1 14 | for depth = darr 15 | 16 | for Lidx = 1:numel(Larr) 17 | 18 | L = Larr(Lidx); 19 | 20 | 21 | f = cast(randn(L,1)',flags.complexity); 22 | 23 | fPtr = libpointer(dataPtr,f); 24 | 25 | funname = makelibraryname('maxtree_initwitharray',flags.complexity,0); 26 | 27 | p = libpointer(); 28 | 29 | calllib('libltfat',funname,L,depth,fPtr,p); 30 | 31 | maxPtr = libpointer(dataPtr,5); 32 | maxposPtr = libpointer('int64Ptr',cast(5,'int64')); 33 | 34 | 35 | funname = makelibraryname('maxtree_findmax',flags.complexity,0); 36 | status=calllib('libltfat',funname,p,maxPtr,maxposPtr); 37 | 38 | fprintf('max=%.3f, maxPos=%d\n',maxPtr.value, maxposPtr.value); 39 | 40 | fPtr.value(1) = 1000; 41 | 42 | funname = makelibraryname('maxtree_setdirty',flags.complexity,0); 43 | status=calllib('libltfat',funname,p,0,1); 44 | 45 | funname = makelibraryname('maxtree_findmax',flags.complexity,0); 46 | status=calllib('libltfat',funname,p,maxPtr,maxposPtr); 47 | 48 | fprintf('max=%.3f, maxPos=%d\n',maxPtr.value, maxposPtr.value); 49 | 50 | 51 | [fmax,fIdx] = max(fPtr.value); 52 | 53 | fprintf('max=%.3f, maxPos=%d\n', fmax, fIdx -1); 54 | fprintf('max=%.3f, maxPos=%d\n',maxPtr.value, maxposPtr.value); 55 | 56 | [test_failed,fail]=ltfatdiditfail(maxPtr.value-fmax + maxposPtr.value - (fIdx -1) ,test_failed,0); 57 | fprintf(['MAXTREE L:%3i, %s %s %s\n'],L,flags.complexity,ltfatstatusstring(status),fail); 58 | 59 | funname = makelibraryname('maxtree_done',flags.complexity,0); 60 | calllib('libltfat',funname,p); 61 | 62 | end 63 | end 64 | end 65 | 66 | 67 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/mUnit/test_fifo.m: -------------------------------------------------------------------------------- 1 | function test_libltfat_fifo 2 | gl = 20; 3 | fifoLen = 120; % Must be at least as big as gl + max expected bufLen 4 | M = gl; 5 | a = 7; 6 | g = firwin('hann',gl); 7 | gd = gabdual(g,a,M); 8 | gg = fftshift(g.*gd)*M; 9 | 10 | fifoPtr = calllib('libltfat','rtdgtreal_fifo_init_d',fifoLen,gl,a,1); 11 | fifoPtr.Value.buf.setdatatype('doublePtr',fifoLen+1) 12 | ififoPtr = calllib('libltfat','rtidgtreal_fifo_init_d',fifoLen,gl,a,1); 13 | ififoPtr.Value.buf.setdatatype('doublePtr',fifoLen+gl+1) 14 | 15 | bufIn = (1:1000)'; 16 | %bufIn = ones(1,1000); 17 | bufOut = zeros(size(bufIn)); 18 | bufLen = 100; 19 | bufOutPtr = libpointer('doublePtr',zeros(gl,1)); 20 | 21 | for ii=1:length(bufIn)/bufLen 22 | slice = (ii-1)*bufLen + 1 : ii*bufLen; 23 | buf = bufIn(slice); 24 | bufInPtr = libpointer('doublePtr',buf); 25 | bufInPtrTmp = libpointer('doublePtr',zeros(size(buf))); 26 | 27 | written = calllib('libltfat','rtdgtreal_fifo_write_d',fifoPtr,bufLen,bufInPtr); 28 | 29 | while calllib('libltfat','rtdgtreal_fifo_read_d',fifoPtr,bufOutPtr) > 0 30 | bufOutPtr.Value = bufOutPtr.Value.*gg; 31 | written = calllib('libltfat','rtidgtreal_fifo_write_d',ififoPtr,bufOutPtr) 32 | end 33 | 34 | read = calllib('libltfat','rtidgtreal_fifo_read_d',ififoPtr,bufLen,bufInPtrTmp) 35 | 36 | bufOut(slice) = bufInPtrTmp.Value; 37 | 38 | end 39 | 40 | inshift = circshift(bufIn,(gl-1)); 41 | inshift(1:(gl-1)) = 0; 42 | stem([bufOut, inshift]);shg; 43 | 44 | 45 | 46 | 47 | calllib('libltfat','rtdgtreal_fifo_done_d',fifoPtr); 48 | calllib('libltfat','rtidgtreal_fifo_done_d',ififoPtr); 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/mUnit/test_gabframediag.m: -------------------------------------------------------------------------------- 1 | function test_libltfat_gabframediag 2 | [~,~,enuminfo]=libltfatprotofile; 3 | LTFAT_FIRWIN = enuminfo.LTFAT_FIRWIN; 4 | 5 | a = 14; 6 | gl = 34; 7 | M = 64; 8 | g = zeros(gl,1); 9 | d = zeros(a,1); 10 | gPtr = libpointer('doublePtr',g); 11 | dPtr = libpointer('doublePtr',d); 12 | 13 | calllib('libltfat','ltfat_firwin_d',LTFAT_FIRWIN.LTFAT_HANN,gl,gPtr); 14 | 15 | 16 | calllib('libltfat','ltfat_gabframediag_d',gPtr,gl,a,M,a,dPtr); 17 | 18 | 19 | d =gabframediag(gPtr.Value,a,M,lcm(a,M)); 20 | d(1:a)-dPtr.Value 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/mUnit/test_libltfat_fftshift.m: -------------------------------------------------------------------------------- 1 | function test_failed = test_libltfat_fftshift(varargin) 2 | test_failed = 0; 3 | 4 | fprintf(' =============== %s ================ \n',upper(mfilename)); 5 | 6 | definput.flags.complexity={'double','single'}; 7 | [flags]=ltfatarghelper({},definput,varargin); 8 | dataPtr = [flags.complexity, 'Ptr']; 9 | 10 | Larr = [1,9,11,110]; 11 | 12 | for do_complex = 0:1 13 | complexstring = ''; 14 | if do_complex, complexstring = 'complex'; end 15 | funname = makelibraryname('fftshift',flags.complexity,do_complex); 16 | 17 | for L = Larr 18 | 19 | if do_complex 20 | z = cast((1:L)'+1i*(L:-1:1)',flags.complexity); 21 | zi = complex2interleaved(z); 22 | zout = randn(size(zi),flags.complexity); 23 | 24 | ziPtr = libpointer(dataPtr,zi); 25 | zoutPtr = libpointer(dataPtr,zout); 26 | else 27 | z = cast((1:L)',flags.complexity); 28 | zi = z; 29 | zout = randn(size(zi),flags.complexity); 30 | 31 | ziPtr = libpointer(dataPtr,zi); 32 | zoutPtr = libpointer(dataPtr,zout); 33 | end 34 | 35 | trueres = fftshift(z); 36 | 37 | 38 | status = calllib('libltfat',funname,ziPtr,L,zoutPtr); 39 | 40 | if do_complex 41 | res = norm(trueres - interleaved2complex(zoutPtr.Value)); 42 | else 43 | res = norm(trueres - zoutPtr.Value); 44 | end 45 | 46 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed,0); 47 | fprintf(['FFTSHIFT OP L:%3i, %s %s %s %s\n'],L,flags.complexity,complexstring,ltfatstatusstring(status),fail); 48 | 49 | status = calllib('libltfat',funname,ziPtr,L,ziPtr); 50 | 51 | if do_complex 52 | res = norm(trueres - interleaved2complex(ziPtr.Value)); 53 | else 54 | res = norm(trueres - ziPtr.Value); 55 | end 56 | 57 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed,0); 58 | fprintf(['FFTSHIFT IP L:%3i, %s %s %s %s\n'],L,flags.complexity,complexstring,ltfatstatusstring(status),fail); 59 | end 60 | end 61 | 62 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/mUnit/test_libltfat_heap.m: -------------------------------------------------------------------------------- 1 | function test_failed = test_libltfat_heap(varargin) 2 | test_failed = 0; 3 | 4 | fprintf(' =============== %s ================ \n',upper(mfilename)); 5 | 6 | L = 1025; 7 | f = rand(L,1); 8 | fPtr = libpointer('doublePtr',f); 9 | idxArr = randperm(L); 10 | 11 | heap = calllib('libltfat','ltfat_heap_init_d', L, fPtr); 12 | 13 | for w = idxArr 14 | calllib('libltfat','ltfat_heap_insert_d', heap, w-1); 15 | end 16 | 17 | sortedIdxArr = zeros(L,1); 18 | 19 | for w = 1:L 20 | sortedIdxArr(w) = calllib('libltfat','ltfat_heap_delete_d', heap); 21 | end 22 | 23 | calllib('libltfat','ltfat_heap_done_d',heap); 24 | 25 | res = norm(f(sortedIdxArr+1) - sort(f,'descend')); 26 | 27 | plot([f,f(sortedIdxArr+1),sort(f,'descend')]) 28 | 29 | if res>0 30 | test_failed=1; 31 | end 32 | 33 | 34 | 35 | 36 | 37 | %plot(sort(f,'descend')) 38 | 39 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/mUnit/test_libltfat_pgauss.m: -------------------------------------------------------------------------------- 1 | function test_failed = test_libltfat_pgauss(varargin) 2 | test_failed = 0; 3 | 4 | fprintf(' =============== %s ================ \n',upper(mfilename)); 5 | 6 | definput.flags.complexity={'double','single'}; 7 | [flags]=ltfatarghelper({},definput,varargin); 8 | dataPtr = [flags.complexity, 'Ptr']; 9 | 10 | Larr = [1 ,9, 11, 110, 1, 9, 11, 110]; 11 | tfratarr = [1, 2, 0.1, 100, 1, 2, 0.1, 100]; 12 | ctarr = [0, 0, 0, 0, 0.1, -0.1, 1.0, 0.2]; 13 | cfarr = [0, 0.1, 0, 0,-0.1, 0, 1, 0]; 14 | 15 | 16 | for L = Larr 17 | for tfrId = 1:numel(tfratarr) 18 | tfr = tfratarr(tfrId); 19 | ct = ctarr(tfrId); 20 | cf = cfarr(tfrId); 21 | 22 | z = cast((1:L)',flags.complexity); 23 | zi = z; 24 | ziPtr = libpointer(dataPtr,zi); 25 | 26 | trueres = pgauss(L,tfr,'delay',-ct); 27 | 28 | status = calllib('libltfat',makelibraryname('pgauss',flags.complexity,0),... 29 | L,tfr,ct,ziPtr); 30 | 31 | res = norm(trueres - ziPtr.Value); 32 | 33 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed); 34 | fprintf(['PGAUSS L:%3i, tfr:%3.3f c_t:%3.3f %s %s %s\n'],L,tfr,ct,flags.complexity,ltfatstatusstring(status),fail); 35 | 36 | 37 | z = cast((1:L)'+1i*(L:-1:1)',flags.complexity); 38 | zi = complex2interleaved(z); 39 | ziPtr = libpointer(dataPtr,zi); 40 | 41 | trueres = pgauss(L,tfr,'delay',-ct,'cf',cf); 42 | 43 | status = calllib('libltfat',makelibraryname('pgauss',flags.complexity,1),... 44 | L,tfr,ct,cf,ziPtr); 45 | 46 | res = norm(trueres - interleaved2complex(ziPtr.Value)); 47 | 48 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed); 49 | fprintf(['PGAUSS CMPLX L:%3i, tfr:%3.3f c_t:%3.3f c_f:%3.3f %s %s %s\n'],L,tfr,ct,cf,flags.complexity,ltfatstatusstring(status),fail); 50 | 51 | end 52 | end 53 | 54 | 55 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/mUnit/test_libltfat_solvehermitiansystem.m: -------------------------------------------------------------------------------- 1 | function test_failed = test_libltfat_solvehermitiansystem(varargin) 2 | test_failed = 0; 3 | 4 | fprintf(' =============== %s ================ \n',upper(mfilename)); 5 | 6 | definput.flags.complexity={'double','single'}; 7 | [flags]=ltfatarghelper({},definput,varargin); 8 | dataPtr = [flags.complexity, 'Ptr']; 9 | 10 | Larr = [301, 9,11,110, 9, 8, 11, 10, 301]; 11 | 12 | 13 | complexstring = 'complex'; 14 | funname_init = makelibraryname('hermsystemsolver_init',flags.complexity,1); 15 | funname_execute = makelibraryname('hermsystemsolver_execute',flags.complexity,1); 16 | funname_done = makelibraryname('hermsystemsolver_done',flags.complexity,1); 17 | 18 | p = libpointer(); 19 | calllib('libltfat',funname_init,max(Larr),p); 20 | 21 | for Lidx = 1:numel(Larr) 22 | L = Larr(Lidx); 23 | 24 | 25 | 26 | 27 | 28 | D = randn(L,flags.complexity)+1i*randn(L,flags.complexity); 29 | % D(:,1) = D(:,end); 30 | A = D*D'; 31 | Amessedup = A; 32 | for n=2:size(A,2) 33 | for m=1:n-1 34 | Amessedup(m,n) = randn(1); 35 | end 36 | end 37 | Aint = complex2interleaved(Amessedup); 38 | APtr = libpointer(dataPtr,Aint); 39 | 40 | b = randn(L,1,flags.complexity)+ 1i*randn(L,1,flags.complexity); 41 | bint = complex2interleaved(b); 42 | bPtr = libpointer(dataPtr,bint); 43 | 44 | tic 45 | trueres = A\b; 46 | toc 47 | 48 | tic 49 | status = calllib('libltfat',funname_execute,p,APtr,L,bPtr); 50 | toc 51 | 52 | 53 | res = norm(trueres - interleaved2complex(bPtr.Value)); 54 | 55 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed,1e-8); 56 | fprintf(['SOLVEHERM L:%3i, %s %s %s %s\n'],L,flags.complexity,complexstring,ltfatstatusstring(status),fail); 57 | 58 | end 59 | 60 | calllib('libltfat',funname_done,p); 61 | 62 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/pyUnit/test_libltfat_fftshift.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | # encoding: utf-8 3 | 4 | from testhelper import lib, ffi 5 | import numpy as np 6 | 7 | 8 | def test_fftshift(): 9 | inArr = np.array([1, 2, 3, 4, 5, 6, 7], dtype=np.float64) 10 | res = np.array([5, 6, 7, 1, 2, 3, 4], dtype=np.float64) 11 | status = getattr(lib, 'ltfat_fftshift_d')( 12 | ffi.cast("double *",inArr.ctypes.data), 7, ffi.cast("double *",res.ctypes.data)) 13 | print(inArr) 14 | print(res) 15 | assert all(inArr == res) 16 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/testing/pyUnit/testhelper.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | # encoding: utf-8 3 | 4 | import os 5 | import subprocess 6 | from cffi import FFI 7 | 8 | ffi = FFI() 9 | filedir = os.path.dirname(os.path.abspath(__file__)) 10 | libpath = os.path.join(filedir, '..', '..', 'build') 11 | libltfat = os.path.join(libpath, 'libltfat.so') 12 | header = os.path.join(libpath, 'ltfat_flat.h') 13 | 14 | with open(header) as f_header: 15 | ffi.cdef(f_header.read()) 16 | 17 | lib = ffi.dlopen(libltfat) 18 | 19 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/thirdparty/kissfft/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2003-2010 Mark Borgerding 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 12 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/thirdparty/kissfft/Makefile: -------------------------------------------------------------------------------- 1 | KFVER=130 2 | 3 | doc: 4 | @echo "Start by reading the README file. If you want to build and test lots of stuff, do a 'make testall'" 5 | @echo "but be aware that 'make testall' has dependencies that the basic kissfft software does not." 6 | @echo "It is generally unneeded to run these tests yourself, unless you plan on changing the inner workings" 7 | @echo "of kissfft and would like to make use of its regression tests." 8 | 9 | testall: 10 | # The simd and int32_t types may or may not work on your machine 11 | make -C test DATATYPE=simd CFLAGADD="$(CFLAGADD)" test 12 | make -C test DATATYPE=int32_t CFLAGADD="$(CFLAGADD)" test 13 | make -C test DATATYPE=int16_t CFLAGADD="$(CFLAGADD)" test 14 | make -C test DATATYPE=float CFLAGADD="$(CFLAGADD)" test 15 | make -C test DATATYPE=double CFLAGADD="$(CFLAGADD)" test 16 | echo "all tests passed" 17 | 18 | tarball: clean 19 | hg archive -r v$(KFVER) -t tgz kiss_fft$(KFVER).tar.gz 20 | hg archive -r v$(KFVER) -t zip kiss_fft$(KFVER).zip 21 | 22 | clean: 23 | cd test && make clean 24 | cd tools && make clean 25 | rm -f kiss_fft*.tar.gz *~ *.pyc kiss_fft*.zip 26 | 27 | asm: kiss_fft.s 28 | 29 | kiss_fft.s: kiss_fft.c kiss_fft.h _kiss_fft_guts.h 30 | [ -e kiss_fft.s ] && mv kiss_fft.s kiss_fft.s~ || true 31 | gcc -S kiss_fft.c -O3 -mtune=native -ffast-math -fomit-frame-pointer -unroll-loops -dA -fverbose-asm 32 | gcc -o kiss_fft_short.s -S kiss_fft.c -O3 -mtune=native -ffast-math -fomit-frame-pointer -dA -fverbose-asm -DFIXED_POINT 33 | [ -e kiss_fft.s~ ] && diff kiss_fft.s~ kiss_fft.s || true 34 | -------------------------------------------------------------------------------- /libltfat/modules/libltfat/thirdparty/kissfft/TIPS: -------------------------------------------------------------------------------- 1 | Speed: 2 | * If you want to use multiple cores, then compile with -openmp or -fopenmp (see your compiler docs). 3 | Realize that larger FFTs will reap more benefit than smaller FFTs. This generally uses more CPU time, but 4 | less wall time. 5 | 6 | * experiment with compiler flags 7 | Special thanks to Oscar Lesta. He suggested some compiler flags 8 | for gcc that make a big difference. They shave 10-15% off 9 | execution time on some systems. Try some combination of: 10 | -march=pentiumpro 11 | -ffast-math 12 | -fomit-frame-pointer 13 | 14 | * If the input data has no imaginary component, use the kiss_fftr code under tools/. 15 | Real ffts are roughly twice as fast as complex. 16 | 17 | * If you can rearrange your code to do 4 FFTs in parallel and you are on a recent Intel or AMD machine, 18 | then you might want to experiment with the USE_SIMD code. See README.simd 19 | 20 | 21 | Reducing code size: 22 | * remove some of the butterflies. There are currently butterflies optimized for radices 23 | 2,3,4,5. It is worth mentioning that you can still use FFT sizes that contain 24 | other factors, they just won't be quite as fast. You can decide for yourself 25 | whether to keep radix 2 or 4. If you do some work in this area, let me 26 | know what you find. 27 | 28 | * For platforms where ROM/code space is more plentiful than RAM, 29 | consider creating a hardcoded kiss_fft_state. In other words, decide which 30 | FFT size(s) you want and make a structure with the correct factors and twiddles. 31 | 32 | * Frank van der Hulst offered numerous suggestions for smaller code size and correct operation 33 | on embedded targets. "I'm happy to help anyone who is trying to implement KISSFFT on a micro" 34 | 35 | Some of these were rolled into the mainline code base: 36 | - using long casts to promote intermediate results of short*short multiplication 37 | - delaying allocation of buffers that are sometimes unused. 38 | In some cases, it may be desirable to limit capability in order to better suit the target: 39 | - predefining the twiddle tables for the desired fft size. 40 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.8) 2 | project (libphaseret C CXX) 3 | 4 | option(NOBLASLAPACK 5 | "Disable BLAS and LAPACK dependency. Must be used if LTFAT was compiled without BLAS 6 | and LAPACK dependency" OFF) 7 | 8 | if (MSVC) 9 | set(USECPP 1) 10 | else (MSVC) 11 | option(USECPP 12 | "Use C++ compiler instead of C compiler" OFF) 13 | endif (MSVC) 14 | 15 | 16 | # FIND_LIBRARY(FFTW3_LIB NAMES fftw3 libfftw3) 17 | # FIND_LIBRARY(FFTW3F_LIB NAMES fftw3f libfftw3f) 18 | 19 | FIND_LIBRARY(LTFAT_LIB NAMES ltfat libltfat) 20 | FIND_LIBRARY(LTFATF_LIB NAMES ltfatf libltfatf) 21 | FIND_LIBRARY(LTFATD_LIB NAMES ltfatd libltfatd) 22 | 23 | FIND_PATH(LTFAT_INCLUDE NAMES ltfat.h) 24 | 25 | # if (NOT NOBLASLAPACK) 26 | # FIND_LIBRARY(BLAS_LIB NAMES blas libblas) 27 | # FIND_LIBRARY(LAPACK_LIB NAMES lapack liblapack) 28 | # endif (NOT NOBLASLAPACK) 29 | 30 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build) 31 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build) 32 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build) 33 | 34 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 35 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty) 36 | include_directories(${LTFAT_INCLUDE}) 37 | 38 | add_subdirectory(src) 39 | 40 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/README.md: -------------------------------------------------------------------------------- 1 | #libPhaseReT 2 | libPhaseReT is a C99 and C++11 library collecting implementations of phase 3 | reconstruction algorithms for complex time-frequency representations (like STFT). 4 | 5 | ## Requirements 6 | 7 | The library depends on [libltfat](http://github.com/ltfat/libltfat). 8 | 9 | ## Instalation and usage 10 | 11 | The following installs the library to /usr/local/lib and phaseret.h to /usr/local/include/ 12 | 13 | ``` 14 | make 15 | sudo make install 16 | ``` 17 | 18 | The path can be changed by calling 19 | 20 | ``` 21 | sudo make install PREFIX=/custom/path 22 | ``` 23 | 24 | ## Documentation 25 | 26 | Doxygen-generated documentation [webpage](http://ltfat.github.io/libphaseret). 27 | 28 | # References 29 | 30 | If you use this toolbox/library in your research, please cite 31 | 32 | > Zdenek Prusa, Peter Soendergaard: TBD. 33 | 34 | and/or relevant references found in help of the individual files. 35 | 36 | # License 37 | PhaseReT is distributed under terms of 38 | [GPL3](http://www.gnu.org/licenses/gpl-3.0.en.html) 39 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/doc/doxymain.md: -------------------------------------------------------------------------------- 1 | \mainpage Phase Retrieval Toolbox Library 2 | 3 | 4 | Algorithms 5 | ---------- 6 | 7 | #### Offline # 8 | - \ref gla 9 | - \ref legla 10 | - \ref pghi 11 | 12 | #### Real-time # 13 | - \ref rtisila 14 | - \ref rtpghi 15 | - \ref spsi 16 | 17 | Conventions 18 | ----------- 19 | 20 | The library follows the same conventions as the 21 | [libltfat](http://ltfat.github.io/libltfat). 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/doc/gla.md: -------------------------------------------------------------------------------- 1 | \defgroup gla Griffin-Lim Algorithm 2 | \addtogroup gla 3 | 4 | Algorithm Description 5 | --------------------- 6 | 7 | The implementation follows papers \cite griflim84 \cite pebaso13 8 | 9 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/doc/htmltemplate/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/doc/htmltemplate/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | $projectname: $title 9 | $title 10 | 11 | 12 | 13 | $treeview 14 | $search 15 | $mathjax 16 | 17 | $extrastylesheet 18 | 19 | 20 |
21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |  $projectnumber --> 34 | 35 |
$projectbrief
--> 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 |
$searchbox
53 |
54 | 55 | 56 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/doc/legla.md: -------------------------------------------------------------------------------- 1 | \defgroup legla Le Roux's Modifications of the Griffin-Lim Algorithm 2 | \addtogroup legla 3 | 4 | Algorithm Description 5 | --------------------- 6 | 7 | The implementation follows papers \cite leroux08 \cite leroux10. 8 | 9 | Algorithm Acceleration 10 | ---------------------- 11 | 12 | \cite pebaso13 13 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/doc/mathjaxinclude/macros.js: -------------------------------------------------------------------------------- 1 | MathJax.Hub.Config({ 2 | TeX: { 3 | Macros: { 4 | stime: "t", 5 | sfreq: "\\omega", 6 | sfreqarg: "\\xi", 7 | stimearg: "\\tau", 8 | me: "\\mathrm{e}", 9 | mi: "\\mathrm{i}", 10 | } 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/doc/pghi.md: -------------------------------------------------------------------------------- 1 | \defgroup pghi Phase Gradient Heap Integration 2 | \addtogroup pghi 3 | 4 | Algorithm Description 5 | --------------------- 6 | 7 | The implementation follows paper \cite ltfatnote040. 8 | 9 | Please note that the gollowing relation holds between 10 | \f$\lambda\f$ used in the paper and \f$\gamma\f$ used in this 11 | implementation 12 | \f[ 13 | \gamma = \lambda L, 14 | \f] 15 | where \f$L\f$ is the transform length. 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/doc/rtisila.md: -------------------------------------------------------------------------------- 1 | \defgroup rtisila Real-Time Spectrogram Inversion with Look Ahead 2 | \addtogroup rtisila 3 | 4 | Algorithm Description 5 | --------------------- 6 | 7 | The implementation follows paper \cite zhbewy07. 8 | 9 | 10 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/doc/rtpghi.md: -------------------------------------------------------------------------------- 1 | \defgroup rtpghi Real-Time Phase Gradient Heap Integration 2 | \addtogroup rtpghi 3 | 4 | Algorithm Description 5 | --------------------- 6 | 7 | The implementation follows paper \cite ltfatnote043 8 | 9 | The \a gamma parameter for a window \f$ g\f$ can be computed as 10 | \f[ 11 | \gamma = C_g (\mathit{gl})^2 12 | \f] 13 | where \a gl is a window length. 14 | 15 | FIR window | \f$ C_g \f$ 16 | ---------------------------------------------|-------------- 17 | LTFAT_HANN, LTFAT_HANNING, NUTTALL10 | 0.25645 18 | LTFAT_SQRTHANN, LTFAT_COSINE, LTFAT_SINE | 0.41532 19 | LTFAT_HAMMING | 0.29794 20 | LTFAT_NUTTALL01 | 0.29610 21 | LTFAT_TRIA, LTFAT_TRIANGULAR, LTFAT_BARTLETT | 0.27561 22 | LTFAT_SQRTTRIA | 0.48068 23 | LTFAT_BLACKMAN | 0.17954 24 | LTFAT_BLACKMAN2 | 0.18465 25 | LTFAT_NUTTALL, LTFAT_NUTTALL12 | 0.12807 26 | LTFAT_OGG, LTFAT_ITERSINE | 0.35744 27 | LTFAT_NUTTALL20 | 0.14315 28 | LTFAT_NUTTALL11 | 0.17001 29 | LTFAT_NUTTALL02 | 0.18284 30 | LTFAT_NUTTALL30 | 0.09895 31 | LTFAT_NUTTALL21 | 0.11636 32 | LTFAT_NUTTALL03 | 0.13369 33 | 34 | For \gamma for a Gaussian window please see \cite ltfatnote043 35 | 36 | The Gaussian window will give the best result. 37 | LTFAT_BLACKMAN is also a good choice. 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/doc/spsi.md: -------------------------------------------------------------------------------- 1 | \defgroup spsi Single Pass Spectrogram Inversion 2 | \addtogroup spsi 3 | 4 | Algorithm Description 5 | --------------------- 6 | 7 | The implementation follows papers \cite be15 . 8 | 9 | 10 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/doc/texinclude/macros.tex: -------------------------------------------------------------------------------- 1 | 2 | \DeclareMathOperator*{\argmax}{arg\,max} 3 | \DeclareMathOperator*{\supp}{supp} 4 | 5 | \newcommand{\stime}{t} 6 | \newcommand{\stimearg}{\tau} 7 | \newcommand{\sfreq}{\omega} 8 | \newcommand{\sfreqarg}{\xi} 9 | 10 | 11 | \newcommand{\Lspacen}[1]{\ensuremath{L^2\left\mathcal{R}^{#1}\right}} 12 | \newcommand{\Lspace}{\Lspacen{}} 13 | \newcommand{\Lspacetwod}{\Lspacen{2}} 14 | 15 | \newcommand{\barg}{\ensuremath{\mathcal{B}}} 16 | \newcommand{\dstimearg}{\ensuremath{\, \mathrm{d}\stimearg}} 17 | 18 | \newcommand{\modop}{\ensuremath{\mathcal{E}}} 19 | \newcommand{\tranop}{\ensuremath{\mathcal{T}}} 20 | \newcommand{\dilop}{\ensuremath{\mathcal{D}}} 21 | 22 | \newcommand{\modoparg}[1]{\ensuremath{\modop_{#1}}} 23 | \newcommand{\tranoparg}[1]{\ensuremath{\tranop_{#1}}} 24 | \newcommand{\diloparg}[1]{\ensuremath{\dilop_{#1}}} 25 | 26 | \newcommand{\modopsfreq}{\modoparg{\sfreq}} 27 | \newcommand{\tranopstime}{\tranoparg{\stime}} 28 | \newcommand{\diloplambda}{\diloparg{\lambda}} 29 | 30 | \newcommand{\stftphase}[2]{\ensuremath{\Phi_{#1}^{#2}}} 31 | \newcommand{\stftmodulus}[2]{\ensuremath{M_{#1}^{#2}}} 32 | 33 | \newcommand{\stftphasefvarphi}{\stftphase{\varphi}{f}} 34 | \newcommand{\stftmodulusfvarphi}{\stftmodulus{\varphi}{f}} 35 | 36 | \newcommand{\stftphasefg}{\stftphase{g}{f}} 37 | \newcommand{\stftmodulusfg}{\stftmodulus{g}{f}} 38 | 39 | \newcommand{\me}{\mathrm{e}} 40 | \newcommand{\mi}{\mathrm{i}} 41 | 42 | % \newcommand{\normm}[1]{\left\lVert#1\right\rVert} 43 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/include/phaseret.h: -------------------------------------------------------------------------------- 1 | #ifndef _phaseret_h 2 | #define _phaseret_h 3 | 4 | #ifndef LTFAT_NOSYSTEMHEADERS 5 | #include "ltfat.h" 6 | #endif 7 | 8 | #ifndef LTFAT_DOUBLE 9 | # ifndef LTFAT_SINGLE 10 | # define LTFAT_SINGLE_WASNOTDEFINED 11 | # define LTFAT_SINGLE 12 | # endif 13 | 14 | # include "phaseret/api.h" 15 | 16 | # ifdef LTFAT_SINGLE_WASNOTDEFINED 17 | # undef LTFAT_SINGLE 18 | # undef LTFAT_SINGLE_WASNOTDEFINED 19 | # endif 20 | #endif 21 | 22 | #ifndef LTFAT_SINGLE 23 | # ifndef LTFAT_DOUBLE 24 | # define LTFAT_DOUBLE_WASNOTDEFINED 25 | # define LTFAT_DOUBLE 26 | # endif 27 | 28 | # include "phaseret/api.h" 29 | 30 | # ifdef LTFAT_DOUBLE_WASNOTDEFINED 31 | # undef LTFAT_DOUBLE 32 | # undef LTFAT_DOUBLE_WASNOTDEFINED 33 | # endif 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/include/phaseret/api.h: -------------------------------------------------------------------------------- 1 | //#include "dgtrealwrapper.h" 2 | #include "gla.h" 3 | #include "legla.h" 4 | #include "pghi.h" 5 | #include "spsi.h" 6 | #include "rtpghi.h" 7 | #include "rtpghifb.h" 8 | #include "rtisila.h" 9 | #include "gsrtisila.h" 10 | #include "gsrtisilapghi.h" 11 | #include "utils.h" 12 | 13 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/include/phaseret/basicmacros.h: -------------------------------------------------------------------------------- 1 | #ifndef _PHASERET_BASICMACROS_H 2 | #define _PHASERET_BASICMACROS_H 3 | 4 | #ifndef PHASERET_API 5 | #if defined(_WIN32) || defined(__WIN32__) 6 | # if defined(LTFAT_BUILD_SHARED) 7 | # define PHASERET_API __declspec(dllexport) 8 | # elif !defined(LTFAT_BUILD_STATIC) 9 | # define PHASERET_API __declspec(dllimport) 10 | # else 11 | # define PHASERET_API 12 | # endif 13 | #else 14 | // # if __GNUC__ >= 4 15 | // # define PHASERET_API __attribute__((visibility("default"))) 16 | // # else 17 | # define PHASERET_API 18 | // # endif 19 | #endif 20 | #endif 21 | 22 | #define PHASERET_NAME_DOUBLE(name) LTFAT_MAKENAME(phaseret,name,_d) 23 | #define PHASERET_NAME_SINGLE(name) LTFAT_MAKENAME(phaseret,name,_s) 24 | #define PHASERET_NAME_COMPLEXDOUBLE(name) LTFAT_MAKENAME(phaseret,name,_dc) 25 | #define PHASERET_NAME_COMPLEXSINGLE(name) LTFAT_MAKENAME(phaseret,name,_sc) 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/include/phaseret/types.h: -------------------------------------------------------------------------------- 1 | #include "basicmacros.h" 2 | #include "ltfat/types.h" 3 | 4 | #ifdef PHASERET_NAME_REAL 5 | #undef PHASERET_NAME_REAL 6 | #endif 7 | 8 | #ifdef PHASERET_NAME_COMPLEX 9 | #undef PHASERET_NAME_COMPLEX 10 | #endif 11 | 12 | #ifdef PHASERET_NAME 13 | #undef PHASERET_NAME 14 | #endif 15 | 16 | #ifdef LTFAT_DOUBLE 17 | # define PHASERET_NAME_REAL(name) PHASERET_NAME_DOUBLE(name) 18 | # define PHASERET_NAME_COMPLEX(name) PHASERET_NAME_COMPLEXDOUBLE(name) 19 | # if defined(LTFAT_COMPLEXTYPE) 20 | # define PHASERET_NAME(name) PHASERET_NAME_COMPLEXDOUBLE(name) 21 | # else 22 | # define PHASERET_NAME(name) PHASERET_NAME_DOUBLE(name) 23 | # endif 24 | #endif 25 | 26 | #ifdef LTFAT_SINGLE 27 | #define PHASERET_NAME_REAL(name) PHASERET_NAME_SINGLE(name) 28 | #define PHASERET_NAME_COMPLEX(name) PHASERET_NAME_COMPLEXSINGLE(name) 29 | # if defined(LTFAT_COMPLEXTYPE) 30 | # define PHASERET_NAME(name) PHASERET_NAME_COMPLEXSINGLE(name) 31 | # else 32 | # define PHASERET_NAME(name) PHASERET_NAME_SINGLE(name) 33 | # endif 34 | #endif 35 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/include/phaseret/utils.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef LTFAT_NOSYSTEMHEADERS 3 | #include "ltfat.h" 4 | #include "ltfat/types.h" 5 | #endif 6 | #include "phaseret/types.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /** Shifts cols of height x N matrix by one to the left 13 | * 14 | * \param[in,o] cols Input/output matrix 15 | * \param[in] height Height 16 | * \param[in] N No. of cols 17 | * \param[in] newcol (optional) Length height vector to be used as the last col. 18 | * If it is NULL, it is set to zeros. 19 | */ 20 | int 21 | PHASERET_NAME(shiftcolsleft)(LTFAT_REAL cols[], ltfat_int height, ltfat_int N, const LTFAT_REAL newcol[]); 22 | 23 | int 24 | PHASERET_NAME_COMPLEX(shiftcolsleft)(LTFAT_COMPLEX cols[], ltfat_int height, ltfat_int N, const LTFAT_COMPLEX newcol[]); 25 | 26 | int 27 | PHASERET_NAME(force_magnitude)(LTFAT_COMPLEX cin[], const LTFAT_REAL s[], ltfat_int L, LTFAT_COMPLEX cout[]); 28 | 29 | void 30 | PHASERET_NAME(realimag2absangle)(const LTFAT_COMPLEX cin[], ltfat_int L, LTFAT_COMPLEX c[]); 31 | 32 | void 33 | PHASERET_NAME(absangle2realimag)(const LTFAT_COMPLEX cin[], ltfat_int L, LTFAT_COMPLEX c[]); 34 | 35 | PHASERET_API void 36 | PHASERET_NAME(absangle2realimag_split2inter)(const LTFAT_REAL s[], 37 | const LTFAT_REAL phase[], ltfat_int L, LTFAT_COMPLEX c[]); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | 44 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/src/filedefs.mk: -------------------------------------------------------------------------------- 1 | files += gla.c legla.c gsrtisila.c gsrtisilapghi.c pghi.c rtisila.c rtpghi.c spsi.c utils.c rtpghifb.c 2 | files_notypechange += pghi_typeconstant.c legla_typeconstant.c 3 | 4 | DSLFLAGS = -lltfat 5 | DLFLAGS = -lltfatd 6 | SLFLAGS = -lltfatf 7 | CFLAGS+=-Imodules/libltfat/include 8 | extradepincludes:=\#include \"ltfat.h\"\n 9 | 10 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/src/gsrtisila_private.h: -------------------------------------------------------------------------------- 1 | #ifndef _PHASERET_GSRTISILA_PRIVATE_H 2 | #define _PHASERET_GSRTISILA_PRIVATE_H 3 | 4 | 5 | struct PHASERET_NAME(gsrtisilaupdate_plan) 6 | { 7 | PHASERET_NAME(rtisilaupdate_plan)* p2; 8 | const LTFAT_REAL* g; 9 | // const LTFAT_REAL* gd; 10 | ltfat_int gl; 11 | ltfat_int M; 12 | ltfat_int a; 13 | ltfat_int gNo; 14 | int do_skipinitialization; 15 | }; 16 | 17 | struct PHASERET_NAME(gsrtisila_state) 18 | { 19 | PHASERET_NAME(gsrtisilaupdate_plan)* uplan; 20 | ltfat_int maxLookahead; 21 | ltfat_int lookahead; 22 | ltfat_int lookback; 23 | ltfat_int maxit; 24 | ltfat_int W; 25 | LTFAT_REAL* frames; //!< Buffer for time-domain frames 26 | LTFAT_COMPLEX* cframes; //!< Buffer for frequency-domain frames 27 | LTFAT_REAL* s; //!< Buffer for target magnitude 28 | void** garbageBin; 29 | ltfat_int garbageBinSize; 30 | }; 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/src/legla_private.h: -------------------------------------------------------------------------------- 1 | #ifndef _phaseret_legla_private_h 2 | #define _phaseret_legla_private_h 3 | //#include "dgtrealwrapper_private.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | struct phaseret_legla_params 10 | { 11 | double relthr; ///< Relative threshold for automatic determination of kernel size, default 1e-3 12 | phaseret_size ksize; ///< Maximum allowed kernel size (default 2*ceil(M/a) -1) or kernel size directly if relthr==0.0 13 | unsigned leglaflags; ///< LEGLA algorithm flags, default MOD_COEFFICIENTWISE | MOD_MODIFIEDUPDATE 14 | ltfat_dgt_params* dparams; 15 | }; 16 | 17 | 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/src/legla_typeconstant.c: -------------------------------------------------------------------------------- 1 | #include "phaseret/legla.h" 2 | #include "legla_private.h" 3 | #include "ltfat/macros.h" 4 | 5 | 6 | int 7 | phaseret_legla_params_defaults(phaseret_legla_params* params) 8 | { 9 | int status = LTFATERR_SUCCESS; 10 | CHECKNULL(params); 11 | 12 | params->relthr = 1e-3; 13 | params->ksize.width = 0; 14 | params->ksize.height = 0; 15 | params->leglaflags = MOD_COEFFICIENTWISE | MOD_MODIFIEDUPDATE; 16 | CHECKMEM( params->dparams = ltfat_dgt_params_allocdef()); 17 | error: 18 | return status; 19 | } 20 | 21 | 22 | PHASERET_API phaseret_legla_params* 23 | phaseret_legla_params_allocdef() 24 | { 25 | phaseret_legla_params* params = 26 | (phaseret_legla_params*) ltfat_calloc(1, sizeof * params); 27 | 28 | phaseret_legla_params_defaults(params); 29 | 30 | return params; 31 | } 32 | 33 | PHASERET_API int 34 | phaseret_legla_params_set_relthr(phaseret_legla_params* params, double relthr) 35 | { 36 | int status = LTFATERR_SUCCESS; 37 | CHECKNULL(params); 38 | params->relthr = relthr; 39 | error: 40 | return status; 41 | } 42 | 43 | 44 | PHASERET_API int 45 | phaseret_legla_params_set_kernelsize(phaseret_legla_params* params, 46 | phaseret_size ksize) 47 | { 48 | int status = LTFATERR_SUCCESS; 49 | CHECKNULL(params); 50 | params->ksize = ksize; 51 | error: 52 | return status; 53 | } 54 | 55 | PHASERET_API int 56 | phaseret_legla_params_set_leglaflags(phaseret_legla_params* params, 57 | unsigned leglaflags) 58 | { 59 | int status = LTFATERR_SUCCESS; 60 | CHECKNULL(params); 61 | params->leglaflags = leglaflags; 62 | error: 63 | return status; 64 | } 65 | 66 | PHASERET_API ltfat_dgt_params* 67 | phaseret_legla_params_get_dgtreal_params(phaseret_legla_params* params) 68 | { 69 | if (params) 70 | return params->dparams; 71 | else 72 | return NULL; 73 | } 74 | 75 | PHASERET_API int 76 | phaseret_legla_params_free(phaseret_legla_params* params) 77 | { 78 | int status = LTFATERR_SUCCESS; 79 | CHECKNULL(params); 80 | ltfat_dgt_params_free(params->dparams); 81 | ltfat_free(params); 82 | error: 83 | return status; 84 | 85 | } 86 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/src/pghi_typeconstant.c: -------------------------------------------------------------------------------- 1 | #include "phaseret/rtpghi.h" 2 | 3 | PHASERET_API double 4 | phaseret_firwin2gamma(LTFAT_FIRWIN win, ltfat_int gl) 5 | { 6 | double gamma; 7 | if ( gl <= 0) return NAN; 8 | 9 | switch (win) 10 | { 11 | case LTFAT_HANN: 12 | /* case LTFAT_HANNING: */ 13 | /* case LTFAT_NUTTALL10: */ 14 | gamma = 0.25645; break; 15 | case LTFAT_SQRTHANN: 16 | /* case LTFAT_COSINE: */ 17 | /* case LTFAT_SINE: */ 18 | gamma = 0.41532; break; 19 | case LTFAT_HAMMING: 20 | gamma = 0.29794; break; 21 | case LTFAT_NUTTALL01: 22 | gamma = 0.29610; break; 23 | case LTFAT_SQUARE: 24 | /* case LTFAT_RECT: */ 25 | gamma = 0.85732; break; 26 | case LTFAT_TRIA: 27 | /* case LTFAT_TRIANGULAR: */ 28 | /* case LTFAT_BARTLETT: */ 29 | gamma = 0.27561; break; 30 | case LTFAT_SQRTTRIA: 31 | gamma = 0.48068; break; 32 | case LTFAT_BLACKMAN: 33 | gamma = 0.17954; break; 34 | case LTFAT_BLACKMAN2: 35 | gamma = 0.18465; break; 36 | case LTFAT_NUTTALL: 37 | /* case LTFAT_NUTTALL12: */ 38 | gamma = 0.12807; break; 39 | case LTFAT_OGG: 40 | /* case LTFAT_ITERSINE: */ 41 | gamma = 0.35744; break; 42 | case LTFAT_NUTTALL20: 43 | gamma = 0.14315; break; 44 | case LTFAT_NUTTALL11: 45 | gamma = 0.17001; break; 46 | case LTFAT_NUTTALL02: 47 | gamma = 0.18284; break; 48 | case LTFAT_NUTTALL30: 49 | gamma = 0.09895; break; 50 | case LTFAT_NUTTALL21: 51 | gamma = 0.11636; break; 52 | case LTFAT_NUTTALL03: 53 | gamma = 0.13369; break; 54 | case LTFAT_TRUNCGAUSS01: 55 | gamma = 0.17054704423023; break; 56 | default: 57 | return NAN; 58 | }; 59 | 60 | gamma *= gl * gl; 61 | 62 | return gamma; 63 | } 64 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/src/rtpghi_private.h: -------------------------------------------------------------------------------- 1 | #ifndef _PHASERET_RTPGHI_PRIVATE_H 2 | #define _PHASERET_RTPGHI_PRIVATE_H 3 | 4 | 5 | struct PHASERET_NAME(rtpghi_state) 6 | { 7 | PHASERET_NAME(rtpghiupdate_plan)* p; 8 | ltfat_int M; 9 | ltfat_int a; 10 | ltfat_int W; 11 | int do_causal; 12 | LTFAT_REAL* slog; 13 | LTFAT_REAL* s; 14 | LTFAT_REAL* tgrad; //!< Time gradient buffer 15 | LTFAT_REAL* fgrad; //!< Frequency gradient buffer 16 | LTFAT_REAL* phase; //!< Buffer for keeping previously computed frame 17 | double gamma; 18 | }; 19 | 20 | struct PHASERET_NAME(rtpghiupdate_plan) 21 | { 22 | LTFAT_NAME(heap)* h; 23 | int* donemask; 24 | double logtol; 25 | double tol; 26 | ltfat_int M; 27 | LTFAT_REAL* randphase; //!< Precomputed array of random phase 28 | ltfat_int randphaseLen; 29 | ltfat_int randphaseId; 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/src/rtpghifb_private.h: -------------------------------------------------------------------------------- 1 | #ifndef _PHASERET_RTPGHIFB_PRIVATE_H 2 | #define _PHASERET_RTPGHIFB_PRIVATE_H 3 | 4 | 5 | struct PHASERET_NAME(rtpghifb_state) 6 | { 7 | PHASERET_NAME(rtpghifbupdate_plan)* p; 8 | ltfat_int M; 9 | ltfat_int a; 10 | ltfat_int W; 11 | int do_causal; 12 | LTFAT_REAL* slog; 13 | LTFAT_REAL* fc; 14 | LTFAT_REAL* s; 15 | LTFAT_REAL* tgrad; //!< Time gradient buffer 16 | LTFAT_REAL* fgrad; //!< Frequency gradient buffer 17 | LTFAT_REAL* phase; //!< Buffer for keeping previously computed frame 18 | double gamma; 19 | }; 20 | 21 | struct PHASERET_NAME(rtpghifbupdate_plan) 22 | { 23 | LTFAT_NAME(heap)* h; 24 | int* donemask; 25 | double logtol; 26 | double tol; 27 | ltfat_int M; 28 | LTFAT_REAL* randphase; //!< Precomputed array of random phase 29 | ltfat_int randphaseLen; 30 | ltfat_int randphaseId; 31 | LTFAT_REAL* fc; 32 | }; 33 | 34 | #endif -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/testing/mUnit/complex2interleaved.m: -------------------------------------------------------------------------------- 1 | function fi = complex2interleaved(fc) 2 | 3 | if ~isnumeric(fc) 4 | error('%s: Input must be numeric.',upper(mfilename)) 5 | end 6 | 7 | fsize = size(fc); 8 | fsize(1)=fsize(1)*2; 9 | 10 | fi = zeros(fsize,class(fc)); 11 | 12 | fi(1:2:end,:,:) = real(fc); 13 | 14 | if ~isreal(fc) 15 | fi(2:2:end,:,:) = imag(fc); 16 | end -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/testing/mUnit/interleaved2complex.m: -------------------------------------------------------------------------------- 1 | function fc = interleaved2complex(fi) 2 | 3 | if ~isreal(fi) 4 | error('%s: Input must be real.',upper(mfilename)) 5 | end 6 | 7 | fsize = size(fi); 8 | fsize(1)=fsize(1)/2; 9 | 10 | if rem(fsize(1),1)~=0 11 | error('%s: Wrong dimension.',upper(mfilename)) 12 | end 13 | 14 | 15 | fc=fi(1:2:end,:,:) + 1i*fi(2:2:end,:,:); 16 | 17 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/testing/mUnit/test_libphaseret_gla.m: -------------------------------------------------------------------------------- 1 | 2 | f = greasy; 3 | a = 128; 4 | M = 1024; 5 | M2 = floor(M/2) + 1; 6 | gl = M; 7 | L = dgtlength(numel(f),a,M); 8 | g = firwin('blackman',gl); 9 | gd = long2fir(gabdual(g,a,M),gl); 10 | N = L/a; 11 | maxit = 100; 12 | 13 | corig = dgtreal(f,{'blackman',gl},a,M); 14 | s = abs(corig) + 1i*zeros(size(corig)); 15 | 16 | cinPtr = libpointer('doublePtr',complex2interleaved(s)); 17 | cout = zeros(2*M2,N); 18 | coutPtr = libpointer('doublePtr',cout); 19 | 20 | calllib('libphaseret','phaseret_gla_d',cinPtr,libpointer(),g,L,gl,1,a,M,maxit,coutPtr); 21 | 22 | cout2 = interleaved2complex(coutPtr.Value); 23 | 24 | frec = idgtreal(cout2,{'dual',{'blackman',gl}},a,M); 25 | 26 | s2 = dgtreal(frec,{'blackman',gl},a,M); 27 | magnitudeerrdb(s,s2) 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/testing/mUnit/test_libphaseret_gsrtisila.m: -------------------------------------------------------------------------------- 1 | ; 2 | f = gspi; 3 | a = 256; 4 | M = 2048; 5 | M2 = floor(M/2) + 1; 6 | gl = 2048; 7 | L = dgtlength(numel(f),a,M); 8 | win = 'hann'; 9 | g = firwin(win,gl); 10 | gd = long2fir(gabdual(g,a,M),gl); 11 | N = L/a; 12 | lookahead = 0; 13 | maxit = 16; 14 | 15 | corig = dgtreal(f,{win,gl},a,M,'timeinv'); 16 | s = abs(corig); 17 | 18 | cout = zeros(2*M2,N); 19 | coutPtr = libpointer('doublePtr',cout); 20 | 21 | calllib('libphaseret','phaseret_gsrtisilaoffline_d',s,g,L,gl,1,a,M,lookahead,maxit,coutPtr); 22 | 23 | coutsingle = zeros(2*M2,N,'single'); 24 | coutsinglePtr = libpointer('singlePtr',coutsingle); 25 | ssingle = cast(s,'single'); 26 | gsingle = cast(g,'single'); 27 | calllib('libphaseret','phaseret_gsrtisilaoffline_s',ssingle,gsingle,L,gl,1,a,M,lookahead,maxit,coutsinglePtr); 28 | 29 | 30 | coutsingle2 = interleaved2complex(coutsinglePtr.Value); 31 | cout2 = interleaved2complex(coutPtr.Value); 32 | 33 | 34 | frec = idgtreal(coutsingle2,{'dual',{win,gl}},a,M,'timeinv'); 35 | 36 | s2 = dgtreal(frec,{win,gl},a,M,'timeinv'); 37 | magnitudeerrdb(s,s2) 38 | 39 | 40 | 41 | c=gsrtisila(s,g,a,M,'lookahead',lookahead,'maxit',maxit,'timeinv'); 42 | frec = idgtreal(c,{'dual',{win,gl}},a,M,'timeinv'); 43 | magnitudeerrdb(s,dgtreal(frec,{win,gl},a,M,'timeinv')) 44 | 45 | 46 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/testing/mUnit/test_libphaseret_gsrtisilapghi.m: -------------------------------------------------------------------------------- 1 | f = gspi; 2 | a = 128; 3 | M = 2048; 4 | M2 = floor(M/2) + 1; 5 | gl = 2048; 6 | L = dgtlength(numel(f),a,M); 7 | g = firwin('hann',gl); 8 | gamma = 0.25645*gl^2; 9 | gd = long2fir(gabdual(g,a,M),gl); 10 | N = L/a; 11 | lookahead = 7; 12 | maxit = 1; 13 | 14 | corig = dgtreal(f,{'hann',gl},a,M,'timeinv'); 15 | s = abs(corig); 16 | 17 | cout = zeros(2*M2,N); 18 | coutPtr = libpointer('doublePtr',cout); 19 | 20 | coutsingle = zeros(2*M2,N,'single'); 21 | coutsinglePtr = libpointer('singlePtr',coutsingle); 22 | 23 | tic 24 | calllib('libphaseret','phaseret_gsrtisilapghioffline_d',s,g,L,gl,0,a,M,lookahead,maxit,... 25 | gamma, 1e-6, 0, coutPtr); 26 | toc 27 | 28 | coutsingle = zeros(2*M2,N,'single'); 29 | coutsinglePtr = libpointer('singlePtr',coutsingle); 30 | ssingle = cast(s,'single'); 31 | 32 | tic 33 | calllib('libphaseret','phaseret_gsrtisilapghioffline_s',ssingle,cast(g,'single'),L,gl,1,a,M,lookahead,maxit,... 34 | gamma, 1e-6, 0, coutsinglePtr); 35 | toc 36 | 37 | coutsingle2 = interleaved2complex(coutsinglePtr.Value); 38 | cout2 = interleaved2complex(coutPtr.Value); 39 | 40 | frec = idgtreal(coutsingle2,{'dual',{'hann',gl}},a,M,'timeinv'); 41 | 42 | s2 = abs(dgtreal(frec,{'hann',gl},a,M,'timeinv')); 43 | magnitudeerrdb(s,s2) 44 | 45 | 46 | 47 | c=gsrtisila(s,g,a,M,'lookahead',lookahead,'maxit',maxit,'timeinv','rtpghi',{gamma}); 48 | 49 | frec = idgtreal(c,{'dual',{'hann',gl}},a,M,'timeinv'); 50 | s3 = abs(dgtreal(frec,{'hann',gl},a,M,'timeinv')); 51 | magnitudeerrdb(s,s3) 52 | 53 | 54 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/testing/mUnit/test_libphaseret_legla.m: -------------------------------------------------------------------------------- 1 | [~,structs]=libphaseretprotofile; 2 | 3 | 4 | S = libstruct('phaseret_legla_init_params',struct()); 5 | calllib('libphaseret','phaseret_legla_init_params_defaults',S); 6 | 7 | 8 | f = greasy; 9 | a = 256; 10 | M = 2*1024; 11 | M2 = floor(M/2) + 1; 12 | gl = M; 13 | L = dgtlength(size(f,1),a,M); 14 | g = firwin('blackman',gl); 15 | gd = long2fir(gabdual(g,a,M),gl); 16 | N = L/a; 17 | maxit = 200; 18 | 19 | corig = dgtreal(f,{'blackman',gl},a,M); 20 | s = abs(corig) + 1i*zeros(size(corig)); 21 | cinitPtr = libpointer('doublePtr',complex2interleaved(s)); 22 | 23 | cout = zeros(2*M2,N); 24 | coutPtr = libpointer('doublePtr',cout); 25 | 26 | tic; 27 | calllib('libphaseret','phaseret_legla_d',cinitPtr,g,L,gl,1,a,M,maxit,coutPtr); 28 | toc; 29 | cout2 = interleaved2complex(coutPtr.Value); 30 | %cout2 = phaselockreal(cout2,a,M); 31 | 32 | 33 | frec = idgtreal(cout2,{'dual',{'blackman',gl}},a,M); 34 | s2 = dgtreal(frec,{'blackman',gl},a,M); 35 | magnitudeerrdb(s,s2) 36 | 37 | tic; 38 | cout2 = legla(s,g,a,M,'modtrunc','onthefly','flegla','maxit',maxit); 39 | toc; 40 | 41 | frec = idgtreal(cout2,{'dual',{'blackman',gl}},a,M); 42 | 43 | s2 = dgtreal(frec,{'blackman',gl},a,M); 44 | magnitudeerrdb(s,s2) 45 | 46 | clear S; 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/testing/mUnit/test_libphaseret_overlaynthframe.m: -------------------------------------------------------------------------------- 1 | function test_libphaseret_overlaynthframe 2 | f = greasy; 3 | a = 128; 4 | M = 1024; 5 | M2 = floor(M/2) + 1; 6 | gl = 1024; 7 | L = dgtlength(numel(f),a,M); 8 | g = firwin('hann',gl); 9 | gamma = 0.25645*gl^2; 10 | gd = long2fir(gabdual(g,a,M),gl); 11 | gshift = fftshift(g); 12 | N = 10; 13 | idx = 9; 14 | g2 = repmat(g.*gd,1,N); 15 | g1 = repmat(fftshift(g.*gd),1,N); 16 | cout = zeros(gl,1); 17 | coutPtr = libpointer('doublePtr',cout); 18 | 19 | calllib('libphaseret','phaseret_overlaynthframe_d',g1,gl,N,a,idx,coutPtr); 20 | 21 | [~,out2] = comp_overlayframes(g2,a,gl,idx); 22 | [~,out3orig] = overlayframes(g2,a,gl,idx); 23 | out1orig = M*coutPtr.Value; 24 | out3orig = out3orig*M; 25 | 26 | out1 = out1orig; 27 | out3 = out3orig; 28 | out1(out1orig==0) = 1; 29 | out1(out1<1e-6) = 1e-6; 30 | out3(out3orig==0) = 1; 31 | out3(out3<1e-6) = 1e-6; 32 | 33 | figure(1); plot([gshift./out1,gshift./out3]) 34 | 35 | 36 | 37 | function [partrec,frame] = overlayframes(cframes,a,M,n) 38 | 39 | N = size(cframes,2); 40 | bufLen = N*a - (a-1) + M-1; 41 | partrec = zeros(bufLen,1); 42 | 43 | startidx = ceil(M/2)-1; 44 | idxrange = startidx + [0:floor(M/2),-ceil(M/2)+1:-1]; 45 | for ii=0:N-1 46 | idx = ii*a + idxrange + 1; 47 | partrec(idx) = partrec(idx) + cframes(:,ii+1); 48 | end 49 | 50 | frame = partrec(a*n+1:a*n + M); 51 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/testing/mUnit/test_libphaseret_pghi.m: -------------------------------------------------------------------------------- 1 | 2 | f = greasy; 3 | a = 128; 4 | M = 1024; 5 | M2 = floor(M/2) + 1; 6 | gl = 1024; 7 | L = dgtlength(numel(f),a,M); 8 | g = firwin('hann',gl); 9 | gd = long2fir(gabdual(g,a,M),gl); 10 | N = L/a; 11 | 12 | 13 | corig = dgtreal(f,{'hann',gl},a,M,'timeinv'); 14 | s = abs(corig); 15 | cout = zeros(2*M2,N); 16 | coutPtr = libpointer('doublePtr',cout); 17 | gamma = gl^2*0.25645; 18 | calllib('libphaseret','phaseret_pghi_d',s,L,1,a,M,gamma,coutPtr); 19 | 20 | cout2 = interleaved2complex(coutPtr.Value); 21 | %cout2 = pghi(s,gamma,a,M,'timeinv'); 22 | 23 | frec = idgtreal(cout2,{'dual',{'hann',gl}},a,M,'timeinv'); 24 | 25 | s2 = dgtreal(frec,{'hann',gl},a,M,'timeinv'); 26 | magnitudeerrdb(s,s2) 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/testing/mUnit/test_libphaseret_rtisila.m: -------------------------------------------------------------------------------- 1 | clear all; 2 | f = greasy; 3 | a = 128; 4 | M = 1024; 5 | M2 = floor(M/2) + 1; 6 | gl = 1024; 7 | L = dgtlength(numel(f),a,M); 8 | g = firwin('hann',gl); 9 | gd = long2fir(gabdual(g,a,M),gl); 10 | N = L/a; 11 | lookahead = 0; 12 | maxit = 10; 13 | 14 | corig = dgtreal(f,{'hann',gl},a,M,'timeinv'); 15 | s = abs(corig); 16 | 17 | cout = zeros(2*M2,N); 18 | coutPtr = libpointer('doublePtr',cout); 19 | 20 | calllib('libphaseret','phaseret_rtisilaoffline_d',s,g,L,gl,1,a,M,lookahead,maxit,coutPtr); 21 | 22 | cout2 = interleaved2complex(coutPtr.Value); 23 | 24 | frec = idgtreal(cout2,{'dual',{'hann',gl}},a,M,'timeinv'); 25 | 26 | s2 = dgtreal(frec,{'hann',gl},a,M,'timeinv'); 27 | magnitudeerrdb(s,s2) 28 | 29 | 30 | 31 | c=rtisila(s,g,a,M,'lookahead',lookahead,'maxit',maxit,'timeinv'); 32 | frec = idgtreal(c,{'dual',{'hann',gl}},a,M,'timeinv'); 33 | magnitudeerrdb(s,dgtreal(frec,{'hann',gl},a,M,'timeinv')) 34 | 35 | plotdgtreal(abs(c-cout2),a,M,'linabs') 36 | 37 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/testing/mUnit/test_libphaseret_rtpghi.m: -------------------------------------------------------------------------------- 1 | clear all; 2 | f = cocktailparty; 3 | a = 128; 4 | M = 2048; 5 | M2 = floor(M/2) + 1; 6 | gl = 2048; 7 | L = dgtlength(numel(f),a,M); 8 | g = firwin('hann',gl); 9 | gd = long2fir(gabdual(g,a,M),gl); 10 | N = L/a; 11 | 12 | 13 | corig = dgtreal(f,{'hann',gl},a,M,'timeinv'); 14 | s = abs(corig); 15 | cout = zeros(2*M2,N); 16 | coutPtr = libpointer('doublePtr',cout); 17 | gamma = gl^2*0.25645; 18 | 19 | tic 20 | calllib('libphaseret','phaseret_rtpghioffline_d',s,L,1,a,M,gamma,1e-6,1,coutPtr); 21 | t = toc; 22 | t/N*1000 23 | 24 | coutsingle = zeros(2*M2,N,'single'); 25 | coutsinglePtr = libpointer('singlePtr',coutsingle); 26 | 27 | ssingle = cast(s,'single'); 28 | 29 | tic 30 | calllib('libphaseret','phaseret_rtpghioffline_s',ssingle,L,1,a,M,gamma,1e-6,1,coutsinglePtr); 31 | t =toc; 32 | t/N*1000 33 | 34 | coutsingle2 = interleaved2complex(coutsinglePtr.Value); 35 | cout2 = interleaved2complex(coutPtr.Value); 36 | 37 | 38 | frec = idgtreal(coutsingle2,{'dual',{'hann',gl}},a,M,'timeinv'); 39 | s2 = dgtreal(frec,{'hann',gl},a,M,'timeinv'); 40 | magnitudeerrdb(s,s2) 41 | 42 | 43 | cout2 = rtpghi(s,gamma,a,M,'timeinv','tol',1e-6,'causal'); 44 | 45 | frec = idgtreal(cout2,{'dual',{'hann',gl}},a,M,'timeinv'); 46 | s2 = dgtreal(frec,{'hann',gl},a,M,'timeinv'); 47 | magnitudeerrdb(s,s2) 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /libltfat/modules/libphaseret/testing/mUnit/test_libphaseret_spsi.m: -------------------------------------------------------------------------------- 1 | clear all; 2 | f = gspi; 3 | a = 256; 4 | M = 1024; 5 | M2 = floor(M/2) + 1; 6 | gl = 1024; 7 | L = dgtlength(numel(f),a,M); 8 | g = firwin('blackman',gl); 9 | gd = long2fir(gabdual(g,a,M),gl); 10 | N = L/a; 11 | 12 | 13 | corig = dgtreal(f,{'hann',gl},a,M,'timeinv'); 14 | s = abs(corig); 15 | cout = zeros(2*M2,N); 16 | cout(1:numel(s)) = s(:); 17 | coutPtr = libpointer('doublePtr',cout); 18 | calllib('libphaseret','phaseret_spsi_d',coutPtr,L,1,a,M,libpointer(),coutPtr); 19 | 20 | %cout2 = interleaved2complex(coutPtr.Value); 21 | cout2 = spsi(s,a,M,'timeinv'); 22 | 23 | frec = idgtreal(cout2,{'dual',{'hann',gl}},a,M,'timeinv'); 24 | 25 | s2 = dgtreal(frec,{'hann',gl},a,M,'timeinv'); 26 | magnitudeerrdb(s,s2) 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /libltfat/ostools.mk: -------------------------------------------------------------------------------- 1 | #This file produces system and environment dependent tools for working with files 2 | #It sets the following variables 3 | # 4 | # RM 5 | # CP 6 | 7 | ifeq ($(OS),Windows_NT) 8 | $(info Windows detected) 9 | MINGW = 1 10 | RM = del /Q /F 11 | CP = copy /Y 12 | MKDIR = md 13 | RMDIR = rmdir /S /Q 14 | PS2 = \\ 15 | PS = $(strip $(PS2)) 16 | CC = gcc 17 | ifndef SHELL 18 | ifdef ComSpec 19 | SHELL := $(ComSpec) 20 | endif 21 | ifdef COMSPEC 22 | SHELL := $(COMSPEC) 23 | endif 24 | endif 25 | else 26 | #If not on Windows 27 | RM = rm -rf 28 | CP = cp -f 29 | PS = / 30 | MKDIR = mkdir -p 31 | RMDIR = $(RM) 32 | endif 33 | 34 | #CC=gcc 35 | -------------------------------------------------------------------------------- /mat2doc/conf.py: -------------------------------------------------------------------------------- 1 | # Mandatory settings 2 | outputdir='~/publish/mat2doc_publish' 3 | plotengine='matlab' 4 | versionfile="phaseret_version" 5 | 6 | # Optional global settings 7 | author=u'Zdenek Prusa' 8 | year="2018" 9 | octtitle="phaseret >> Phase Retrieval Toolbox" 10 | addonbase='~/Dropbox' 11 | 12 | # Settings used by scripts just for this project 13 | username='susnak' 14 | 15 | -------------------------------------------------------------------------------- /mat2doc/copyrightplate: -------------------------------------------------------------------------------- 1 | This program is free software: you can redistribute it and/or modify 2 | it under the terms of the GNU General Public License as published by 3 | the Free Software Foundation, either version 3 of the License, or 4 | (at your option) any later version. 5 | 6 | This program is distributed in the hope that it will be useful, 7 | but WITHOUT ANY WARRANTY; without even the implied warranty of 8 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 | GNU General Public License for more details. 10 | 11 | You should have received a copy of the GNU General Public License 12 | along with this program. If not, see . 13 | -------------------------------------------------------------------------------- /mat2doc/generatetitle.m: -------------------------------------------------------------------------------- 1 | [f,fs] = greasy; 2 | Ls = numel(f); 3 | 4 | a = 16; 5 | M = 1024; 6 | M2 = floor(M/2) + 1; 7 | thr = 1e-1; 8 | thr2 = 1e-10;%1e-10; 9 | 10 | L=dgtlength(Ls,a,M); 11 | b = L/M; 12 | N = L/a; 13 | 14 | ggauss = 'gauss'; 15 | 16 | 17 | c = dgtreal(f,ggauss,a,M,'timeinv'); 18 | cfreq = dgtreal(f,ggauss,a,M,'freqinv'); 19 | s = abs(c); 20 | 21 | chat = constructphasereal(abs(c),ggauss,a,M,[thr,thr2],'timeinv'); 22 | HEAPINTtime = toc; 23 | 24 | figure(1); 25 | plotdgtreal(s,a,M,'fs',fs,'dynrange',80); 26 | title('Spectrogram'); 27 | print(gcf,'images/title_greasy.png','-r72','-dpng'); 28 | 29 | fhatHeapint = idgtreal(chat,{'dual',g},a,M,numel(f),'timeinv'); 30 | nextprojc = dgtreal(fhatHeapint,g,a,M,'timeinv'); 31 | EheapintF = magnitudeerrdb(s,nextprojc) 32 | 33 | figure(2); 34 | plotdgtrealphasediff(angle(c),angle(chat),s,thr2,a,M,'fs',fs); 35 | title('Phase difference'); 36 | shg 37 | 38 | print(gcf,'images/title_greasy_diff.png','-r72','-dpng'); 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /mat2doc/html/conf.py: -------------------------------------------------------------------------------- 1 | fext = '.html' 2 | urlbase = '#BASEURL#/phaseret/doc' 3 | urlext = '.html' 4 | widthstr = '' 5 | imagetype = 'png' 6 | 7 | extlinks = {'dgtreal': 'http://ltfat.github.io/doc/gabor/dgtreal.html', 8 | 'idgtreal': 'http://ltfat.github.io/doc/gabor/idgtreal.html', 9 | 'gabdual': 'http://ltfat.github.io/doc/gabor/gabdual.html', 10 | 'gabwin': 'http://ltfat.github.io/doc/gabor/gabwin.html', 11 | 'firwin': 'http://ltfat.github.io/doc/sigproc/firwin.html', 12 | 'constructphasereal': 'http://ltfat.github.io/doc/gabor/constructphasereal.html', 13 | 'minFunc': 'https://www.cs.ubc.ca/~schmidtm/Software/minFunc.html', 14 | 'plotdgtreal': 'http://ltfat.github.io/doc/gabor/plotdgtreal.html', 15 | 'pgauss': 'http://ltfat.github.io/doc/fourier/pgauss.html', 16 | 'frsynabs': 'http://ltfat.github.io/doc/frames/frsynabs.html' 17 | } 18 | -------------------------------------------------------------------------------- /mat2doc/html/include/docnav.html: -------------------------------------------------------------------------------- 1 |

6 | 7 | -------------------------------------------------------------------------------- /mat2doc/html/include/macros.js: -------------------------------------------------------------------------------- 1 | window.MathJax = { 2 | TeX: { 3 | Macros: { 4 | stime: "t", 5 | sfreq: "\\omega", 6 | sfreqarg: "\\xi", 7 | stimearg: "\\tau", 8 | me: "\\mathrm{e}", 9 | mi: "\\mathrm{i}", 10 | } 11 | } 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /mat2doc/html/template.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | {TITLE} 9 | 10 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 |
23 |
24 |
25 |
{SWITCHVIEW}
26 |
This is where navigation should be.
27 |
28 |
29 |
30 |
31 |

{SEEALSO}

32 |
33 |
34 | 35 | {CONTENT} 36 | 37 |
38 |
39 |
40 | 41 | 42 | 43 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /mat2doc/images/phaseret2_common.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltfat/phaseret/9befaf30936e2413b3dceac8fc1e0a3442f58320/mat2doc/images/phaseret2_common.png -------------------------------------------------------------------------------- /mat2doc/images/phaseret2_gsrtisila.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltfat/phaseret/9befaf30936e2413b3dceac8fc1e0a3442f58320/mat2doc/images/phaseret2_gsrtisila.png -------------------------------------------------------------------------------- /mat2doc/images/phaseret2_proposed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltfat/phaseret/9befaf30936e2413b3dceac8fc1e0a3442f58320/mat2doc/images/phaseret2_proposed.png -------------------------------------------------------------------------------- /mat2doc/images/phaseret2_rtisila.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltfat/phaseret/9befaf30936e2413b3dceac8fc1e0a3442f58320/mat2doc/images/phaseret2_rtisila.png -------------------------------------------------------------------------------- /mat2doc/images/phaseret2_rtpghi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltfat/phaseret/9befaf30936e2413b3dceac8fc1e0a3442f58320/mat2doc/images/phaseret2_rtpghi.png -------------------------------------------------------------------------------- /mat2doc/images/phaseret_rtisi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltfat/phaseret/9befaf30936e2413b3dceac8fc1e0a3442f58320/mat2doc/images/phaseret_rtisi.png -------------------------------------------------------------------------------- /mat2doc/images/phaseret_rtpghi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltfat/phaseret/9befaf30936e2413b3dceac8fc1e0a3442f58320/mat2doc/images/phaseret_rtpghi.png -------------------------------------------------------------------------------- /mat2doc/images/phaseret_spsi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltfat/phaseret/9befaf30936e2413b3dceac8fc1e0a3442f58320/mat2doc/images/phaseret_spsi.png -------------------------------------------------------------------------------- /mat2doc/images/phaseretmix_default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltfat/phaseret/9befaf30936e2413b3dceac8fc1e0a3442f58320/mat2doc/images/phaseretmix_default.png -------------------------------------------------------------------------------- /mat2doc/images/phaseretmix_pghi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltfat/phaseret/9befaf30936e2413b3dceac8fc1e0a3442f58320/mat2doc/images/phaseretmix_pghi.png -------------------------------------------------------------------------------- /mat2doc/images/phaseretmix_rtisi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltfat/phaseret/9befaf30936e2413b3dceac8fc1e0a3442f58320/mat2doc/images/phaseretmix_rtisi.png -------------------------------------------------------------------------------- /mat2doc/images/phaseretmix_spsi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltfat/phaseret/9befaf30936e2413b3dceac8fc1e0a3442f58320/mat2doc/images/phaseretmix_spsi.png -------------------------------------------------------------------------------- /mat2doc/images/title_greasy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltfat/phaseret/9befaf30936e2413b3dceac8fc1e0a3442f58320/mat2doc/images/title_greasy.png -------------------------------------------------------------------------------- /mat2doc/images/title_greasy_diff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltfat/phaseret/9befaf30936e2413b3dceac8fc1e0a3442f58320/mat2doc/images/title_greasy_diff.png -------------------------------------------------------------------------------- /mat2doc/make_packages.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd .. 3 | make -C mex -f Makefile_crossmingw 4 | /home/susnak/dev/mat2doc/mat2doc.py . mat --tgz --unix --script=release.py --packagename=phaseret-%s-src 5 | /home/susnak/dev/mat2doc/mat2doc.py . mat --zip --dos --addon=phaseret_win64 --packagename=phaseret-%s-win64 --script=release.py 6 | /home/susnak/dev/mat2doc/mat2doc.py . html 7 | 8 | 9 | -------------------------------------------------------------------------------- /mat2doc/mat/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Name: PHASERET 2 | Version: {VERSION} 3 | Date: {DATE} 4 | Author: Zdenek Prusa 5 | Maintainer: Zdenek Prusa 6 | Title: Phase Retrieval Toolbox 7 | Description: The phase retrieval toolbox is a collection 8 | of STFT phase retrieval algorithms. 9 | License: GPLv3+ 10 | Depends: octave (>= 3.8.0), ltfat (>= 2.1.2) 11 | BuildRequires: fftw3 [Debian] libfftw3-3 12 | Url: http://ltfat.github.io/phaseret 13 | -------------------------------------------------------------------------------- /mat2doc/mat/conf.py: -------------------------------------------------------------------------------- 1 | fext='.m' 2 | urlbase='http://ltfat.github.io/phaseret/doc' 3 | urlext='.html' 4 | 5 | # Option for the Octave package 6 | builddir='~/build/' 7 | -------------------------------------------------------------------------------- /mat2doc/mat/header.m: -------------------------------------------------------------------------------- 1 | % Copyright (C) 2018 Zdenek Prusa . 2 | % This file is part of PHASERET version {VERSION} 3 | % 4 | % This program is free software: you can redistribute it and/or modify 5 | % it under the terms of the GNU General Public License as published by 6 | % the Free Software Foundation, either version 3 of the License, or 7 | % (at your option) any later version. 8 | % 9 | % This program is distributed in the hope that it will be useful, 10 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | % GNU General Public License for more details. 13 | % 14 | % You should have received a copy of the GNU General Public License 15 | % along with this program. If not, see . 16 | -------------------------------------------------------------------------------- /mat2doc/mat/release.py: -------------------------------------------------------------------------------- 1 | print("Creating downloadable package") 2 | 3 | # s=os.path.join(conf.t.dir,'doxygen') 4 | # rmrf(s) 5 | # os.rmdir(s) 6 | 7 | 8 | # Recursively remove the .git files 9 | for root, dirs, files in os.walk(conf.t.dir, topdown=False): 10 | for name in files: 11 | if name in ['.gitattributes','.gitignore','desktop.ini']: 12 | os.remove(os.path.join(root, name)) 13 | 14 | 15 | -------------------------------------------------------------------------------- /mat2doc/nodocs: -------------------------------------------------------------------------------- 1 | mat2doc_publish 2 | libphaseret 3 | libltfat 4 | -------------------------------------------------------------------------------- /mat2doc/startup.m: -------------------------------------------------------------------------------- 1 | addpath ~/dev/ltfat 2 | addpath ~/dev/phaseret 3 | addpath ~/dev/minFunc/ 4 | 5 | 6 | ltfatstart; 7 | phaseretstart; 8 | 9 | -------------------------------------------------------------------------------- /mex/Makefile: -------------------------------------------------------------------------------- 1 | # MEX 2 | # 3 | MATLABROOT?=/usr/local/MATLAB_R2018a 4 | ARCH?=glnxa64 5 | EXT?=mexa64 6 | MEXCFLAGS?=-I"$(MATLABROOT)/extern/include" 7 | MEXLFLAGS?= -L"$(MATLABROOT)/bin/$(ARCH)" -lmex -lmx 8 | FFTW_LIBS ?= -lfftw3 9 | 10 | MEXSOURCES = $(wildcard *.c) 11 | MEXTARGETS = $(patsubst %.c,%.$(EXT),$(MEXSOURCES)) 12 | OCTAVEMEXTARGETS = $(patsubst %.c,%.mex,$(MEXSOURCES)) 13 | 14 | export TARGETUP = ../libltfat/build/libphaseretd.a ../libltfat/build/libltfatd.a 15 | 16 | MYCFLAGS =-std=c99 -Wall -Wextra -fPIC -shared 17 | 18 | ifeq ($(COMPTARGET), debug) 19 | MYCFLAGS+=-O0 -g 20 | else 21 | MYCFLAGS+=-O2 -DNDEBUG 22 | endif 23 | 24 | # MATLAB MEX files, only works if there are no spaces in the path to Matlab 25 | MYCFLAGS+=-DLTFAT_BUILD_STATIC -DMATLAB_MEXCMD_RELEASE=R2017b 26 | MYCFLAGS+=-DMATLAB_MEX_FILE -DLTFAT_LARGEARRAYS 27 | MYCFLAGS+=-I../libltfat/modules/libltfat/include -I../libltfat/modules/libphaseret/include 28 | # matlab: MBIN = $(shell matlab -nojvm -nodisplay -nosplash -r "disp([matlabroot,filesep,'bin',filesep,computer('arch'),filesep]);exit;" | grep /bin/) 29 | # matlab: MWFFTWLIB = $(shell ls $(MBIN)*fftw3.* | head -n 1) 30 | matlab: $(MEXTARGETS) 31 | 32 | # This appends the correct suffix anyway 33 | # and also only supresses warnings from mex (about old compiler) but not from 34 | # the compiler itself. 35 | %.$(EXT) : %.c 36 | $(CC) $(MYCFLAGS) $(MEXCFLAGS) $< -o $@ $(TARGETUP) $(MEXLFLAGS) $(FFTW_LIBS) -lm 37 | 38 | # OCTAVE MEX files 39 | # := $(shell ...) runs shell immediatelly even if we do not use the octave 40 | # target at all 41 | octave: MKOCTFILE ?= mkoctfile 42 | octave: FFTW_LIBS = $(shell $(MKOCTFILE) -p FFTW_LIBS) 43 | octave: export CFLAGS = $(shell $(MKOCTFILE) -p CFLAGS) $(MYCFLAGS) 44 | octave: export LFLAGS = $(shell $(MKOCTFILE) -p LFLAGS) $(TARGETUP) $(FFTW_LIBS) -lm 45 | octave: $(OCTAVEMEXTARGETS) 46 | 47 | %.mex: %.c 48 | $(MKOCTFILE) --mex -o $@ $< 49 | 50 | .PHONY: clean matlab octave 51 | 52 | clean: 53 | @rm -rf *.mex* 54 | @rm -rf *.o 55 | -------------------------------------------------------------------------------- /mex/Makefile_crossmingw: -------------------------------------------------------------------------------- 1 | outdir = /home/susnak/Dropbox/phaseret_win64/mex 2 | export CROSS=x86_64-w64-mingw32.shared- 3 | export MINGW=1 4 | export NOBLASLAPACK=1 5 | export EXT=mexw64 6 | export MAKECMDGOALS=static 7 | MEXDIR = /home/susnak/Dropbox/win64libs 8 | 9 | all: clean libltfat libphaseret odir fftw mex clean 10 | 11 | libltfat: 12 | (cd ../libltfat ; make MODULE=libltfat cleanobj ) 13 | (cd ../libltfat ; make static MODULE=libltfat OPTCFLAGS=-DLTFAT_LARGEARRAYS ) 14 | 15 | libphaseret: 16 | (cd ../libltfat ; make MODULE=libphaseret cleanobj ) 17 | (cd ../libltfat ; make static MODULE=libphaseret OPTCFLAGS=-DLTFAT_LARGEARRAYS) 18 | 19 | odir: 20 | mkdir -p $(outdir) 21 | 22 | fftw: 23 | cp $(MEXDIR)/libfftw3-*.dll $(outdir) 24 | 25 | mex: 26 | make -f Makefile_mingw MEXCOMPFLAGS="-I$(MEXDIR)" MEXLINKFLAGS="-L$(MEXDIR) -lmex -lmx -L$(outdir) -L../libltfat/build/$(CROSS)" 27 | cp *.$(EXT) $(outdir) 28 | 29 | clean: 30 | make -C ../libltfat clean 31 | # make -C ../libphaseret clean 32 | -rm *.o 33 | -rm *.$(EXT) 34 | 35 | 36 | -------------------------------------------------------------------------------- /mex/Makefile_mingw: -------------------------------------------------------------------------------- 1 | # To run this makefile, you must provide your system specific EXT and MATLABROOT 2 | # variables on the command line e.g.: 3 | # 4 | # make -f Makefile_mingw MATLABROOT="C:\Program Files\MATLAB\R2011b" EXT=mexw64 ARCH=win64 FFTWLIB="-Lc:/dll -lfftw3-3" 5 | # make -f Makefile_mingw CROSS=x86_64-w64-mingw32.shared- MEXCOMPFLAGS="-I/home/susnak/Dropbox/win64libs" MEXLINKFLAGS="-L/home/susnak/Dropbox/win64libs -lmex -lmx" 6 | # 7 | ifdef CROSS 8 | CC = $(CROSS)gcc 9 | AR = $(CROSS)ar 10 | RANLIB =ranlib 11 | MINGW=1 12 | TARGETUP = -lphaseretd -lltfatd 13 | else 14 | CC ?= gcc 15 | AR ?= ar 16 | RANLIB?=ranlib 17 | TARGETUP = ../libltfat/build/libphaseretd.a ../libltfat/build/libltfatd.a 18 | endif 19 | 20 | include ../libltfat/ostools.mk 21 | 22 | ifndef MATLABROOT 23 | $(warning MATLABROOT variable is undefined. Using default MATLABROOT="C:\Program Files\MATLAB\R2011b" ) 24 | MATLABROOT=C:\Program Files\MATLAB\R2011b 25 | endif 26 | 27 | ifndef EXT 28 | $(warning EXT variable is undefined. Using default EXT=mexw64 ) 29 | EXT=mexw64 30 | endif 31 | 32 | ifndef ARCH 33 | $(warning ARCH variable is undefined. Using default ARCH=win64 ) 34 | ARCH=win64 35 | endif 36 | 37 | FFTW_LIBS?=-lfftw3-3 38 | 39 | # MEX 40 | MEXSOURCES = $(wildcard *.c) 41 | MEXTARGETS = $(patsubst %.c,%.$(EXT),$(MEXSOURCES)) 42 | 43 | CFLAGS =-shared -s -Wall -std=c99 44 | CFLAGS+=-I../libltfat/modules/libltfat/include -I../libltfat/modules/libphaseret/include 45 | CFLAGS+=-DLTFAT_BUILD_STATIC -DMATLAB_MEXCMD_RELEASE=R2017b 46 | CFLAGS+=-DMATLAB_MEX_FILE -DLTFAT_LARGEARRAYS 47 | 48 | ifeq ($(COMPTARGET), debug) 49 | CFLAGS += -O0 -g 50 | else 51 | CFLAGS += -O2 -DNDEBUG 52 | endif 53 | 54 | MEXCOMPFLAGS?=-I"$(MATLABROOT)\extern\include" 55 | MEXLINKFLAGS?=-L"$(MATLABROOT)\bin\$(ARCH)" -lmex -lmx 56 | 57 | matlab: $(MEXTARGETS) 58 | 59 | %.$(EXT): %.c 60 | $(CC) $(CFLAGS) $(MEXCOMPFLAGS) $< -o $@ -Wl,--dll -L./ $(MEXLINKFLAGS) $(TARGETUP) $(FFTW_LIBS) -static-libgcc 61 | 62 | clean: 63 | del /Q /F *.$(EXT) 64 | del /Q /F *.o 65 | 66 | .PHONY: all clean 67 | -------------------------------------------------------------------------------- /mex/comp_rtpghifbupdate.c: -------------------------------------------------------------------------------- 1 | /** \addtogroup mex 2 | * \{ 3 | * \file 4 | * \brief MEX file interface for spsi() 5 | * 6 | * **This is a computaional routine. The input arguments are not checked for correctness!!** 7 | * 8 | * Matlab calling convention: 9 | * -------------------------- 10 | * 11 | * [phase] = comp_rtpghifbupdate(slog,fc, tgrad, fgrad, prevphase, tol, M) 12 | * 13 | * Input arg. | Description 14 | * ------------ | ------------------------------------------------------------- 15 | * slog | M2 x 2 real matrix, tarhet magnitude 16 | * fc | M2 x 1 real 17 | * tgrad | M2 x 2 real 18 | * fgrad | M2 x 1 real 19 | * prevphase | M2 x 1 real 20 | * tol | scalar 21 | * M | Number of channels (FFT length) 22 | * 23 | * Output arg. | Description 24 | * ----------- | ------------------------------------------------------------- 25 | * phase | M2 x 1 real 26 | * 27 | * \author Clara Hollomey 28 | * \date 12.05.2023 29 | * \} 30 | */ 31 | 32 | #include "mex_helper.h" 33 | #define LTFAT_DOUBLE 34 | #include "phaseret/rtpghifb.h" 35 | #include "../libltfat/modules/libphaseret/src/rtpghifb_private.h" 36 | 37 | void 38 | mexFunction(int nlhs, mxArray* plhs[], 39 | int nrhs, const mxArray* prhs[]) 40 | { 41 | UNUSED(nrhs); UNUSED(nlhs); 42 | double* slog = mxGetData(prhs[0]); 43 | double* fc = mxGetData(prhs[1]); 44 | double* tgrad = mxGetData(prhs[2]); 45 | double* fgrad = mxGetData(prhs[3]); 46 | double* prevphase = mxGetData(prhs[4]); 47 | double tol = mxGetScalar(prhs[5]); 48 | mwSignedIndex M = (mwSignedIndex) mxGetScalar(prhs[6]); 49 | 50 | 51 | plhs[0] = mxCreateDoubleMatrix(M, 1, mxREAL); 52 | double* phase = mxGetData(plhs[0]); 53 | 54 | 55 | phaseret_rtpghifbupdate_plan_d* plan = NULL; 56 | phaseret_rtpghifbupdate_init_d(M,1, fc, tol,&plan); 57 | phaseret_rtpghifbupdate_execute_d(plan, slog, fc, tgrad, fgrad, prevphase, phase); 58 | phaseret_rtpghifbupdate_done_d(&plan); 59 | } 60 | 61 | -------------------------------------------------------------------------------- /mex/comp_rtpghiupdate.c: -------------------------------------------------------------------------------- 1 | /** \addtogroup mex 2 | * \{ 3 | * \file 4 | * \brief MEX file interface for spsi() 5 | * 6 | * **This is a computaional routine. The input arguments are not checked for correctness!!** 7 | * 8 | * Matlab calling convention: 9 | * -------------------------- 10 | * 11 | * [c,endphase] = comp_spsi(s,a,M[,startphase]) 12 | * 13 | * Input arg. | Description 14 | * ------------ | ------------------------------------------------------------- 15 | * slog | M2 x 2 real matrix, tarhet magnitude 16 | * tgrad | M2 x 2 real 17 | * fgrad | M2 x 1 real 18 | * prevphase | M2 x 1 real 19 | * tol | scalar 20 | * M | Number of channels (FFT length) 21 | * 22 | * Output arg. | Description 23 | * ----------- | ------------------------------------------------------------- 24 | * phase | M2 x 1 real 25 | * 26 | * \author Zdeněk Průša 27 | * \date 17.02.2016 28 | * \} 29 | */ 30 | 31 | 32 | #include "mex_helper.h" 33 | #define LTFAT_DOUBLE 34 | #include "phaseret/rtpghi.h" 35 | 36 | void 37 | mexFunction(int nlhs, mxArray* plhs[], 38 | int nrhs, const mxArray* prhs[]) 39 | { 40 | UNUSED(nrhs); UNUSED(nlhs); 41 | double* slog = mxGetData(prhs[0]); 42 | double* tgrad = mxGetData(prhs[1]); 43 | double* fgrad = mxGetData(prhs[2]); 44 | double* prevphase = mxGetData(prhs[3]); 45 | double tol = mxGetScalar(prhs[4]); 46 | mwSignedIndex M = (mwSignedIndex) mxGetScalar(prhs[5]); 47 | mwSignedIndex M2 = M / 2 + 1; 48 | 49 | plhs[0] = mxCreateDoubleMatrix(M2, 1, mxREAL); 50 | double* phase = mxGetData(plhs[0]); 51 | 52 | phaseret_rtpghiupdate_plan_d* plan = NULL; 53 | phaseret_rtpghiupdate_init_d(M,1,tol,&plan); 54 | phaseret_rtpghiupdate_execute_d(plan, slog, tgrad, fgrad, prevphase, phase); 55 | phaseret_rtpghiupdate_done_d(&plan); 56 | } 57 | -------------------------------------------------------------------------------- /mex/comp_spsi.c: -------------------------------------------------------------------------------- 1 | /** \addtogroup mex 2 | * \{ 3 | * \file 4 | * \brief MEX file interface for spsi() 5 | * 6 | * **This is a computaional routine. The input arguments are not checked for correctness!!** 7 | * 8 | * Matlab calling convention: 9 | * -------------------------- 10 | * 11 | * [c,endphase] = comp_spsi(s,a,M[,startphase]) 12 | * 13 | * Input arg. | Description 14 | * ------------ | ------------------------------------------------------------- 15 | * s | M2 x N real matrix, tarhet magnitude 16 | * a | Hop factor 17 | * M | Number of channels (FFT length) 18 | * startphase | (optional) Length M2 vector, phase of -1 col 19 | * 20 | * Output arg. | Description 21 | * ----------- | ------------------------------------------------------------- 22 | * c | M2 x N complex coefficients 23 | * endphase | length M2 vector phase of N-1 col 24 | * 25 | * \author Zdeněk Průša 26 | * \date 17.02.2016 27 | * \} 28 | */ 29 | 30 | 31 | #include "mex_helper.h" 32 | #define LTFAT_DOUBLE 33 | #include "phaseret/spsi.h" 34 | 35 | void 36 | mexFunction(int nlhs, mxArray* plhs[], 37 | int nrhs, const mxArray* prhs[]) 38 | { 39 | UNUSED(nrhs); 40 | double* s, *cr, *ci, *initphase = (void*) 0; 41 | mwSignedIndex N, M, a, M2; 42 | a = (mwSignedIndex) mxGetScalar(prhs[1]); 43 | M = (mwSignedIndex) mxGetScalar(prhs[2]); 44 | M2 = M / 2 + 1; 45 | N = mxGetN(prhs[0]); 46 | s = mxGetData(prhs[0]); 47 | 48 | if (nrhs > 3) 49 | initphase = mxGetData(prhs[3]); 50 | 51 | plhs[0] = mxCreateDoubleMatrix(M2, N, mxCOMPLEX); 52 | cr = mxGetData(plhs[0]); 53 | ci = mxGetImagData(plhs[0]); 54 | 55 | double complex* cc = mxMalloc( M2 * N * sizeof * cc); 56 | 57 | phaseret_spsi_d(s, N*a, 1, a, M, initphase, cc); 58 | 59 | complex2split(cc, M2 * N, cr, ci); 60 | 61 | if (nlhs > 1) 62 | { 63 | plhs[1] = mxCreateDoubleMatrix(M2, 1, mxREAL); 64 | double* endphase = mxGetData(plhs[1]); 65 | memcpy(endphase, initphase, M2 * sizeof * initphase); 66 | } 67 | 68 | mxFree(cc); 69 | } 70 | -------------------------------------------------------------------------------- /mex/mex_helper.h: -------------------------------------------------------------------------------- 1 | #ifndef _mex_helper_h 2 | #define _mex_helper_h 3 | 4 | #include 5 | // #ifdef __STDC_UTF_16__ 6 | // #include 7 | // #endif 8 | 9 | #ifndef MATLAB_MEX_FILE 10 | #define MATLAB_MEX_FILE 11 | #endif 12 | 13 | #include "mex.h" 14 | 15 | // Compatibility for pre-2017b 16 | #ifndef MX_HAS_INTERLEAVED_COMPLEX 17 | #define MX_HAS_INTERLEAVED_COMPLEX 0 18 | #endif 19 | 20 | #ifndef UNUSED 21 | #define UNUSED(expr) do { (void)(expr); } while (0) 22 | #endif 23 | 24 | void 25 | complex2split(const complex double* in, int L, double* outr, double* outi) 26 | { 27 | if(outi) 28 | { 29 | for (int ii = 0; ii < L; ++ii) 30 | { 31 | outr[ii] = creal(in[ii]); 32 | outi[ii] = cimag(in[ii]); 33 | } 34 | } 35 | else 36 | { 37 | for (int ii = 0; ii < L; ++ii) 38 | { 39 | outr[ii] = creal(in[ii]); 40 | } 41 | } 42 | 43 | } 44 | 45 | void 46 | split2complex(const double* inr, const double* ini, int L, complex double* out) 47 | { 48 | 49 | if(ini) 50 | { 51 | for (int ii = 0; ii < L; ++ii) 52 | { 53 | out[ii] = inr[ii] + I*ini[ii]; 54 | } 55 | } 56 | else 57 | { 58 | for (int ii = 0; ii < L; ++ii) 59 | { 60 | double* out2 = (double*) out; 61 | out2[2*ii] = inr[ii]; 62 | out2[2*ii+1] = 0.0; 63 | } 64 | } 65 | 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /mex/mexinit.m: -------------------------------------------------------------------------------- 1 | status = 1; 2 | -------------------------------------------------------------------------------- /mex/phaseret_dummymex.c: -------------------------------------------------------------------------------- 1 | #include "mex_helper.h" 2 | 3 | void 4 | mexFunction(int nlhs, mxArray* plhs[], 5 | int nrhs, const mxArray* prhs[]) 6 | { 7 | UNUSED(nlhs);UNUSED(nrhs);UNUSED(prhs); 8 | plhs[0] = mxCreateString("mexok"); 9 | } 10 | -------------------------------------------------------------------------------- /phaseret_version: -------------------------------------------------------------------------------- 1 | 0.2.3 2 | -------------------------------------------------------------------------------- /test_rtpghifb.m: -------------------------------------------------------------------------------- 1 | clear all 2 | clc 3 | 4 | tol=1e-10; 5 | [f,fs] = gspi; 6 | 7 | Ls = length(f); 8 | scales = 2.^(linspace(6,-3.3,200)); 9 | [g,a,fc,L, info]=waveletfilters(Ls,scales, 'repeat', 'uniform'); 10 | corig = ufilterbank(f,g,a); 11 | 12 | [c,newphase,tgrad,fgrad]=rtpghifbwl(abs(corig.'),a(1),info.fc,info.tfr); 13 | 14 | c = c.'; 15 | Emags = magnitudeerrdb(corig,c) % Foolproofing 16 | 17 | gd = filterbankrealdual(g,a,L); 18 | f_rec_rtpghi = ifilterbank(c,gd,a,'real'); 19 | c_rec_rtpghi = ufilterbank(f_rec_rtpghi,g,a); 20 | Emags_rtpghi = magnitudeerrdb(corig,c_rec_rtpghi) 21 | 22 | -------------------------------------------------------------------------------- /tests/test_all_phaseret.m: -------------------------------------------------------------------------------- 1 | function test_all_phaseret 2 | 3 | testprefix = 'testphaseret_'; 4 | tests_todo = { 'gla','legla','spsi','rtpghi','pghi','decolbfgs',... 5 | 'rtisila','gsrtisila','lertisila','phaseretdemos' }; 6 | 7 | total_tests_failed=0; 8 | list_of_failed_tests={}; 9 | 10 | preccell = {'double'}; 11 | 12 | for precId = 1:length(preccell) 13 | prec = preccell{precId}; 14 | 15 | for ii=1:length(tests_todo) 16 | testtorun = [testprefix,tests_todo{ii}]; 17 | fprintf('------Running %s------\n',testtorun); 18 | test_failed=feval([testprefix,tests_todo{ii}]); 19 | total_tests_failed=total_tests_failed+test_failed; 20 | if test_failed>0 21 | list_of_failed_tests{end+1}=[testprefix,tests_todo{ii},' ',prec]; 22 | end; 23 | end; 24 | end 25 | 26 | disp(' '); 27 | if total_tests_failed==0 28 | disp('ALL TESTS PASSED'); 29 | else 30 | s=sprintf('%i TESTS FAILED',total_tests_failed); 31 | disp(s); 32 | disp('The following test scripts contained failed tests'); 33 | for ii=1:length(list_of_failed_tests) 34 | disp([' ',list_of_failed_tests{ii}]); 35 | end; 36 | end; 37 | -------------------------------------------------------------------------------- /tests/testphaseret_decolbfgs.m: -------------------------------------------------------------------------------- 1 | function test_failed=testphaseret_decolbfgs 2 | %TEST_CONSTRUCTPHASE 3 | % 4 | test_failed = 0; 5 | 6 | f = greasy; 7 | a = 128; 8 | M = 1024; 9 | g = {'blackman',M}; 10 | 11 | for pcId = 1:2 12 | % Complex case 13 | phaseconv = getat({'timeinv','freqinv'},pcId); 14 | 15 | tra = @(f) dgtreal(f,g,a,M,phaseconv); 16 | itra = @(c) idgtreal(c,{'dual',g},a,M,phaseconv); 17 | proj = @(c) tra(itra(c)); 18 | c = tra(f); 19 | s = abs(c); 20 | 21 | try 22 | [chat]=decolbfgs(s,g,a,M,phaseconv,'p',2); 23 | catch 24 | err = lasterror; 25 | fprintf('%s FAILED:\n',upper(mfilename)); 26 | warning(err.message); 27 | test_failed = 1; 28 | return; 29 | end 30 | 31 | E = magnitudeerrdb(s,proj(chat)); 32 | fail = ''; 33 | if E>-20 34 | test_failed = test_failed + 1; 35 | fail = 'FAILED'; 36 | end 37 | 38 | fprintf('DECOLBFGS p=2 %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 39 | 40 | [chat]=decolbfgs(s,g,a,M,phaseconv); 41 | 42 | E = magnitudeerrdb(s,proj(chat)); 43 | fail = ''; 44 | if E>-20 45 | test_failed = test_failed + 1; 46 | fail = 'FAILED'; 47 | end 48 | 49 | fprintf('DECOLBFGS p=2/3 %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 50 | end 51 | 52 | 53 | 54 | function el = getat(collection,id) 55 | if iscell(collection) 56 | el = collection{id}; 57 | else 58 | el = collection(id); 59 | end 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /tests/testphaseret_gla.m: -------------------------------------------------------------------------------- 1 | function test_failed=testphaseret_gla 2 | test_failed = 0; 3 | 4 | f = greasy; 5 | a = 128; 6 | M = 1024; 7 | g = {'blackman',M}; 8 | 9 | for pcId = 1:2 10 | % Complex case 11 | phaseconv = getat({'timeinv','freqinv'},pcId); 12 | 13 | tra = @(f) dgtreal(f,g,a,M,phaseconv); 14 | itra = @(c) idgtreal(c,{'dual',g},a,M,phaseconv); 15 | proj = @(c) tra(itra(c)); 16 | c = tra(f); 17 | s = abs(c); 18 | 19 | [chat,~,relres,iter]=gla(s,g,a,M,phaseconv); 20 | 21 | if strcmp(phaseconv,'timeinv') 22 | % test if timeinv is default 23 | [chat2,~,relres2,iter2]=gla(s,g,a,M); 24 | 25 | E = norm(chat-chat2,'fro'); 26 | 27 | fail = ''; 28 | if E>eps 29 | test_failed = test_failed + 1; 30 | fail = 'FAILED'; 31 | end 32 | 33 | fprintf('GLA timeinv default W=%d %s\n',1,fail); 34 | end 35 | 36 | E = magnitudeerrdb(s,proj(chat)); 37 | fail = ''; 38 | if E>-20 || abs(E-20*log10(relres(end)))>1 39 | test_failed = test_failed + 1; 40 | fail = 'FAILED'; 41 | end 42 | 43 | fprintf('GLA %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 44 | 45 | [chat,~,relres,iter]=gla(s,g,a,M,phaseconv,'fgla'); 46 | 47 | E = magnitudeerrdb(s,proj(chat)); 48 | fail = ''; 49 | if E>-30 50 | test_failed = test_failed + 1; 51 | fail = 'FAILED'; 52 | end 53 | 54 | fprintf('FGLA %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 55 | end 56 | 57 | 58 | 59 | function el = getat(collection,id) 60 | if iscell(collection) 61 | el = collection{id}; 62 | else 63 | el = collection(id); 64 | end 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /tests/testphaseret_gsrtisila.m: -------------------------------------------------------------------------------- 1 | function test_failed=testphaseret_gsrtisila 2 | %TEST_CONSTRUCTPHASE 3 | % 4 | test_failed = 0; 5 | 6 | f = cocktailparty; 7 | a = 256; 8 | M = 2048; 9 | gl = 2048; 10 | h = 0.01; 11 | g = gabwin({'gauss','width',gl,'atheight',h,'inf'},a,M,10*gl); 12 | g = long2fir(g,gl); 13 | gamma = -pi/4*(gl)^2/log(h); 14 | 15 | for pcId = 1:2 16 | % Complex case 17 | phaseconv = getat({'timeinv','freqinv'},pcId); 18 | 19 | tra = @(f) dgtreal(f,g,a,M,phaseconv); 20 | itra = @(c) idgtreal(c,{'dual',g},a,M,phaseconv); 21 | proj = @(c) tra(itra(c)); 22 | c = tra(f); 23 | s = abs(c); 24 | 25 | [chat]=gsrtisila(s,g,a,M,phaseconv,'maxit',2,'lookahead',3); 26 | 27 | E = magnitudeerrdb(s,proj(chat)); 28 | fail = ''; 29 | if E>-20 30 | test_failed = test_failed + 1; 31 | fail = 'FAILED'; 32 | end 33 | 34 | fprintf('GSRTISILA %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 35 | 36 | [chat]=gsrtisila(s,g,a,M,phaseconv,'unwrap','maxit',2,'lookahead',3); 37 | 38 | E = magnitudeerrdb(s,proj(chat)); 39 | fail = ''; 40 | if E>-20 41 | test_failed = test_failed + 1; 42 | fail = 'FAILED'; 43 | end 44 | 45 | fprintf('GSRTISILA %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 46 | 47 | [chat]=gsrtisila(s,g,a,M,phaseconv,'spsi','maxit',2,'lookahead',3); 48 | 49 | E = magnitudeerrdb(s,proj(chat)); 50 | fail = ''; 51 | if E>-20 52 | test_failed = test_failed + 1; 53 | fail = 'FAILED'; 54 | end 55 | 56 | fprintf('GSRTISILA lookahead=2 %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 57 | 58 | [chat]=gsrtisila(s,g,a,M,phaseconv,'rtpghi',{gamma},'maxit',2,'lookahead',2); 59 | 60 | E = magnitudeerrdb(s,proj(chat)); 61 | fail = ''; 62 | if E>-20 63 | test_failed = test_failed + 1; 64 | fail = 'FAILED'; 65 | end 66 | 67 | fprintf('GSRTISILA lookahead=2 %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 68 | 69 | end 70 | 71 | 72 | 73 | function el = getat(collection,id) 74 | if iscell(collection) 75 | el = collection{id}; 76 | else 77 | el = collection(id); 78 | end 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /tests/testphaseret_lertisila.m: -------------------------------------------------------------------------------- 1 | function test_failed=testphaseret_lertisila 2 | %TEST_CONSTRUCTPHASE 3 | % 4 | test_failed = 0; 5 | 6 | f = greasy; 7 | a = 128; 8 | M = 1024; 9 | g = {'blackman',512}; 10 | 11 | for pcId = 1:2 12 | % Complex case 13 | phaseconv = getat({'timeinv','freqinv'},pcId); 14 | 15 | tra = @(f) dgtreal(f,g,a,M,phaseconv); 16 | itra = @(c) idgtreal(c,{'dual',g},a,M,phaseconv); 17 | proj = @(c) tra(itra(c)); 18 | c = tra(f); 19 | s = abs(c); 20 | 21 | [chat]=lertisila(s,g,a,M,phaseconv); 22 | 23 | E = magnitudeerrdb(s,proj(chat)); 24 | fail = ''; 25 | if E>-20 26 | test_failed = test_failed + 1; 27 | fail = 'FAILED'; 28 | end 29 | 30 | fprintf('LERTISILA %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 31 | 32 | [chat]=lertisila(s,g,a,M,phaseconv,'maxit',20); 33 | 34 | E = magnitudeerrdb(s,proj(chat)); 35 | fail = ''; 36 | if E>-20 37 | test_failed = test_failed + 1; 38 | fail = 'FAILED'; 39 | end 40 | 41 | fprintf('LERTISILA %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 42 | 43 | [chat]=lertisila(s,g,a,M,phaseconv,'maxit',10,'lookahead',2); 44 | 45 | E = magnitudeerrdb(s,proj(chat)); 46 | fail = ''; 47 | if E>-20 48 | test_failed = test_failed + 1; 49 | fail = 'FAILED'; 50 | end 51 | 52 | fprintf('LERTISILA lookahead=2 %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 53 | 54 | 55 | % [M2,N] = size(s); 56 | % mask = ones(size(s)); 57 | % mask(:,floor(N/2):end) = 0; 58 | % [chat]=spsi(s,a,M,mask,angle(c),phaseconv); 59 | % 60 | % E = magnitudeerrdb(s,proj(chat)); 61 | % fail = ''; 62 | % if E>-10 63 | % test_failed = test_failed + 1; 64 | % fail = 'FAILED'; 65 | % end 66 | % 67 | % fprintf('SPSI MASK %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 68 | end 69 | 70 | 71 | 72 | function el = getat(collection,id) 73 | if iscell(collection) 74 | el = collection{id}; 75 | else 76 | el = collection(id); 77 | end 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /tests/testphaseret_pghi.m: -------------------------------------------------------------------------------- 1 | function test_failed=testphaseret_pghi 2 | %TEST_CONSTRUCTPHASE 3 | % 4 | test_failed = 0; 5 | 6 | f = greasy; 7 | a = 128; 8 | M = 1024; 9 | g = {'blackman',M}; 10 | gamma = 0.17954*M^2; 11 | 12 | for pcId = 1:2 13 | % Complex case 14 | phaseconv = getat({'timeinv','freqinv'},pcId); 15 | 16 | tra = @(f) dgtreal(f,g,a,M,phaseconv); 17 | itra = @(c) idgtreal(c,{'dual',g},a,M,phaseconv); 18 | proj = @(c) tra(itra(c)); 19 | c = tra(f); 20 | s = abs(c); 21 | 22 | [chat]=pghi(s,gamma,a,M,phaseconv); 23 | 24 | E = magnitudeerrdb(s,proj(chat)); 25 | fail = ''; 26 | if E>-20 27 | test_failed = test_failed + 1; 28 | fail = 'FAILED'; 29 | end 30 | 31 | fprintf('PGHI %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 32 | 33 | 34 | % [M2,N] = size(s); 35 | % mask = ones(size(s)); 36 | % mask(:,floor(N/2):end) = 0; 37 | % [chat]=spsi(s,a,M,mask,angle(c),phaseconv); 38 | % 39 | % E = magnitudeerrdb(s,proj(chat)); 40 | % fail = ''; 41 | % if E>-10 42 | % test_failed = test_failed + 1; 43 | % fail = 'FAILED'; 44 | % end 45 | % 46 | % fprintf('SPSI MASK %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 47 | end 48 | 49 | 50 | 51 | function el = getat(collection,id) 52 | if iscell(collection) 53 | el = collection{id}; 54 | else 55 | el = collection(id); 56 | end 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /tests/testphaseret_phaseretdemos.m: -------------------------------------------------------------------------------- 1 | function test_failed=testphaseret_phaseretdemos 2 | %TEST_DEMOS Test if all the demos runs without errors. 3 | 4 | test_failed=0; 5 | matpath = fileparts(which('phaseretstart')); 6 | s=dir([matpath,filesep,'demos',filesep,'demo_*.m']); 7 | 8 | for ii=1:numel(s) 9 | filename = s(ii).name; 10 | 11 | disp(filename); 12 | 13 | % The demo is run in separate function to avoid 14 | % variable name clash 15 | test_failed = test_failed + rundemo(filename(1:end-2)); 16 | end 17 | 18 | 19 | function test_failed = rundemo(demoname) 20 | test_failed = 0; 21 | close all; 22 | try 23 | eval(demoname); 24 | catch 25 | test_failed = 1; 26 | err = lasterror; 27 | fprintf('DEMO %s FAILED\n with the following reason:',demoname); 28 | warning(err.message); 29 | close all; 30 | end 31 | close all; 32 | -------------------------------------------------------------------------------- /tests/testphaseret_rtisila.m: -------------------------------------------------------------------------------- 1 | function test_failed=testphaseret_rtisila 2 | %TEST_CONSTRUCTPHASE 3 | % 4 | test_failed = 0; 5 | 6 | f = greasy; 7 | a = 128; 8 | M = 1024; 9 | g = {'blackman',512}; 10 | 11 | for pcId = 1:2 12 | % Complex case 13 | phaseconv = getat({'timeinv','freqinv'},pcId); 14 | 15 | tra = @(f) dgtreal(f,g,a,M,phaseconv); 16 | itra = @(c) idgtreal(c,{'dual',g},a,M,phaseconv); 17 | proj = @(c) tra(itra(c)); 18 | c = tra(f); 19 | s = abs(c); 20 | 21 | [chat]=rtisila(s,g,a,M,phaseconv); 22 | 23 | E = magnitudeerrdb(s,proj(chat)); 24 | fail = ''; 25 | if E>-20 26 | test_failed = test_failed + 1; 27 | fail = 'FAILED'; 28 | end 29 | 30 | fprintf('RTISILA %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 31 | 32 | [chat]=rtisila(s,g,a,M,phaseconv,'maxit',20); 33 | 34 | E = magnitudeerrdb(s,proj(chat)); 35 | fail = ''; 36 | if E>-20 37 | test_failed = test_failed + 1; 38 | fail = 'FAILED'; 39 | end 40 | 41 | fprintf('RTISILA %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 42 | 43 | [chat]=rtisila(s,g,a,M,phaseconv,'maxit',10,'lookahead',2); 44 | 45 | E = magnitudeerrdb(s,proj(chat)); 46 | fail = ''; 47 | if E>-20 48 | test_failed = test_failed + 1; 49 | fail = 'FAILED'; 50 | end 51 | 52 | fprintf('RTISILA %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 53 | 54 | 55 | % [M2,N] = size(s); 56 | % mask = ones(size(s)); 57 | % mask(:,floor(N/2):end) = 0; 58 | % [chat]=spsi(s,a,M,mask,angle(c),phaseconv); 59 | % 60 | % E = magnitudeerrdb(s,proj(chat)); 61 | % fail = ''; 62 | % if E>-10 63 | % test_failed = test_failed + 1; 64 | % fail = 'FAILED'; 65 | % end 66 | % 67 | % fprintf('SPSI MASK %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 68 | end 69 | 70 | 71 | 72 | function el = getat(collection,id) 73 | if iscell(collection) 74 | el = collection{id}; 75 | else 76 | el = collection(id); 77 | end 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /tests/testphaseret_rtpghi.m: -------------------------------------------------------------------------------- 1 | function test_failed=testphaseret_rtpghi 2 | %TEST_CONSTRUCTPHASE 3 | % 4 | test_failed = 0; 5 | 6 | f = greasy; 7 | a = 64; 8 | M = 1024; 9 | g = {'blackman',M}; 10 | gamma = 0.17954*M^2; 11 | 12 | for pcId = 1:2 13 | % Complex case 14 | phaseconv = getat({'timeinv','freqinv'},pcId); 15 | 16 | tra = @(f) dgtreal(f,g,a,M,phaseconv); 17 | itra = @(c) idgtreal(c,{'dual',g},a,M,phaseconv); 18 | proj = @(c) tra(itra(c)); 19 | c = tra(f); 20 | s = abs(c); 21 | 22 | [chat]=rtpghi(s,gamma,a,M,phaseconv); 23 | 24 | E = magnitudeerrdb(s,proj(chat)); 25 | fail = ''; 26 | if E>-20 27 | test_failed = test_failed + 1; 28 | fail = 'FAILED'; 29 | end 30 | 31 | fprintf('RTPGHI %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 32 | 33 | [chat]=rtpghi(s,gamma,a,M,phaseconv,'causal'); 34 | 35 | E = magnitudeerrdb(s,proj(chat)); 36 | fail = ''; 37 | if E>-20 38 | test_failed = test_failed + 1; 39 | fail = 'FAILED'; 40 | end 41 | 42 | fprintf('RTPGHI CAUSAL %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 43 | 44 | 45 | % [M2,N] = size(s); 46 | % mask = ones(size(s)); 47 | % mask(:,floor(N/2):end) = 0; 48 | % [chat]=spsi(s,a,M,mask,angle(c),phaseconv); 49 | % 50 | % E = magnitudeerrdb(s,proj(chat)); 51 | % fail = ''; 52 | % if E>-10 53 | % test_failed = test_failed + 1; 54 | % fail = 'FAILED'; 55 | % end 56 | % 57 | % fprintf('SPSI MASK %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 58 | end 59 | 60 | 61 | 62 | function el = getat(collection,id) 63 | if iscell(collection) 64 | el = collection{id}; 65 | else 66 | el = collection(id); 67 | end 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /tests/testphaseret_spsi.m: -------------------------------------------------------------------------------- 1 | function test_failed=testphaseret_spsi 2 | test_failed = 0; 3 | 4 | f = greasy; 5 | a = 128; 6 | M = 1024; 7 | g = {'blackman',M}; 8 | 9 | for pcId = 1:2 10 | % Complex case 11 | phaseconv = getat({'timeinv','freqinv'},pcId); 12 | 13 | tra = @(f) dgtreal(f,g,a,M,phaseconv); 14 | itra = @(c) idgtreal(c,{'dual',g},a,M,phaseconv); 15 | proj = @(c) tra(itra(c)); 16 | c = tra(f); 17 | s = abs(c); 18 | 19 | [chat]=spsi(s,a,M,phaseconv); 20 | 21 | E = magnitudeerrdb(s,proj(chat)); 22 | fail = ''; 23 | if E>-10 24 | test_failed = test_failed + 1; 25 | fail = 'FAILED'; 26 | end 27 | 28 | fprintf('SPSI %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 29 | 30 | 31 | [M2,N] = size(s); 32 | mask = ones(size(s)); 33 | mask(:,floor(N/2):end) = 0; 34 | [chat]=spsi(s,a,M,mask,angle(c),phaseconv); 35 | 36 | E = magnitudeerrdb(s,proj(chat)); 37 | fail = ''; 38 | if E>-10 39 | test_failed = test_failed + 1; 40 | fail = 'FAILED'; 41 | end 42 | 43 | fprintf('SPSI MASK %s W=%d E=%.2f %s\n',phaseconv,1,E,fail); 44 | end 45 | 46 | 47 | 48 | function el = getat(collection,id) 49 | if iscell(collection) 50 | el = collection{id}; 51 | else 52 | el = collection(id); 53 | end 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /tests/testsinit.m: -------------------------------------------------------------------------------- 1 | status = 1; 2 | --------------------------------------------------------------------------------