├── examples ├── .gitignore ├── error_handling_example.c ├── math_primitive_root_example.c ├── poly_findroots_example.c ├── dotprod_rrrf_example.c ├── modular_arithmetic_example.c ├── cbufferf_example.c ├── qs1dsearch_example.c ├── msequence_generator_example.c ├── bsequence_example.c ├── dotprod_cccf_example.c ├── msequence_example.c ├── platformio_example.c ├── crc_example.c ├── windowf_example.c ├── wdelayf_example.c ├── firfilt_crcf_copy_example.c ├── firdes_doppler_example.c ├── liquid_argparse_example.c ├── math_lngamma_example.c ├── firdespm_halfband_example.c ├── libliquid_example.c ├── interleaver_example.c ├── kbd_window_example.c ├── repack_bytes_example.c ├── kaiser_window_example.c ├── polyfit_example.c ├── polyfit_comparison_example.c └── firdespm_lowpass_example.c ├── autotest ├── logs │ └── .gitignore ├── null_autotest.c └── libliquid_autotest.c ├── doc └── CMakeLists.txt ├── gentab ├── .gitignore ├── README.rst └── makefile ├── sandbox ├── .gitignore ├── README.md ├── fec_rep3_test.c ├── vectorcf_test.c ├── ellip_func_test.c ├── fec_hamming128_example.c ├── fec_rep5_test.c ├── matrix_eig_test.c ├── simplex_test.c ├── thiran_allpass_iir_test.c ├── fec_sumproduct_test.c ├── fec_hamming128_gentab.c ├── fecsoft_hamming128_gentab.c ├── chromosome_test.c ├── crc_gentab.c ├── throttle_test.c ├── minsearch_test.c └── fct_test.c ├── bench ├── .gitignore ├── main.c ├── null_benchmark.c └── example_benchmark.h ├── scripts ├── generate_headers.py ├── .gitignore ├── liquid_linker_test.mk ├── liquid_linker_test.c ├── benchmark_compare.py ├── nmutil.py ├── example_autotest.h ├── version.sh └── example_benchmark.h ├── src ├── matrix │ ├── tests │ │ ├── data │ │ │ └── README.md │ │ ├── gendata_write_matrix.m │ │ └── gendata_write_header.m │ └── src │ │ ├── smatrix.common.c │ │ ├── smatrixf.c │ │ ├── smatrixi.c │ │ ├── matrix.c │ │ ├── matrixf.c │ │ ├── matrixc.c │ │ └── matrixcf.c ├── utility │ ├── src │ │ ├── msb_index.x86.s │ │ ├── memory.c │ │ └── count_ones.c │ ├── tests │ │ └── bdotprod_gentest.m │ └── bench │ │ └── byte_utilities_benchmark.c ├── fft │ ├── tests │ │ ├── gen_fft_files.m │ │ ├── data │ │ │ ├── fft_data_2.c │ │ │ ├── fft_data_3.c │ │ │ ├── fft_data_4.c │ │ │ ├── fft_data_5.c │ │ │ ├── fft_data_6.c │ │ │ ├── fft_data_7.c │ │ │ └── fft_data_8.c │ │ ├── fft_small_autotest.c │ │ ├── fft_prime_autotest.c │ │ └── fft_radix2_autotest.c │ ├── bench │ │ └── fft_runbench.h │ └── src │ │ ├── spgramf.c │ │ └── spgramcf.c ├── quantization │ ├── src │ │ ├── quantizerf.c │ │ └── quantizercf.c │ └── tests │ │ └── quantize_autotest.c ├── dotprod │ └── src │ │ ├── dotprod_rrrf.c │ │ ├── dotprod_crcf.c │ │ └── dotprod_cccf.c ├── vector │ └── src │ │ ├── vectorf.port.c │ │ ├── vectorcf.port.c │ │ ├── vectorf.avx.c │ │ └── vectorcf.neon.c ├── agc │ └── src │ │ ├── agc_rrrf.c │ │ └── agc_crcf.c ├── buffer │ └── src │ │ ├── bufferf.c │ │ └── buffercf.c ├── filter │ └── tests │ │ ├── data │ │ ├── firfilt_rrrf_data_h4x8.c │ │ └── firdecim_rrrf_data_M2h4x20.c │ │ ├── ordfilt_autotest.c │ │ └── iirdecim_autotest.c ├── equalization │ └── src │ │ ├── equalizer_rrrf.c │ │ └── equalizer_cccf.c ├── nco │ └── src │ │ └── nco_crcf.c ├── fec │ ├── src │ │ ├── fec_conv_poly.c │ │ └── c_ones_mod2.c │ └── tests │ │ └── fec_rep3_autotest.c ├── optim │ ├── src │ │ └── optim.h │ └── tests │ │ └── utility_autotest.c ├── multichannel │ └── src │ │ └── firpfbch_cccf.c └── channel │ └── src │ └── channel_cccf.c ├── cmake ├── Config.cmake.in ├── config.h.cmake ├── version.c.in ├── debug.cmake ├── Findfftw3f.cmake └── version.cmake ├── .github └── workflows │ ├── platformio.yml │ ├── coverage.yml │ └── core.yml ├── .travis.yml ├── .gitignore ├── .codecov.yml ├── LICENSE ├── library.json └── bootstrap.sh /examples/.gitignore: -------------------------------------------------------------------------------- 1 | *_example 2 | -------------------------------------------------------------------------------- /autotest/logs/.gitignore: -------------------------------------------------------------------------------- 1 | *.m 2 | *.dat 3 | 4 | -------------------------------------------------------------------------------- /doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # documentation build script 2 | 3 | -------------------------------------------------------------------------------- /gentab/.gitignore: -------------------------------------------------------------------------------- 1 | # ignore compiled objects and executables 2 | *.o 3 | *_gentab 4 | 5 | -------------------------------------------------------------------------------- /sandbox/.gitignore: -------------------------------------------------------------------------------- 1 | # ignore all temporary file 2 | *.m 3 | *.swp 4 | 5 | # ignore all program files 6 | *_test 7 | -------------------------------------------------------------------------------- /bench/.gitignore: -------------------------------------------------------------------------------- 1 | # git ignore file 2 | 3 | # ignore generator program 4 | benchmarkgen 5 | 6 | # ignore output header 7 | benchmark_include.h 8 | -------------------------------------------------------------------------------- /scripts/generate_headers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | '''Generate (or copy) configuration header''' 3 | import os 4 | 5 | os.system('cp config.h ..') 6 | 7 | -------------------------------------------------------------------------------- /src/matrix/tests/data/README.md: -------------------------------------------------------------------------------- 1 | 2 | matrix test data 3 | ================ 4 | 5 | This directory contains all of the data files for testing matrix 6 | operations within liquid-dsp. 7 | 8 | -------------------------------------------------------------------------------- /scripts/.gitignore: -------------------------------------------------------------------------------- 1 | # git ignore for scripts directory 2 | 3 | # ignore programs, object 4 | *.o 5 | autoscript 6 | benchmark_compare 7 | 8 | # ignore auto-generated (test) files 9 | autotest_test.h 10 | benchmark_test.h 11 | -------------------------------------------------------------------------------- /cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | set_and_check(@PROJECT_NAME@_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") 4 | 5 | include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") 6 | 7 | check_required_components(@PROJECT_NAME@) 8 | -------------------------------------------------------------------------------- /src/utility/src/msb_index.x86.s: -------------------------------------------------------------------------------- 1 | ; Index of most-significant bit 2 | 3 | .text 4 | .globl msb_index 5 | msb_index: 6 | pushl %ebx 7 | pushl %ecx 8 | pushl %edx 9 | bsrl %eax,%eax 10 | popl %edx 11 | popl %ecx 12 | popl %ebx 13 | ret 14 | -------------------------------------------------------------------------------- /cmake/config.h.cmake: -------------------------------------------------------------------------------- 1 | #cmakedefine HAVE_GETOPT_LONG 1 2 | #cmakedefine HAVE_GETOPT_H 3 | #cmakedefine HAVE_MEMORY_H 4 | #cmakedefine HAVE_STDIO_H 5 | #cmakedefine HAVE_STDLIB_H 6 | #cmakedefine HAVE_LIBC 7 | #cmakedefine SIZEOF_INT @SIZEOF_INT@ 8 | #cmakedefine01 fftw3f_FOUND 9 | -------------------------------------------------------------------------------- /cmake/version.c.in: -------------------------------------------------------------------------------- 1 | // 2 | 3 | const char * version = "@PROJECT_VERSION@"; 4 | unsigned int version_major = @PROJECT_VERSION_MAJOR@; 5 | unsigned int version_minor = @PROJECT_VERSION_MINOR@+0; 6 | unsigned int version_patch = @PROJECT_VERSION_PATCH@+0; 7 | unsigned int version_tweak = @PROJECT_VERSION_TWEAK@+0; 8 | 9 | -------------------------------------------------------------------------------- /scripts/liquid_linker_test.mk: -------------------------------------------------------------------------------- 1 | # simple makefile to test linking to liquid after library has been installed 2 | 3 | all: check 4 | 5 | check: liquid_linker_test 6 | ./$< 7 | 8 | liquid_linker_test: % : scripts/%.c 9 | $(CC) -Wall -O2 -o $@ $< -lm -lc -lliquid 10 | 11 | clean: 12 | rm -f liquid_linker_test 13 | 14 | -------------------------------------------------------------------------------- /src/fft/tests/gen_fft_files.m: -------------------------------------------------------------------------------- 1 | % generate fft data for autotests 2 | 3 | n = [2, 3, 4, 5, 6, 7, 8, 9,... 4 | 10, 16, 17, 20, 21, 22, 24, 26,... 5 | 30, 32, 35, 36, 43, 48, 63, 64, 79, 92, 96,... 6 | 120, 130, 157, 192, 317, 509] 7 | 8 | for i=1:length(n), 9 | gen_fft_data(n(i)); 10 | end; 11 | 12 | -------------------------------------------------------------------------------- /src/utility/tests/bdotprod_gentest.m: -------------------------------------------------------------------------------- 1 | 2 | clear all; 3 | close all; 4 | 5 | a = floor(rand(1) * 2^16); 6 | b = floor(rand(1) * 2^16); 7 | 8 | as = dec2bin(a,16); 9 | bs = dec2bin(b,16); 10 | ap = []; 11 | bp = []; 12 | for i=1:16, 13 | ap = [ap str2num(as(i))]; 14 | bp = [bp str2num(bs(i))]; 15 | end; 16 | 17 | bit = mod(sum(ap.*bp),2); 18 | 19 | printf('CONTEND_EQUALITY( liquid_bdotprod(0x%.4x, 0x%.4x), %1u);\n', a,b,bit); 20 | 21 | -------------------------------------------------------------------------------- /sandbox/README.md: -------------------------------------------------------------------------------- 1 | 2 | liquid-dsp sandbox 3 | ================== 4 | 5 | This directory is the sandbox for prototyping DSP processing 6 | elements in liquid. It contains a number of scripts which are used 7 | for testing and prototyping certain signal processing algorithms. 8 | Its primary function is to validate functional correctness without 9 | adding unnecessary code to the main project files. 10 | 11 | All the programs in this directory can be build by invoking 'make' 12 | from the root directory, viz. 13 | 14 | $ make sandbox 15 | 16 | -------------------------------------------------------------------------------- /gentab/README.rst: -------------------------------------------------------------------------------- 1 | 2 | liquid-dsp Table Generation ("gentab") Programs 3 | =============================================== 4 | 5 | This directory contains programs for generating tables and constants used 6 | in liquid-dsp. These programs are not built and run at compile time as 7 | doing this complicates the build process substantially, but rather are 8 | compiled and run offline with the resulting output committed to the main 9 | source tree. 10 | 11 | To build and run the table-generation scripts, simply run the following: 12 | 13 | .. code-block:: bash 14 | 15 | make -f gentab/makefile 16 | 17 | 18 | -------------------------------------------------------------------------------- /cmake/debug.cmake: -------------------------------------------------------------------------------- 1 | # dump a (sorted) list of cmake variables 2 | function(liquid_debug_print_vars) 3 | get_cmake_property(_variableNames VARIABLES) 4 | list (SORT _variableNames) 5 | foreach (_variableName ${_variableNames}) 6 | message(STATUS "${_variableName}=${${_variableName}}") 7 | endforeach() 8 | endfunction() 9 | 10 | liquid_debug_print_vars() 11 | message("top: CMAKE_SOURCE_DIR = ${CMAKE_SOURCE_DIR}") 12 | message("top: CMAKE_BINARY_DIR = ${CMAKE_BINARY_DIR}") 13 | message("top: CMAKE_CURRENT_SOURCE_DIR = ${CMAKE_CURRENT_SOURCE_DIR}") 14 | message("top: CMAKE_CURRENT_BINARY_DIR = ${CMAKE_CURRENT_BINARY_DIR}") 15 | -------------------------------------------------------------------------------- /scripts/liquid_linker_test.c: -------------------------------------------------------------------------------- 1 | // test linking to liquid after library has been installed 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | // test liquid version number 9 | printf("checking installed liquid version numbers...\n"); 10 | printf(" header : 0x%.6x\n", LIQUID_VERSION_NUMBER); 11 | printf(" library : 0x%.6x\n", liquid_libversion_number()); 12 | LIQUID_VALIDATE_LIBVERSION; 13 | 14 | // create object, print and return 15 | printf("creating test object...\n"); 16 | resamp_crcf q = resamp_crcf_create(0.12345f, 12, 0.25f, 60.0f, 256); 17 | resamp_crcf_print(q); 18 | resamp_crcf_destroy(q); 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /.github/workflows/platformio.yml: -------------------------------------------------------------------------------- 1 | name: PlatformIO CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ${{ matrix.os }} 9 | strategy: 10 | matrix: 11 | os: [ubuntu-latest] #, macos-latest] #, windows-latest] 12 | example: [examples/platformio_example.c] 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | 17 | - name: Set up Python 18 | uses: actions/setup-python@v2 19 | 20 | - name: Install PlatformIO 21 | run: | 22 | python3 -m pip install --upgrade pip 23 | python3 -m pip install --upgrade platformio 24 | 25 | - name: Run PlatformIO 26 | run: pio ci --lib="." --board=pico 27 | env: 28 | PLATFORMIO_CI_SRC: ${{ matrix.example }} 29 | 30 | -------------------------------------------------------------------------------- /examples/error_handling_example.c: -------------------------------------------------------------------------------- 1 | char __docstr__[] = "Demonstrate error handling in liquid"; 2 | 3 | #include 4 | #include 5 | #include "liquid.h" 6 | #include "liquid.argparse.h" 7 | 8 | int main(int argc, char*argv[]) 9 | { 10 | // define variables and parse command-line arguments 11 | liquid_argparse_init(__docstr__); 12 | liquid_argparse_parse(argc,argv); 13 | 14 | // create agc object 15 | agc_crcf q = agc_crcf_create(); 16 | 17 | // try to set invalid parameter 18 | int rc = agc_crcf_set_bandwidth(q, -1e-3f); 19 | if (rc != LIQUID_OK) 20 | printf("received error %d: %s\n", rc, liquid_error_info(rc)); 21 | 22 | // destroy object 23 | agc_crcf_destroy(q); 24 | 25 | // 26 | printf("done.\n"); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /gentab/makefile: -------------------------------------------------------------------------------- 1 | # Makefile for liquid-dsp pre-compiled tables and constants 2 | 3 | all: 4 | 5 | CFLAGS := -I include -g -O2 -Wall 6 | LDFLAGS := 7 | LIBS := -lm -lc -lliquid 8 | 9 | .PHONY: gentab 10 | gentab_programs = \ 11 | gentab/count_ones_gentab \ 12 | gentab/firfilt_gentab \ 13 | 14 | gentab_objects = $(patsubst %,%.o,$(gentab_programs)) 15 | gentab: $(gentab_programs) 16 | 17 | # NOTE: linked libraries must come _after_ the target program 18 | $(gentab_objects): %.o : %.c 19 | 20 | $(gentab_programs): % : %.o ${ARCHIVE_LIB} 21 | $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(LIBS) 22 | 23 | # clean gentab binaries 24 | clean: 25 | $(RM) gentab/*.o 26 | $(RM) $(gentab_programs) 27 | 28 | run: $(gentab_programs) 29 | ./gentab/count_ones_gentab > src/utility/src/count_ones.c 30 | 31 | all: run 32 | 33 | 34 | -------------------------------------------------------------------------------- /sandbox/fec_rep3_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | #include 6 | #include "liquid.h" 7 | 8 | int main() { 9 | unsigned char s0, s1, s2, r, r_hat; 10 | unsigned int errors = 0; 11 | 12 | for (s0=0; s0<2; s0++) { 13 | for (s1=0; s1<2; s1++) { 14 | for (s2=0; s2<2; s2++) { 15 | r = (s0 + s1 + s2) < 2 ? 0 : 1; 16 | 17 | //r_hat = (!s0 & s1 & s2) | (s0 & !(!s1 & !s2)); 18 | r_hat = (s1 & s2) | (s0 & s1) | (s0 & s2); 19 | 20 | int error_found = (s0 ^ s1) | (s0 ^ s2) | (s1 ^ s2); 21 | 22 | errors += r != r_hat; 23 | 24 | printf("%2u %2u %2u %2u (%2u) %2u\n", s0, s1, s2, r, r_hat, error_found); 25 | } 26 | } 27 | } 28 | printf("errors : %u\n", errors); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /sandbox/vectorcf_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // vectorcf_test.c : test complex floating-point vector operations 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | //#include 10 | 11 | #include "liquid.h" 12 | 13 | int main() 14 | { 15 | // options 16 | unsigned int n = 64; 17 | 18 | // 19 | unsigned int i; 20 | float complex v[n]; 21 | for (i=0; i 5 | #include 6 | 7 | #include "liquid.h" 8 | #include "liquid.argparse.h" 9 | 10 | int main(int argc, char*argv[]) 11 | { 12 | // define variables and parse command-line options 13 | liquid_argparse_init(__docstr__); 14 | liquid_argparse_add(unsigned, n, 140, 'n', "maximum number", NULL); 15 | liquid_argparse_parse(argc,argv); 16 | 17 | printf("primitive roots of prime numbers up to %u:\n", n); 18 | unsigned int i; 19 | for (i=3; i<=n; i++) { 20 | if (!liquid_is_prime(i)) 21 | continue; 22 | 23 | unsigned int root = liquid_primitive_root_prime(i); 24 | printf(" %4u : %4u\n", i, root); 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: C 2 | 3 | matrix: 4 | include: 5 | - os: linux 6 | compiler: gcc 7 | env: BUILD_CXX=off 8 | - os: osx 9 | compiler: clang 10 | env: BUILD_CXX=off 11 | 12 | script: 13 | - git clone https://github.com/quiet/libcorrect.git 14 | - cd libcorrect 15 | - mkdir build 16 | - cd build 17 | - set -e 18 | - cmake -DCMAKE_BUILD_TYPE=Release .. && make && make shim 19 | - sudo make install 20 | - set +e 21 | - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo ldconfig; fi 22 | - cd ../.. 23 | - set -e 24 | - ./bootstrap.sh 25 | - ./configure 26 | - make 27 | - make examples 28 | - make benchmark 29 | - make xautotest 30 | - ./xautotest -R 0 # execute with a specific random seed 31 | - ./xautotest # execute with a random seed based on time 32 | -------------------------------------------------------------------------------- /sandbox/ellip_func_test.c: -------------------------------------------------------------------------------- 1 | char __docstr__[] = "Test elliptic functions"; 2 | 3 | #include 4 | #include 5 | 6 | #include "liquid.internal.h" 7 | 8 | int main() { 9 | 10 | float complex u = 0.7f; 11 | float k = 0.8f; 12 | unsigned int n=7; 13 | 14 | float complex cd = ellip_cdf(u,k,n); 15 | float complex sn = ellip_snf(u,k,n); 16 | printf("u : %12.8f + j*%12.8f\n", crealf(u), cimagf(u)); 17 | printf("k : %12.8f\n", k); 18 | printf("cd : %12.8f + j*%12.8f\n", crealf(cd), cimagf(cd)); 19 | printf("sn : %12.8f + j*%12.8f\n", crealf(sn), cimagf(sn)); 20 | 21 | printf("\n"); 22 | float complex acd = ellip_acdf(cd,k,n); 23 | float complex asn = ellip_asnf(sn,k,n); 24 | printf("acd : %12.8f + j*%12.8f\n", crealf(acd), cimagf(acd)); 25 | printf("asn : %12.8f + j*%12.8f\n", crealf(asn), cimagf(asn)); 26 | 27 | printf("done.\n"); 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ignore all object files 2 | *.a 3 | *.ar 4 | *.d 5 | *.dylib 6 | *.dSYM 7 | *.gcda 8 | *.gcno 9 | *.o 10 | *.so 11 | *~ 12 | build 13 | 14 | # ignore swap files for vim editing 15 | *.swp 16 | 17 | # build objects 18 | autom4te.cache 19 | aclocal.m4 20 | 21 | # ignore all auto-generated targets 22 | autotest_include.h 23 | benchmark 24 | benchmark_include.h 25 | bench/fftbench 26 | configure 27 | config.h 28 | config.h.in 29 | config.h.in~ 30 | config.log 31 | config.status 32 | makefile 33 | xautotest 34 | *.m 35 | autotest.json 36 | autotest/logs/*.bin 37 | autotest/logs/*.gnu 38 | readme.* 39 | liquid_linker_test 40 | 41 | # miscellany 42 | octave-core 43 | *.tar 44 | *.gz 45 | .DS_Store 46 | 47 | # gentab programs 48 | src/fec/gentab/*_gentab 49 | src/utility/gentab/*_gentab 50 | 51 | # gentab output sources 52 | src/fec/gentab/reverse_byte.c 53 | src/utility/gentab/count_ones.c 54 | 55 | # sandbox 56 | sandbox/*_test 57 | sandbox/*_example 58 | sandbox/*_gentab 59 | -------------------------------------------------------------------------------- /cmake/Findfftw3f.cmake: -------------------------------------------------------------------------------- 1 | # find library and header instance of libfftw3f (fast Fourier transform) 2 | 3 | include(FindPackageHandleStandardArgs) 4 | 5 | find_path(fftw3f_INCLUDE_DIR NAMES fftw3.h 6 | HINTS 7 | /usr/include 8 | /usr/local/include 9 | ${CMAKE_INSTALL_PREFIX}/include 10 | ) 11 | 12 | find_library(fftw3f_LIBRARY NAMES fftw3f libfftw3f 13 | HINTS 14 | /usr/lib 15 | /usr/lib/x86_64-linux-gnu 16 | /usr/local/lib 17 | ${CMAKE_INSTALL_PREFIX}/lib 18 | ) 19 | 20 | find_package_handle_standard_args(fftw3f REQUIRED_VARS fftw3f_LIBRARY fftw3f_INCLUDE_DIR) 21 | 22 | if (fftw3f_FOUND) 23 | mark_as_advanced(fftw3f_INCLUDE_DIR) 24 | mark_as_advanced(fftw3f_LIBRARY) 25 | endif() 26 | 27 | if (fftw3f_FOUND AND NOT TARGET fftw::fftw) 28 | add_library(fftw::fftw IMPORTED SHARED) 29 | set_property(TARGET fftw::fftw PROPERTY IMPORTED_LOCATION ${fftw3f_LIBRARY}) 30 | target_include_directories(fftw::fftw INTERFACE ${fftw3f_LIBRARY}) 31 | endif() 32 | 33 | -------------------------------------------------------------------------------- /cmake/version.cmake: -------------------------------------------------------------------------------- 1 | function(get_liquid_version HEADER_FILE OUTPUT_VAR) 2 | if (NOT EXISTS "${HEADER_FILE}") 3 | message(FATAL_ERROR "No ${HEADER_FILE} found!") 4 | endif() 5 | 6 | file(READ "${HEADER_FILE}" HEADER_CONTENTS) 7 | 8 | string(REGEX MATCH "#define[ \t]+LIQUID_VERSION_MAJOR[ \t]+([0-9]+)" _ ${HEADER_CONTENTS}) 9 | set(VERSION_MAJOR ${CMAKE_MATCH_1}) 10 | 11 | string(REGEX MATCH "#define[ \t]+LIQUID_VERSION_MINOR[ \t]+([0-9]+)" _ ${HEADER_CONTENTS}) 12 | set(VERSION_MINOR ${CMAKE_MATCH_1}) 13 | 14 | string(REGEX MATCH "#define[ \t]+LIQUID_VERSION_PATCH[ \t]+([0-9]+)" _ ${HEADER_CONTENTS}) 15 | set(VERSION_PATCH ${CMAKE_MATCH_1}) 16 | 17 | if (VERSION_MAJOR STREQUAL "" OR VERSION_MINOR STREQUAL "" OR VERSION_PATCH STREQUAL "") 18 | message(FATAL_ERROR "Could not extract version from ${HEADER_FILE}!") 19 | endif() 20 | 21 | set(${OUTPUT_VAR} "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" PARENT_SCOPE) 22 | endfunction() 23 | -------------------------------------------------------------------------------- /examples/poly_findroots_example.c: -------------------------------------------------------------------------------- 1 | char __docstr__[] = "Test polynomial root-finding algorithm"; 2 | 3 | #include 4 | #include 5 | #include "liquid.h" 6 | #include "liquid.argparse.h" 7 | 8 | int main(int argc, char* argv[]) 9 | { 10 | // define variables and parse command-line arguments 11 | liquid_argparse_init(__docstr__); 12 | liquid_argparse_parse(argc,argv); 13 | 14 | unsigned int n=6; // polynomial length (order+1) 15 | unsigned int i; 16 | 17 | // generate polynomial 18 | float p[6] = {6,11,-33,-33,11,6}; 19 | float complex roots[n-1]; 20 | 21 | // print polynomial 22 | printf("polynomial:\n"); 23 | for (i=0; i 6 | #include "liquid.h" 7 | #include "liquid.argparse.h" 8 | 9 | int main(int argc, char* argv[]) 10 | { 11 | // define variables and parse command-line arguments 12 | liquid_argparse_init(__docstr__); 13 | liquid_argparse_parse(argc,argv); 14 | 15 | // input array 16 | float x[] = { 1, 2, 3, 4, 5}; 17 | 18 | // coefficients array 19 | float h[] = { 1, -1, 1, -1, 1}; 20 | 21 | // dot product result 22 | float y; 23 | 24 | // run regular dot product 25 | dotprod_rrrf_run(x,h,5,&y); 26 | printf("dotprod_rrrf : %8.2f\n", y); 27 | 28 | // run structured dot product 29 | dotprod_rrrf q = dotprod_rrrf_create(x,5); 30 | dotprod_rrrf_execute(q,h,&y); 31 | printf("dotprod_rrrf (structured) : %8.2f\n", y); 32 | dotprod_rrrf_print(q); 33 | dotprod_rrrf_destroy(q); 34 | 35 | return 0; 36 | } 37 | 38 | 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007 - 2016 Joseph Gaeddert 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /scripts/benchmark_compare.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | '''Compare benchmark results''' 3 | import argparse, json, numpy as np 4 | 5 | # parse command-line arguments 6 | p = argparse.ArgumentParser(description=__doc__) 7 | p.add_argument('old', help='old benchmark file (.json)') 8 | p.add_argument('new', help='new benchmark file (.json)') 9 | p.add_argument('-thresh', default=1.5, type=float, help='threshold for displaying deltas') 10 | args = p.parse_args() 11 | 12 | # load json files 13 | v0 = json.load(open(args.old,'r')) 14 | v1 = json.load(open(args.new,'r')) 15 | 16 | # convert to dictionary and get set of common names 17 | b0 = {v['name']:v for v in v0['benchmarks']} 18 | b1 = {v['name']:v for v in v1['benchmarks']} 19 | set_common = set(b0.keys()).intersection(set(b1.keys())) 20 | 21 | # iterate over common benchmarks and print results 22 | for key in set_common: 23 | r0,r1 = b0[key], b1[key] 24 | if 0 in (r0['trials'],r1['trials']): 25 | continue 26 | rate = r1['rate'] / r0['rate'] 27 | if np.exp(np.abs(np.log(rate))) < args.thresh: 28 | continue 29 | 30 | print(' %32s, rate = %12.8f' % (key, rate)) 31 | 32 | -------------------------------------------------------------------------------- /examples/modular_arithmetic_example.c: -------------------------------------------------------------------------------- 1 | char __docstr__[] = 2 | "This example demonstrates some modular arithmetic functions."; 3 | 4 | #include 5 | #include "liquid.h" 6 | #include "liquid.argparse.h" 7 | 8 | int main(int argc, char* argv[]) 9 | { 10 | // define variables and parse command-line arguments 11 | liquid_argparse_init(__docstr__); 12 | liquid_argparse_add(unsigned, n, 280, 'n', "number to evaluate", NULL); 13 | liquid_argparse_parse(argc,argv); 14 | 15 | unsigned int factors[LIQUID_MAX_FACTORS]; 16 | unsigned int num_factors=0; 17 | 18 | // compute factors of n 19 | liquid_factor(n,factors,&num_factors); 20 | printf("factors of %u:\n", n); 21 | unsigned int i; 22 | for (i=0; i 6 | 7 | #include "liquid.h" 8 | #include "liquid.argparse.h" 9 | 10 | int main(int argc, char* argv[]) 11 | { 12 | // define variables and parse command-line arguments 13 | liquid_argparse_init(__docstr__); 14 | liquid_argparse_parse(argc,argv); 15 | 16 | float v[] = {1, 2, 3, 4, 5, 6, 7, 8}; 17 | float *r; // reader 18 | unsigned int num_requested = 3; 19 | unsigned int num_read; 20 | 21 | cbufferf cb = cbufferf_create(10); 22 | 23 | cbufferf_write(cb, v, 4); 24 | cbufferf_read(cb, num_requested, &r, &num_read); 25 | printf("cbufferf: requested %u elements, read %u elements\n", 26 | num_requested, num_read); 27 | 28 | unsigned int i; 29 | for (i=0; i 4 | #include 5 | #include 6 | 7 | #include "liquid.h" 8 | #include "liquid.argparse.h" 9 | 10 | float utility(float _v, void * _context) 11 | { 12 | float v_opt = *(float*)(_context); 13 | float v = _v - v_opt; 14 | return tanhf(v)*tanhf(v); 15 | } 16 | 17 | int main(int argc, char* argv[]) 18 | { 19 | // define variables and parse command-line arguments 20 | liquid_argparse_init(__docstr__); 21 | liquid_argparse_parse(argc,argv); 22 | 23 | // create qs1dsearch object 24 | float v_opt = 0.0f; 25 | qs1dsearch q = qs1dsearch_create(utility, &v_opt, LIQUID_OPTIM_MINIMIZE); 26 | 27 | //qs1dsearch_init_bounds(q, -20, 10); 28 | qs1dsearch_init(q, -50); 29 | 30 | // run search 31 | unsigned int i; 32 | for (i=0; i<32; i++) { 33 | qs1dsearch_step(q); 34 | qs1dsearch_print(q); 35 | } 36 | 37 | // print results 38 | printf("%3u : u(%12.8f) = %12.4e, v_opt=%12.4e (error=%12.4e)\n", 39 | i, 40 | qs1dsearch_get_opt_v(q), 41 | qs1dsearch_get_opt_u(q), 42 | v_opt, 43 | v_opt - qs1dsearch_get_opt_v(q)); 44 | 45 | qs1dsearch_destroy(q); 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /autotest/null_autotest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2015 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #include "autotest.h" 24 | 25 | void autotest_null() 26 | { 27 | // pass unconditionally 28 | AUTOTEST_PASS(); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "liquid-dsp", 3 | "version": "1.7.0", 4 | "description": "Software-defined radio digital signal processing library", 5 | "homepage": "https://liquidsdr.org", 6 | "keywords": 7 | [ 8 | "digital signal processing","DSP", 9 | "software-defined radio", "SDR", 10 | "Fourier transform,","FFT", 11 | "filter","resample","interpolate","decimate", 12 | "error correction","modulation" 13 | ], 14 | "repository": 15 | { 16 | "type": "git", 17 | "url": "https://github.com/jgaeddert/liquid-dsp.git" 18 | }, 19 | "authors": 20 | { 21 | "name": "Joseph D. Gaeddert", 22 | "email": "joseph@liquidsdr.org", 23 | "url": "https://liquidsdr.org/colophon", 24 | "maintainer": true 25 | }, 26 | "license": "MIT", 27 | "build": 28 | { 29 | "extraScript": "scripts/generate_headers.py", 30 | "flags": 31 | [ 32 | "-I.", 33 | "-Wno-deprecated-declarations" 34 | ], 35 | "srcFilter": 36 | [ 37 | "+<*.c>", 38 | "+<*/src/*.c>", 39 | "-<.git/>", 40 | "-<*/src/*.proto.c>", 41 | "-<*/src/*.av.c>", 42 | "-<*/src/*.neon.c>", 43 | "-<*/src/*.sse.c>", 44 | "-<*/src/*.avx.c>", 45 | "-<*/src/*.avx512f.c>", 46 | "-<*/src/*.x86.s>" 47 | ] 48 | }, 49 | "headers":"liquid.h" 50 | } 51 | -------------------------------------------------------------------------------- /sandbox/fec_hamming128_example.c: -------------------------------------------------------------------------------- 1 | // 2 | // Hamming(12,8) example 3 | // 4 | 5 | #include 6 | #include 7 | 8 | #include "liquid.internal.h" 9 | 10 | void print_bitstring(unsigned int _x, 11 | unsigned int _n) 12 | { 13 | unsigned int i; 14 | for (i=0; i<_n; i++) 15 | printf("%1u", (_x >> (_n-i-1)) & 1); 16 | } 17 | 18 | int main(int argc, char*argv[]) 19 | { 20 | // original symbol 21 | unsigned int sym_org = 139; 22 | 23 | // encoded symbol 24 | unsigned int sym_enc = fec_hamming128_encode_symbol(sym_org); 25 | 26 | // received symbol 27 | unsigned int n=7; // index of bit to corrupt 28 | unsigned int sym_rec = sym_enc ^ (1<<(12-n)); 29 | 30 | // decoded symbol 31 | unsigned int sym_dec = fec_hamming128_decode_symbol(sym_rec); 32 | 33 | // print results 34 | printf(" sym org : "); print_bitstring(sym_org, 8); printf("\n"); 35 | printf(" sym enc : "); print_bitstring(sym_enc, 12); printf("\n"); 36 | printf(" sym rec : "); print_bitstring(sym_rec, 12); printf("\n"); 37 | printf(" sym dec : "); print_bitstring(sym_dec, 8); printf("\n"); 38 | 39 | // print number of bit errors 40 | printf(" bit errors : %u\n", count_bit_errors(sym_org, sym_dec)); 41 | 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /examples/msequence_generator_example.c: -------------------------------------------------------------------------------- 1 | char __docstr__[] = 2 | "This example demonstrates brute-force finding maximal-length sequence" 3 | " (m-sequence) generator polynomials of a certain length."; 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "liquid.h" 10 | #include "liquid.argparse.h" 11 | 12 | int main(int argc, char* argv[]) 13 | { 14 | // define variables and parse command-line arguments 15 | liquid_argparse_init(__docstr__); 16 | //liquid_argparse_add(char*, filename, "msequence_example.m", 'o', "output filename", NULL); 17 | liquid_argparse_add(int, degree, 8, 'd', "degree", NULL); 18 | liquid_argparse_parse(argc,argv); 19 | 20 | unsigned int maxpoly = (1 << degree) - 1; 21 | unsigned int expected_sum = ((maxpoly + 1) / 2) * maxpoly; 22 | unsigned int i; 23 | unsigned int poly; 24 | for (poly = 0; poly <= maxpoly; ++poly) { 25 | unsigned int g = (poly << 1) + 1; 26 | msequence seq = msequence_create(degree, g, 1); 27 | unsigned int sum = 0; 28 | for (i = 0; i < maxpoly; ++i) { 29 | sum += msequence_get_state(seq); 30 | msequence_advance(seq); 31 | } 32 | if (sum == expected_sum) { 33 | printf("degree %d poly: %#06x\n", degree, g); 34 | } 35 | msequence_destroy(seq); 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /scripts/example_autotest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2015 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // Example of a benchmark header 25 | // 26 | 27 | #include 28 | #include 29 | 30 | void autotest_mytest() 31 | { 32 | printf("this is my test\n"); 33 | } 34 | 35 | 36 | -------------------------------------------------------------------------------- /sandbox/fec_rep5_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | #include 6 | #include "liquid.h" 7 | 8 | int main() { 9 | unsigned char s0, s1, s2, s3, s4, r, r_hat; 10 | unsigned int errors = 0; 11 | 12 | for (s0=0; s0<2; s0++) { 13 | for (s1=0; s1<2; s1++) { 14 | for (s2=0; s2<2; s2++) { 15 | for (s3=0; s3<2; s3++) { 16 | for (s4=0; s4<2; s4++) { 17 | r = (s0 + s1 + s2 + s3 + s4) < 3 ? 0 : 1; 18 | 19 | r_hat = (s0 & s1) | (s0 & s2) | (s0 & s3) | (s0 & s4) | 20 | (s1 & s2) | (s1 & s3) | (s1 & s4) | 21 | (s2 & s3) | (s2 & s4) | 22 | (s3 & s4); 23 | 24 | r_hat = (s0 & s1 & s2) | 25 | (s0 & s1 & s3) | 26 | (s0 & s1 & s4) | 27 | (s0 & s2 & s3) | 28 | (s0 & s2 & s4) | 29 | (s0 & s3 & s4) | 30 | (s1 & s2 & s3) | 31 | (s1 & s2 & s4) | 32 | (s1 & s3 & s4) | 33 | (s2 & s3 & s4); 34 | 35 | int error_found = 0; 36 | 37 | errors += r != r_hat; 38 | 39 | printf("%2u %2u %2u %2u %2u %2u (%2u) %c %2u\n", 40 | s0, s1, s2, s3, s4, r, r_hat, r==r_hat ? ' ' : '*', error_found); 41 | } 42 | } 43 | } 44 | } 45 | } 46 | printf("errors : %u\n", errors); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2007 - 2016 Joseph Gaeddert 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | # THE SOFTWARE. 21 | 22 | # 23 | # bootstrap.sh 24 | # 25 | # This is the bootstrapping script to auto-generate a configure 26 | # script for checking build environments, etc. 27 | # 28 | 29 | rm -f config.cache aclocal.m4 30 | aclocal 31 | autoconf 32 | autoheader 33 | #automake --foreign --add-missing 34 | -------------------------------------------------------------------------------- /scripts/version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script parses the global header and extracts the major.minor.patch version for 4 | # liquid-dsp and prints to the screen. This is a simplified version of: 5 | # https://github.com/tinyalsa/tinyalsa/blob/master/scripts/version.sh 6 | 7 | INCLUDE_FILE="include/liquid.h" 8 | 9 | # exit program with error 10 | die() 11 | { 12 | echo "error: $@" 1>&2 13 | exit 1 14 | } 15 | 16 | # check that file exists 17 | check_files() 18 | { 19 | [ -f ${INCLUDE_FILE} ] || die "No ${INCLUDE_FILE} found!"; 20 | } 21 | 22 | # get a part of the version from the header, e.g. LIQUID_VERSION_MAJOR 23 | get_version_part() 24 | { 25 | set -- "$1" "$(grep -m 1 "^#define\([ \t]*\)$1" ${INCLUDE_FILE} | sed 's/[^0-9]*//g')" 26 | 27 | if [ -z "$2" ]; then 28 | die "Could not get $1 from ${INCLUDE_FILE}" 29 | fi 30 | 31 | echo "$2" 32 | } 33 | 34 | # gets the complete version from the include file 35 | get_version() 36 | { 37 | VERSION_MAJOR=$(get_version_part "LIQUID_VERSION_MAJOR") 38 | VERSION_MINOR=$(get_version_part "LIQUID_VERSION_MINOR") 39 | VERSION_PATCH=$(get_version_part "LIQUID_VERSION_PATCH") 40 | } 41 | 42 | print_version() 43 | { 44 | printf "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}${LF}" 45 | return 0 46 | } 47 | 48 | check_files 49 | get_version 50 | print_version "$2" 51 | exit $? 52 | 53 | # The script should never reach this place. 54 | die "Internal error. Please report this." 55 | 56 | -------------------------------------------------------------------------------- /examples/bsequence_example.c: -------------------------------------------------------------------------------- 1 | char __docstr__[] = 2 | "This example demonstrates the interface to the bsequence (binary" 3 | " sequence) object. The bsequence object acts like a buffer of bits" 4 | " which are stored and manipulated efficiently in memory."; 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "liquid.h" 11 | #include "liquid.argparse.h" 12 | 13 | int main(int argc, char* argv[]) 14 | { 15 | // define variables and parse command-line arguments 16 | liquid_argparse_init(__docstr__); 17 | //liquid_argparse_add(char*, filename, "bsequence_example.m", 'o', "output filename", NULL); 18 | liquid_argparse_parse(argc,argv); 19 | 20 | // create and initialize binary sequence 21 | unsigned int n=16; 22 | bsequence q = bsequence_create(n); 23 | 24 | unsigned char v[4] = {0x35, 0x35}; 25 | bsequence_init(q,v); 26 | 27 | bsequence_push(q,1); 28 | bsequence_push(q,1); 29 | bsequence_push(q,1); 30 | bsequence_push(q,1); 31 | 32 | bsequence_push(q,0); 33 | bsequence_push(q,1); 34 | 35 | bsequence_print(q); 36 | 37 | bsequence_circshift(q); 38 | bsequence_print(q); 39 | bsequence_circshift(q); 40 | bsequence_print(q); 41 | 42 | unsigned int b; 43 | unsigned int i; 44 | for (i=0; i 6 | #include "liquid.h" 7 | #include "liquid.argparse.h" 8 | 9 | int main(int argc, char* argv[]) 10 | { 11 | // define variables and parse command-line arguments 12 | liquid_argparse_init(__docstr__); 13 | liquid_argparse_parse(argc,argv); 14 | 15 | // input array 16 | float complex x[] = { 1 + 1 * _Complex_I, 17 | 2 + 1 * _Complex_I, 18 | 3 + 1 * _Complex_I, 19 | 4 + 1 * _Complex_I, 20 | 5 + 1 * _Complex_I}; 21 | 22 | // coefficients array 23 | float complex h[] = { 1 + 1 * _Complex_I, 24 | -1 + 1 * _Complex_I, 25 | 1 + 1 * _Complex_I, 26 | -1 + 1 * _Complex_I, 27 | 1 + 1 * _Complex_I}; 28 | 29 | // dot product result 30 | float complex y; 31 | 32 | // run regular dot product 33 | dotprod_cccf_run(x,h,5,&y); 34 | printf("dotprod_cccf : %8.2f + j%8.2f\n", crealf(y), cimagf(y)); 35 | 36 | // run structured dot product 37 | dotprod_cccf q = dotprod_cccf_create(x,5); 38 | dotprod_cccf_execute(q,h,&y); 39 | printf("dotprod_cccf (structured) : %8.2f + j%8.2f\n", crealf(y), cimagf(y)); 40 | dotprod_cccf_destroy(q); 41 | 42 | return 0; 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/quantization/src/quantizerf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2022 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // Quantizer API: floating-point 25 | // 26 | 27 | #include "liquid.internal.h" 28 | 29 | // 30 | #define QUANTIZER(name) LIQUID_CONCAT(quantizerf,name) 31 | 32 | #define T float // general 33 | 34 | #define T_COMPLEX 0 35 | 36 | // prototypes 37 | #include "quantizer.proto.c" 38 | 39 | -------------------------------------------------------------------------------- /sandbox/matrix_eig_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // matrix_eig_test.c 3 | // 4 | // Test eigenvalue computation using Q/R decomposition. Eigenvalues 5 | // will be on diagonal if they are all real. 6 | // 7 | 8 | #include 9 | #include 10 | #include "liquid.h" 11 | 12 | int main() { 13 | unsigned int num_iterations=8; 14 | 15 | #if 0 16 | unsigned int n=4; 17 | float A[16] = { 18 | 1,2,3,4, 19 | 5,5,7,8, 20 | 6,4,8,7, 21 | 1,0,3,1}; 22 | #else 23 | unsigned int n=3; 24 | float A[9] = { 25 | 1.0f, 1.0f, 1.0f, 26 | 1.0f, 2.0f, 1.0f, 27 | 1.0f, 1.0f, 2.0f}; 28 | #endif 29 | 30 | float eig[n]; 31 | float A0[n*n]; 32 | float Q[n*n], R[n*n]; 33 | 34 | memmove(A0, A, n*n*sizeof(float)); 35 | 36 | printf("\n"); 37 | printf("testing Q/R decomposition [Gram-Schmidt]\n"); 38 | matrixf_qrdecomp_gramschmidt(A,n,n,Q,R); 39 | //matrixf_print(Q,n,n); 40 | //matrixf_print(R,n,n); 41 | 42 | unsigned int k; 43 | for (k=0; k 24 | #include "autotest.h" 25 | #include "liquid.h" 26 | 27 | void autotest_libliquid() 28 | { 29 | // test liquid string version 30 | CONTEND_EQUALITY(strcmp(LIQUID_VERSION,liquid_libversion()),0) 31 | 32 | // test liquid integer version 33 | CONTEND_EQUALITY(LIQUID_VERSION_NUMBER, liquid_libversion_number()); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /examples/msequence_example.c: -------------------------------------------------------------------------------- 1 | char __docstr__[] = 2 | "This example demonstrates the property of maximal-length sequence" 3 | " (m-sequence) linear feedback shift registers (LFSR) where the state" 4 | " cycles through all permutations of integers from 1 to 2^m-1."; 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "liquid.h" 12 | #include "liquid.argparse.h" 13 | 14 | int main(int argc, char* argv[]) 15 | { 16 | // define variables and parse command-line arguments 17 | liquid_argparse_init(__docstr__); 18 | //liquid_argparse_add(char*, filename, "msequence_example.m", 'o', "output filename", NULL); 19 | liquid_argparse_add(unsigned, m, 5, 'm', "shift register length, m=2^m-1", NULL); 20 | liquid_argparse_parse(argc,argv); 21 | 22 | // create and initialize m-sequence 23 | msequence q = msequence_create_default(m); 24 | msequence_print(q); 25 | 26 | // cycle through values and print state 27 | unsigned int i; 28 | for (i=0; i 0 && msequence_get_state(q)==1) { 31 | printf("invalid state!\n"); 32 | break; 33 | } 34 | printf("%u\n",msequence_get_state(q)); 35 | msequence_advance(q); 36 | } 37 | 38 | // ensure final state is 1 (circled all the way back around) 39 | printf("final state (should be 1): %u\n", msequence_get_state(q)); 40 | 41 | msequence_destroy(q); 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /.github/workflows/coverage.yml: -------------------------------------------------------------------------------- 1 | name: Code Coverage CI 2 | 3 | on: 4 | workflow_dispatch: 5 | pull_request: 6 | push: 7 | branches: 8 | - master 9 | - cmake-dev 10 | - coverage-dev 11 | - release-dev 12 | 13 | jobs: 14 | standard: 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | runs-on: [ubuntu-latest] 19 | 20 | name: "💦 ${{ matrix.runs-on }}" 21 | runs-on: ${{ matrix.runs-on }} 22 | 23 | steps: 24 | - uses: actions/checkout@v2 25 | 26 | - name: Setup environment (macOS) 27 | if: runner.os == 'macos' 28 | run: | 29 | brew update 30 | brew install cmake virtualenv 31 | 32 | - name: Setup environment (Linux) 33 | if: runner.os == 'Linux' 34 | run: | 35 | sudo apt-get install -y --no-install-recommends build-essential virtualenv 36 | 37 | #- name: Setup libfec 38 | # run: git clone https://github.com/jgaeddert/libfec.git && cd libfec && ./configure && make && sudo make install 39 | 40 | - name: build 41 | run: | 42 | mkdir build 43 | cd build 44 | cmake -DBUILD_AUTOTESTS=ON -DCOVERAGE=ON -DBUILD_BENCHMARKS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_SANDBOX=OFF .. 45 | make -j4 46 | 47 | - name: check 48 | run: | 49 | cd build 50 | ./xautotest -o autotest.json 51 | 52 | - name: upload report to codecov with github action 53 | uses: codecov/codecov-action@v4 54 | with: 55 | fail_ci_if_error: true 56 | verbose: true 57 | token: ${{ secrets.CODECOV_TOKEN }} 58 | -------------------------------------------------------------------------------- /src/dotprod/src/dotprod_rrrf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2022 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // Floating-point dot product 25 | // 26 | 27 | #include "liquid.internal.h" 28 | 29 | #define DOTPROD(name) LIQUID_CONCAT(dotprod_rrrf,name) 30 | #define TO float 31 | #define TC float 32 | #define TI float 33 | 34 | #define TO_COMPLEX 0 35 | #define TC_COMPLEX 0 36 | #define TI_COMPLEX 0 37 | 38 | #include "dotprod.proto.c" 39 | -------------------------------------------------------------------------------- /src/fft/tests/data/fft_data_2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2015 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // autotest fft data for 2-point transform 25 | // 26 | 27 | #include 28 | 29 | float complex fft_test_x2[] = { 30 | -0.442695266914 + -1.176601139920*_Complex_I, 31 | 0.164300702210 + 0.941269951205*_Complex_I}; 32 | 33 | float complex fft_test_y2[] = { 34 | -0.278394564704 + -0.235331188715*_Complex_I, 35 | -0.606995969123 + -2.117871091124*_Complex_I}; 36 | 37 | -------------------------------------------------------------------------------- /examples/platformio_example.c: -------------------------------------------------------------------------------- 1 | char __docstr__[] = "Demonstrate using liquid-dsp with platformio"; 2 | 3 | #include 4 | #include 5 | 6 | #include "liquid.h" 7 | #include "liquid.argparse.h" 8 | 9 | int main(int argc, char* argv[]) 10 | { 11 | // define variables and parse command-line arguments 12 | liquid_argparse_init(__docstr__); 13 | liquid_argparse_parse(argc,argv); 14 | 15 | // create mod/demod objects 16 | modulation_scheme ms = LIQUID_MODEM_QAM16; 17 | 18 | // create the modem objects 19 | modemcf mod = modemcf_create(ms); 20 | modemcf demod = modemcf_create(ms); 21 | 22 | // ensure bits/symbol matches modem description (only 23 | // applicable to certain specific modems) 24 | unsigned int bps = modemcf_get_bps(mod); 25 | modemcf_print(mod); 26 | 27 | unsigned int i; // modulated symbol 28 | unsigned int s; // demodulated symbol 29 | unsigned int num_symbols = 1< 9 | #include 10 | 11 | #include "liquid.h" 12 | #include "liquid.argparse.h" 13 | 14 | int main(int argc, char*argv[]) 15 | { 16 | // define variables and parse command-line options 17 | liquid_argparse_init(__docstr__); 18 | liquid_argparse_add(char*, crc_type, "crc32", 'v', "data integrity check", liquid_argparse_crc); 19 | liquid_argparse_add(unsigned, n, 32, 'n', "original data message length", NULL); 20 | liquid_argparse_parse(argc,argv); 21 | 22 | // validate options 23 | crc_scheme crc = liquid_getopt_str2crc(crc_type); 24 | 25 | unsigned int i; 26 | 27 | // initialize data array, leaving space for key at the end 28 | unsigned char data[n+4]; 29 | for (i=0; i 28 | #include "liquid.internal.h" 29 | 30 | #define DOTPROD(name) LIQUID_CONCAT(dotprod_crcf,name) 31 | #define TO float complex 32 | #define TC float 33 | #define TI float complex 34 | 35 | #define TO_COMPLEX 1 36 | #define TC_COMPLEX 0 37 | #define TI_COMPLEX 1 38 | 39 | #include "dotprod.proto.c" 40 | -------------------------------------------------------------------------------- /src/dotprod/src/dotprod_cccf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2022 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // Complex floating-point dot product 25 | // 26 | 27 | #include 28 | #include "liquid.internal.h" 29 | 30 | #define DOTPROD(name) LIQUID_CONCAT(dotprod_cccf,name) 31 | #define TO float complex 32 | #define TC float complex 33 | #define TI float complex 34 | 35 | #define TO_COMPLEX 1 36 | #define TC_COMPLEX 1 37 | #define TI_COMPLEX 1 38 | 39 | #include "dotprod.proto.c" 40 | -------------------------------------------------------------------------------- /.github/workflows/core.yml: -------------------------------------------------------------------------------- 1 | name: Core C CI 2 | 3 | on: 4 | workflow_dispatch: 5 | pull_request: 6 | push: 7 | 8 | jobs: 9 | standard: 10 | strategy: 11 | fail-fast: false 12 | matrix: 13 | runs-on: [ubuntu-latest, macos-latest] 14 | 15 | name: "💦 ${{ matrix.runs-on }}" 16 | runs-on: ${{ matrix.runs-on }} 17 | 18 | steps: 19 | - uses: actions/checkout@v4 20 | 21 | - name: setup (macos) 22 | if: runner.os == 'macos' 23 | run: | 24 | brew update 25 | brew install cmake 26 | 27 | - name: setup (linux) 28 | if: runner.os == 'Linux' 29 | run: | 30 | sudo apt-get update --fix-missing 31 | sudo apt-get install -y --no-install-recommends cmake valgrind time curl 32 | 33 | #- name: Setup libfec 34 | # run: git clone https://github.com/jgaeddert/libfec.git && cd libfec && ./configure && make && sudo make install 35 | 36 | - name: build 37 | run: | 38 | mkdir build 39 | cd build 40 | cmake .. 41 | make -j2 42 | 43 | - name: check 44 | run: | 45 | cd build 46 | ./xautotest -v -o autotest.json 47 | 48 | - name: install 49 | run: | 50 | cd build 51 | sudo make install 52 | 53 | - name: check installation (macos) 54 | if: runner.os == 'macos' 55 | run: | 56 | gcc -Wall -O2 -rpath /usr/local/lib -o liquid_linker_test scripts/liquid_linker_test.c -lm -lc -lliquid 57 | ./liquid_linker_test 58 | 59 | - name: check installation (linux) 60 | if: runner.os == 'Linux' 61 | run: | 62 | sudo ldconfig 63 | make -f scripts/liquid_linker_test.mk 64 | 65 | -------------------------------------------------------------------------------- /src/vector/src/vectorf.port.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2025 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // vector operatios 24 | 25 | #include "liquid.internal.h" 26 | 27 | #define VECTOR(name) LIQUID_CONCAT(liquid_vectorf,name) 28 | #define T float // input/output type 29 | #define TP float // primitive type 30 | 31 | #define T_COMPLEX 0 // is input type complex 32 | 33 | #include "vector_add.proto.c" 34 | #include "vector_mul.proto.c" 35 | #include "vector_norm.proto.c" 36 | #include "vector_trig.proto.c" 37 | 38 | -------------------------------------------------------------------------------- /src/vector/src/vectorcf.port.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2025 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // vector operatios 24 | 25 | #include "liquid.internal.h" 26 | 27 | #define VECTOR(name) LIQUID_CONCAT(liquid_vectorcf,name) 28 | #define T float complex // input/output type 29 | #define TP float // primitive type 30 | 31 | #define T_COMPLEX 1 // is input type complex 32 | 33 | #include "vector_add.proto.c" 34 | #include "vector_mul.proto.c" 35 | #include "vector_norm.proto.c" 36 | #include "vector_trig.proto.c" 37 | 38 | -------------------------------------------------------------------------------- /src/vector/src/vectorf.avx.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2025 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // vector operatios 24 | 25 | #include "liquid.internal.h" 26 | 27 | #define VECTOR(name) LIQUID_CONCAT(liquid_vectorf,name) 28 | #define T float // input/output type 29 | #define TP float // primitive type 30 | 31 | #define T_COMPLEX 0 // is input type complex 32 | 33 | #include "vector_add.proto.c" 34 | #include "vectorf_mul.avx.c" // AVX version 35 | #include "vector_norm.proto.c" 36 | #include "vector_trig.proto.c" 37 | 38 | -------------------------------------------------------------------------------- /src/fft/tests/data/fft_data_3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2015 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // autotest fft data for 3-point transform 25 | // 26 | 27 | #include 28 | 29 | float complex fft_test_x3[] = { 30 | -0.757661328095 + 0.655250200055*_Complex_I, 31 | -1.262964116539 + 0.804288531547*_Complex_I, 32 | 0.075727215016 + -0.825503865060*_Complex_I}; 33 | 34 | float complex fft_test_y3[] = { 35 | -1.944898229617 + 0.634034866542*_Complex_I, 36 | 1.247398741022 + 1.825198567765*_Complex_I, 37 | -1.575484495691 + -0.493482834141*_Complex_I}; 38 | 39 | -------------------------------------------------------------------------------- /src/vector/src/vectorcf.neon.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2025 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // vector operatios 24 | 25 | #include "liquid.internal.h" 26 | 27 | #define VECTOR(name) LIQUID_CONCAT(liquid_vectorcf,name) 28 | #define T float complex // input/output type 29 | #define TP float // primitive type 30 | 31 | #define T_COMPLEX 1 // is input type complex 32 | 33 | #include "vector_add.proto.c" 34 | #include "vectorcf_mul.neon.c" // neon version 35 | #include "vector_norm.proto.c" 36 | #include "vector_trig.proto.c" 37 | 38 | -------------------------------------------------------------------------------- /examples/windowf_example.c: -------------------------------------------------------------------------------- 1 | char __docstr__[] = 2 | "This example demonstrates the functionality of a window buffer (also" 3 | " known as a circular or ring buffer) of floating-point values. Values" 4 | " are written to and read from the buffer using several different" 5 | " methods."; 6 | 7 | #include 8 | 9 | #include "liquid.h" 10 | #include "liquid.argparse.h" 11 | 12 | int main(int argc, char* argv[]) 13 | { 14 | // define variables and parse command-line arguments 15 | liquid_argparse_init(__docstr__); 16 | liquid_argparse_parse(argc,argv); 17 | 18 | // initialize vector of data for testing 19 | float v[] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; 20 | float *r; // reader 21 | unsigned int i; 22 | 23 | // create window: 10 elements, initialized to 0 24 | // w: 0 0 0 0 0 0 0 0 0 0 25 | windowf w = windowf_create(10); 26 | 27 | // push 4 elements 28 | // w: 0 0 0 0 0 0 1 1 1 1 29 | windowf_push(w, 1); 30 | windowf_push(w, 1); 31 | windowf_push(w, 1); 32 | windowf_push(w, 1); 33 | 34 | // push 4 more elements 35 | // w: 0 0 1 1 1 1 9 8 7 6 36 | windowf_write(w, v, 4); 37 | 38 | // push 4 more elements 39 | // w: 1 1 9 8 7 6 3 3 3 3 40 | windowf_push(w, 3); 41 | windowf_push(w, 3); 42 | windowf_push(w, 3); 43 | windowf_push(w, 3); 44 | 45 | // read the buffer by assigning the pointer 46 | // appropriately 47 | windowf_read(w, &r); 48 | 49 | // manual print 50 | printf("manual output:\n"); 51 | for (i=0; i<10; i++) 52 | printf("%6u : %f\n", i, r[i]); 53 | 54 | windowf_debug_print(w); 55 | 56 | // clean it up 57 | windowf_destroy(w); 58 | 59 | printf("done.\n"); 60 | return 0; 61 | } 62 | 63 | 64 | -------------------------------------------------------------------------------- /src/agc/src/agc_rrrf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2022 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // AGC API: floating-point [real] 25 | // 26 | 27 | #include "liquid.internal.h" 28 | 29 | // naming extensions (useful for print statements) 30 | #define EXTENSION_SHORT "f" 31 | #define EXTENSION_FULL "rrrf" 32 | 33 | // macros 34 | #define AGC(name) LIQUID_CONCAT(agc_rrrf,name) 35 | 36 | #define T float // general 37 | #define TC float // input/output 38 | 39 | #define TC_COMPLEX 0 40 | 41 | // prototypes 42 | #include "agc.proto.c" 43 | -------------------------------------------------------------------------------- /src/agc/src/agc_crcf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2022 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // AGC API: floating-point [complex] 25 | // 26 | 27 | #include "liquid.internal.h" 28 | 29 | // naming extensions (useful for print statements) 30 | #define EXTENSION_SHORT "f" 31 | #define EXTENSION_FULL "crcf" 32 | 33 | // macros 34 | #define AGC(name) LIQUID_CONCAT(agc_crcf,name) 35 | 36 | #define T float // general 37 | #define TC float complex // input/output 38 | 39 | #define TC_COMPLEX 1 40 | 41 | // prototypes 42 | #include "agc.proto.c" 43 | -------------------------------------------------------------------------------- /src/utility/src/memory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2022 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include "liquid.h" 26 | 27 | // allocate memory and copy from original location 28 | // _orig : pointer to original memory array 29 | // _num : number of original elements 30 | // _size : size of each element 31 | void * liquid_malloc_copy(void * _orig, 32 | unsigned int _num, 33 | unsigned int _size) 34 | { 35 | void * copy = malloc(_num * _size); 36 | memmove(copy, _orig, _num * _size); 37 | return copy; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /src/matrix/tests/gendata_write_matrix.m: -------------------------------------------------------------------------------- 1 | % 2 | % write_matrix(fid,x,comment) 3 | % 4 | % write matrix 'x' to file descriptor 'fid' with optional comment 5 | % 6 | function gendata_write_matrix(fid,x,varname,comment) 7 | 8 | if nargin < 3, 9 | error('must specify output file descriptor, input matrix, and variable name'); 10 | elseif nargin < 4, 11 | comment = varname; 12 | end; 13 | 14 | % other options 15 | one_line_per_element = 1; % display one line per element? 16 | print_index_as_comment = 1; % print index of element as comment? 17 | 18 | % get size of matrix 19 | [rows cols] = size(x); 20 | 21 | % even though matrix might have two dimensions, we store it as 22 | % a one-dimensional array 23 | n = rows*cols; 24 | 25 | % determine if matrix is complex or not 26 | if iscomplex(x), 27 | type = 'float complex'; 28 | else, 29 | type = 'float'; 30 | end; 31 | 32 | % write array comment 33 | fprintf(fid,'// %s [size: %u x %u]\n', comment, rows, cols); 34 | 35 | % write variable declaration 36 | fprintf(fid,'%s %s[] = {\n',type, varname); 37 | 38 | % write array data 39 | n=0; 40 | for r=1:rows, 41 | for c=1:cols, 42 | n = n+1; 43 | if iscomplex(x), 44 | fprintf(fid,' %16.12f + %16.12f*_Complex_I', real(x(r,c)), imag(x(r,c))); 45 | else, 46 | fprintf(fid,' %16.12f', real(x(r,c))); 47 | end; 48 | 49 | if print_index_as_comment, 50 | fprintf(fid,' /* (%2u,%2u) */', r-1, c-1); 51 | end; 52 | 53 | if r==rows && c==cols, 54 | fprintf(fid,'};\n'); 55 | elseif c==cols || one_line_per_element, 56 | fprintf(fid,',\n'); 57 | else, 58 | fprintf(fid,', '); 59 | end; 60 | end; 61 | end; 62 | fprintf(fid,'\n'); 63 | 64 | -------------------------------------------------------------------------------- /src/matrix/src/smatrix.common.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2015 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // sparse matrices: common methods 25 | // 26 | 27 | // search for index placement in list 28 | unsigned short int smatrix_indexsearch(unsigned short int * _list, 29 | unsigned int _num_elements, 30 | unsigned short int _value) 31 | { 32 | // TODO: use bisection method 33 | 34 | unsigned int i; 35 | for (i=0; i<_num_elements; i++) { 36 | if (_list[i] > _value) 37 | break; 38 | } 39 | 40 | // 41 | return i; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /examples/wdelayf_example.c: -------------------------------------------------------------------------------- 1 | char __docstr__[] = "Demonstration of wdelayf object"; 2 | 3 | #include 4 | 5 | #include "liquid.h" 6 | #include "liquid.argparse.h" 7 | 8 | int main(int argc, char* argv[]) 9 | { 10 | // define variables and parse command-line arguments 11 | liquid_argparse_init(__docstr__); 12 | liquid_argparse_add(char*, filename, "wdelayf_example.m", 'o', "output filename", NULL); 13 | liquid_argparse_add(unsigned, delay, 10, 'm', "delay [samples]", NULL); 14 | liquid_argparse_add(unsigned, num_samples, 64, 'n', "number of samples", NULL); 15 | liquid_argparse_parse(argc,argv); 16 | 17 | // create wdelay, all elements initialized to 0 18 | wdelayf w = wdelayf_create(delay); 19 | float y; // output 20 | 21 | FILE * fid = fopen(filename,"w"); 22 | fprintf(fid,"%% %s : auto-generated file\n", filename); 23 | fprintf(fid,"clear all;\n"); 24 | fprintf(fid,"close all;\n"); 25 | fprintf(fid,"num_samples = %u;\n", num_samples); 26 | fprintf(fid,"delay = %u;\n", delay); 27 | 28 | // push several elements 29 | unsigned int i; 30 | float x; 31 | for (i=0; i 29 | #include 30 | #include 31 | 32 | #include "benchmarkgen.h" 33 | 34 | int main(int argc, char*argv[]) 35 | { 36 | // create benchmarkgen object 37 | benchmarkgen q = benchmarkgen_create(); 38 | 39 | // parse files 40 | int i; 41 | for (i=1; i 28 | 29 | float complex fft_test_x4[] = { 30 | -2.218920151449 + -1.079004048069*_Complex_I, 31 | 0.045264423484 + 0.426155393025*_Complex_I, 32 | 0.218614474268 + -0.334711618319*_Complex_I, 33 | 2.182538230032 + 1.706944462070*_Complex_I}; 34 | 35 | float complex fft_test_y4[] = { 36 | 0.227496976335 + 0.719384188708*_Complex_I, 37 | -3.718323694762 + 1.392981376798*_Complex_I, 38 | -4.228108330697 + -3.546815521483*_Complex_I, 39 | -1.156745556672 + -2.881566236299*_Complex_I}; 40 | 41 | -------------------------------------------------------------------------------- /sandbox/simplex_test.c: -------------------------------------------------------------------------------- 1 | // simplex method for solving linear programming problems 2 | #include 3 | #include 4 | #include "liquid.h" 5 | 6 | void matrixf_pivot2(float * _x, 7 | unsigned int _m, 8 | unsigned int _n, 9 | unsigned int _i, 10 | unsigned int _j) 11 | { 12 | float v = 1.0f / matrix_access(_x,_m,_n,_i,_j); 13 | 14 | float g; // multiplier 15 | unsigned int r,c; 16 | for (r=0; r<_m; r++) { 17 | // skip over pivot row 18 | if (r == _i) continue; 19 | 20 | // compute multiplier 21 | g = matrix_access(_x,_m,_n,r,_j) * v; 22 | 23 | // back-substitution 24 | for (c=0; c<_n; c++) { 25 | matrix_access(_x,_m,_n,r,c) -= matrix_access(_x,_m,_n,_i,c)*g; 26 | } 27 | } 28 | 29 | // normalize row by multiplier 30 | for (c=0; c<_n; c++) 31 | matrix_access(_x,_m,_n,_i,c) *= v; 32 | } 33 | 34 | int main() { 35 | // problem definition 36 | float x[18] = { 37 | 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 38 | 0.0f, 2.0f, 1.0f, 1.0f, 0.0f, 4.0f, 39 | 0.0f, 1.0f, 2.0f, 0.0f, 1.0f, 3.0f 40 | }; 41 | unsigned int r = 3; 42 | unsigned int c = 6; 43 | 44 | matrixf_print(x,r,c); 45 | 46 | // pivot around x(1,1) = 2 47 | matrixf_pivot2(x,r,c, 1,1); 48 | matrixf_print(x,r,c); 49 | 50 | // pivot around x(2,2) = 1.5 51 | matrixf_pivot2(x,r,c, 2,2); 52 | matrixf_print(x,r,c); 53 | 54 | // print solution 55 | printf("solution:\n"); 56 | printf("z : %12.8f\n", matrixf_access(x,r,c,0,c-1)); 57 | unsigned int i; 58 | for (i=1; i 24 | #include 25 | 26 | // null benchmark 27 | void benchmark_null(struct rusage *_start, 28 | struct rusage *_finish, 29 | unsigned long int *_num_iterations) 30 | { 31 | unsigned long int i; 32 | *_num_iterations *= 100; 33 | 34 | getrusage(RUSAGE_SELF, _start); 35 | unsigned int x = 0; 36 | for (i=0; i<*_num_iterations; i++) { 37 | // perform mindless task 38 | x <<= 1; 39 | x |= 1; 40 | x &= 0xff; 41 | x ^= 0xff; 42 | } 43 | *_num_iterations += (x & 0x1234) ? 0 : 1; 44 | getrusage(RUSAGE_SELF, _finish); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /sandbox/thiran_allpass_iir_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // thiran_allpass_iir_test.c 3 | // 4 | // Test thiran allpass interpolator 5 | // 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "liquid.internal.h" 13 | 14 | void compute_thiran_allpass(unsigned int _n, 15 | float _mu, 16 | float * _b, 17 | float * _a); 18 | 19 | int main() 20 | { 21 | unsigned int n = 4; 22 | float mu = 0.1f; 23 | 24 | float b[n+1]; 25 | float a[n+1]; 26 | 27 | // compute filter coefficients 28 | compute_thiran_allpass(n,mu,b,a); 29 | 30 | // print coefficients to screen 31 | unsigned int i; 32 | for (i=0; i<=n; i++) 33 | printf("a(%3u) = %12.8f; b(%3u) = %12.8f;\n", i+1, a[i], i+1, b[i]); 34 | 35 | // compute group delay 36 | float g = iir_group_delay(b,n+1,a,n+1,0.0f); 37 | 38 | printf(" g = %f\n", g); 39 | 40 | printf("done.\n"); 41 | return 0; 42 | } 43 | 44 | void compute_thiran_allpass(unsigned int _n, 45 | float _mu, 46 | float * _b, 47 | float * _a) 48 | { 49 | float nf = (float)_n; 50 | 51 | unsigned int k; 52 | for (k=0; k<=_n; k++) { 53 | _a[k] = ((k%2)==0 ? 1.0f : -1.0f) * liquid_nchoosek(_n, k); 54 | 55 | // check condition when mu is very small (eliminate divide-by-zero) 56 | if ( fabsf(_mu) < 1e-6f ) { 57 | _a[k] = _a[k]*_a[k]; 58 | continue; 59 | } 60 | 61 | // TODO : expand as sum of logarithms 62 | unsigned int n; 63 | for (n=0; n<=_n; n++) { 64 | _a[k] *= (_mu - nf + (float)n) / (_mu - nf + (float)(n+k)); 65 | } 66 | } 67 | 68 | for (k=0; k<=_n; k++) 69 | _b[k] = _a[_n-k]; 70 | } 71 | 72 | -------------------------------------------------------------------------------- /src/matrix/src/smatrixf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2022 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // sparse matrix API: float 25 | // 26 | 27 | #include 28 | #include 29 | #include 30 | #include "liquid.internal.h" 31 | 32 | // macro 33 | #define SMATRIX(name) LIQUID_CONCAT(smatrixf,name) 34 | #define EXTENSION "f" 35 | 36 | // primitive type 37 | #define T float 38 | 39 | // category (float/int/bool) 40 | #define SMATRIX_FLOAT 1 41 | #define SMATRIX_INT 0 42 | #define SMATRIX_BOOL 0 43 | 44 | // print macros 45 | #define PRINTVAL_ZERO() printf(" %6s", "."); 46 | #define PRINTVAL(V) printf(" %6.2f", V); 47 | 48 | // prototypes 49 | #include "smatrix.proto.c" 50 | -------------------------------------------------------------------------------- /examples/firfilt_crcf_copy_example.c: -------------------------------------------------------------------------------- 1 | char __docstr__[] = "Demonstrate filter copy operation"; 2 | 3 | #include 4 | #include 5 | #include 6 | #include "liquid.h" 7 | #include "liquid.argparse.h" 8 | 9 | int main(int argc, char* argv[]) 10 | { 11 | // define variables and parse command-line arguments 12 | liquid_argparse_init(__docstr__); 13 | liquid_argparse_parse(argc,argv); 14 | 15 | // design filter from prototype 16 | firfilt_crcf filt_orig = firfilt_crcf_create_kaiser(21, 0.345f, 60.0f, 0.0f); 17 | firfilt_crcf_set_scale(filt_orig, 2.0f); 18 | firfilt_crcf_print(filt_orig); 19 | 20 | // start running input through filter 21 | unsigned int n = 32; 22 | unsigned int i; 23 | float complex x, y_orig, y_copy; 24 | for (i=0; iv[I]); 41 | #define BUFFER_PRINT_VALUE(V) \ 42 | printf(" : %12.4e", V); 43 | 44 | // prototypes 45 | #include "cbuffer.proto.c" 46 | #include "wdelay.proto.c" 47 | #include "window.proto.c" 48 | 49 | -------------------------------------------------------------------------------- /src/matrix/src/smatrixi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2022 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // sparse matrix API: short signed integer 25 | // 26 | 27 | #include 28 | #include 29 | #include 30 | #include "liquid.internal.h" 31 | 32 | // name-mangling macro 33 | #define SMATRIX(name) LIQUID_CONCAT(smatrixi,name) 34 | #define EXTENSION "i" 35 | 36 | // primitive type 37 | #define T short int 38 | 39 | // category (float/int/bool) 40 | #define SMATRIX_FLOAT 0 41 | #define SMATRIX_INT 1 42 | #define SMATRIX_BOOL 0 43 | 44 | // print macros 45 | #define PRINTVAL_ZERO() printf(" ."); 46 | #define PRINTVAL(V) printf(" %3d", V); 47 | 48 | // prototypes 49 | #include "smatrix.proto.c" 50 | 51 | -------------------------------------------------------------------------------- /src/fft/tests/fft_small_autotest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2015 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // fft_small_autotest.c : test small transforms 25 | // 26 | 27 | #include "autotest/autotest.h" 28 | #include "liquid.h" 29 | 30 | // autotest data definitions 31 | #include "src/fft/tests/fft_runtest.h" 32 | 33 | // 34 | // AUTOTESTS: small FFTs 35 | // 36 | void autotest_fft_3() { fft_test( fft_test_x4, fft_test_y4, 4); } 37 | void autotest_fft_5() { fft_test( fft_test_x5, fft_test_y5, 5); } 38 | void autotest_fft_6() { fft_test( fft_test_x6, fft_test_y6, 6); } 39 | void autotest_fft_7() { fft_test( fft_test_x7, fft_test_y7, 7); } 40 | void autotest_fft_9() { fft_test( fft_test_x9, fft_test_y9, 9); } 41 | 42 | -------------------------------------------------------------------------------- /src/fft/tests/data/fft_data_5.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2015 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // autotest fft data for 5-point transform 25 | // 26 | 27 | #include 28 | 29 | float complex fft_test_x5[] = { 30 | 1.043452789296 + -0.216675780077*_Complex_I, 31 | -0.039259154719 + -0.756503590362*_Complex_I, 32 | -1.378329383804 + -1.629692578129*_Complex_I, 33 | 0.695728357044 + -2.639675956000*_Complex_I, 34 | -0.019932891052 + 0.123958045411*_Complex_I}; 35 | 36 | float complex fft_test_y5[] = { 37 | 0.301659716765 + -5.118589859158*_Complex_I, 38 | 1.333681830770 + 4.279329517647*_Complex_I, 39 | -0.597668794979 + -2.985429553632*_Complex_I, 40 | 2.358478480201 + 0.936943320049*_Complex_I, 41 | 1.821112713724 + 1.804367674708*_Complex_I}; 42 | 43 | -------------------------------------------------------------------------------- /src/filter/tests/data/firfilt_rrrf_data_h4x8.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2015 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // firfilt_rrrf_data_h4x8.c: autotest firfilt data 25 | // 26 | 27 | float firfilt_rrrf_data_h4x8_h[] = { 28 | -0.121887159208, 29 | -0.231303112477, 30 | -0.011081038093, 31 | 0.002940945390}; 32 | 33 | float firfilt_rrrf_data_h4x8_x[] = { 34 | 0.087523073427, 35 | 0.091626543082, 36 | 0.069905988906, 37 | -0.025530671018, 38 | -0.085926435885, 39 | 0.016121796124, 40 | 0.067241716218, 41 | 0.036151454364}; 42 | 43 | float firfilt_rrrf_data_h4x8_y[] = { 44 | -0.010667938785, 45 | -0.031412458342, 46 | -0.030683993510, 47 | -0.013815528486, 48 | 0.015873490575, 49 | 0.018398508167, 50 | -0.011047853592, 51 | -0.020390967516}; 52 | 53 | -------------------------------------------------------------------------------- /sandbox/fec_sumproduct_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // fec_sumproduct_test.c 3 | // 4 | // Test soft decoding of LDPC codes using internal sum-product 5 | // algorithm. 6 | // 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "liquid.internal.h" 13 | 14 | int main(int argc, char*argv[]) 15 | { 16 | // parity check matrix 17 | unsigned char Hb[32] = { 18 | 1, 1, 1, 0, 0, 0, 0, 0, 19 | 0, 0, 0, 1, 1, 1, 0, 0, 20 | 1, 0, 0, 1, 0, 0, 1, 0, 21 | 0, 1, 0, 0, 1, 0, 0, 1}; 22 | 23 | // convert H to sparse matrix 24 | smatrixb H = smatrixb_create_array(Hb, 4, 8); 25 | 26 | // transmitted codeword 27 | unsigned char c[8] = { 28 | 1, 0, 1, 0, 1, 1, 1, 1}; 29 | 30 | // received message 31 | float y[8] = {0.2, 0.2, -0.9, 0.6, 0.5, -1.1, -0.4, -1.2}; 32 | unsigned int i; 33 | 34 | // noise standard deviation 35 | float sigma = sqrtf(0.5f); 36 | 37 | unsigned int m = 4; 38 | unsigned int n = 8; 39 | 40 | // convert received signal to LLR 41 | float LLR[n]; 42 | for (i=0; iv[I]), cimagf(B->v[I])); 41 | #define BUFFER_PRINT_VALUE(V) \ 42 | printf(" : %12.4e + %12.4e", crealf(V), cimagf(V)); 43 | 44 | // prototypes 45 | #include "cbuffer.proto.c" 46 | #include "window.proto.c" 47 | #include "wdelay.proto.c" 48 | 49 | -------------------------------------------------------------------------------- /sandbox/fec_hamming128_gentab.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2015 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // 2/3-rate (12,8) Hamming code encoding table generator 25 | // 26 | 27 | #include 28 | #include 29 | 30 | #include "liquid.internal.h" 31 | 32 | int main() 33 | { 34 | unsigned int i; 35 | unsigned int c; 36 | 37 | printf("unsigned short int hamming128_enc_gentab[256] = {\n "); 38 | 39 | for (i=0; i<256; i++) { 40 | // encode symbol 41 | c = fec_hamming128_encode_symbol(i); 42 | 43 | // print result 44 | printf("0x%.4x", c); 45 | if (i != 255) 46 | printf(", "); 47 | else 48 | printf("};"); 49 | 50 | if ( ((i+1)%8) == 0) 51 | printf("\n "); 52 | } 53 | printf("\n"); 54 | 55 | return 0; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /examples/firdes_doppler_example.c: -------------------------------------------------------------------------------- 1 | char __docstr__[] = 2 | "This example demonstrates finite impulse response Doppler filter design"; 3 | 4 | #include 5 | #include 6 | #include "liquid.h" 7 | #include "liquid.argparse.h" 8 | 9 | int main(int argc, char* argv[]) 10 | { 11 | // define variables and parse command-line options 12 | liquid_argparse_init(__docstr__); 13 | liquid_argparse_add(char*, filename, "firdes_doppler_example.m", 'o', "output filename", NULL); 14 | liquid_argparse_add(float, fd, 0.2, 'f', "Normalized Doppler frequency", NULL); 15 | liquid_argparse_add(float, K, 10, 'K', "Rice fading factor", NULL); 16 | liquid_argparse_add(float, theta, 0, 't', "LoS component angle of arrival", NULL); 17 | liquid_argparse_add(unsigned, h_len, 161, 'p', "filter length", NULL); 18 | liquid_argparse_parse(argc,argv); 19 | 20 | // generate the filter 21 | float h[h_len]; 22 | liquid_firdes_doppler(h_len,fd,K,theta,h); 23 | 24 | // output to file 25 | FILE*fid = fopen(filename,"w"); 26 | fprintf(fid,"%% %s: auto-generated file\n\n", filename); 27 | fprintf(fid,"clear all;\nclose all;\n\n"); 28 | fprintf(fid,"h_len=%u;\n",h_len); 29 | unsigned int i; 30 | for (i=0; i 4 | #include 5 | #include 6 | 7 | #include "liquid.h" 8 | #include "liquid.argparse.h" 9 | 10 | int main(int argc, char* argv[]) 11 | { 12 | // define variables and parse command-line options 13 | liquid_argparse_init(__docstr__); 14 | liquid_argparse_add(char*, filename, "math_lngamma_example.m", 'o', "output filename", NULL); 15 | liquid_argparse_add(unsigned, n, 256, 'n', "number of steps", NULL); 16 | liquid_argparse_add(float, zmin, 1e-3f, 'z', "minimum value", NULL); 17 | liquid_argparse_add(float, zmax, 6.00f, 'Z', "maximum value", NULL); 18 | liquid_argparse_parse(argc,argv); 19 | 20 | unsigned int d = n/32; // print every d values to screen 21 | 22 | // log scale values 23 | float xmin = logf(zmin); 24 | float xmax = logf(zmax); 25 | float dx = (xmax-xmin)/(n-1); 26 | 27 | FILE * fid = fopen(filename,"w"); 28 | fprintf(fid,"clear all;\n"); 29 | fprintf(fid,"close all;\n"); 30 | unsigned int i; 31 | float z; 32 | float g; 33 | float x = xmin; // log(z) 34 | for (i=0; i 4 | #include 5 | #include 6 | #include "liquid.h" 7 | #include "liquid.argparse.h" 8 | 9 | int main(int argc, char*argv[]) 10 | { 11 | // define variables and parse command-line options 12 | liquid_argparse_init(__docstr__); 13 | liquid_argparse_add(char*, filename, "firdespm_halfband_example.m", 'o', "output filename", NULL); 14 | liquid_argparse_add(unsigned, m, 12, 'm', "filter semi-length", NULL); 15 | liquid_argparse_add(float, As, 60, 'a', "filter stop-band attenuation [dB]", NULL); 16 | liquid_argparse_parse(argc,argv); 17 | 18 | // derived values 19 | unsigned int h_len = 4*m + 1; 20 | float h[h_len]; 21 | liquid_firdespm_halfband_as(m, As, h); 22 | 23 | // print coefficients 24 | unsigned int i; 25 | for (i=0; i 31 | 32 | #define LIQUID_FFT_BENCHMARK_API(NFFT,D) \ 33 | ( struct rusage *_start, \ 34 | struct rusage *_finish, \ 35 | unsigned long int *_num_iterations) \ 36 | { fft_runbench(_start, _finish, _num_iterations, NFFT, D); } 37 | 38 | // Helper function to keep code base small 39 | void fft_runbench(struct rusage * _start, 40 | struct rusage * _finish, 41 | unsigned long int * _num_iterations, 42 | unsigned int _nfft, 43 | int _direction); 44 | 45 | #endif // __FFT_RUNBENCH_H__ 46 | 47 | -------------------------------------------------------------------------------- /src/fft/tests/fft_radix2_autotest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2015 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // fft_radix2_autotest.c : test power-of-two transforms 25 | // 26 | 27 | #include "autotest/autotest.h" 28 | #include "liquid.h" 29 | 30 | // autotest data definitions 31 | #include "src/fft/tests/fft_runtest.h" 32 | 33 | // 34 | // AUTOTESTS: power-of-two transforms 35 | // 36 | void autotest_fft_2() { fft_test( fft_test_x2, fft_test_y2, 2); } 37 | void autotest_fft_4() { fft_test( fft_test_x4, fft_test_y4, 4); } 38 | void autotest_fft_8() { fft_test( fft_test_x8, fft_test_y8, 8); } 39 | void autotest_fft_16() { fft_test( fft_test_x16, fft_test_y16, 16); } 40 | void autotest_fft_32() { fft_test( fft_test_x32, fft_test_y32, 32); } 41 | void autotest_fft_64() { fft_test( fft_test_x64, fft_test_y64, 64); } 42 | 43 | -------------------------------------------------------------------------------- /src/matrix/tests/gendata_write_header.m: -------------------------------------------------------------------------------- 1 | % 2 | % write_header(fid,comment) 3 | % 4 | % write copyright and header to file descriptor 'fid' with optional comment 5 | % 6 | function gendata_write_header(fid,comment) 7 | 8 | if nargin < 2, 9 | comment = 'auto-generated data file'; 10 | end; 11 | 12 | fprintf(fid,'/* Copyright (c) 2007 - 2015 Joseph Gaeddert\n'); 13 | fprintf(fid,' *\n'); 14 | fprintf(fid,' * Permission is hereby granted, free of charge, to any person obtaining a copy\n'); 15 | fprintf(fid,' * of this software and associated documentation files (the "Software"), to deal\n'); 16 | fprintf(fid,' * in the Software without restriction, including without limitation the rights\n'); 17 | fprintf(fid,' * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n'); 18 | fprintf(fid,' * copies of the Software, and to permit persons to whom the Software is\n'); 19 | fprintf(fid,' * furnished to do so, subject to the following conditions:\n'); 20 | fprintf(fid,' * \n'); 21 | fprintf(fid,' * The above copyright notice and this permission notice shall be included in\n'); 22 | fprintf(fid,' * all copies or substantial portions of the Software.\n'); 23 | fprintf(fid,' *\n'); 24 | fprintf(fid,' * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n'); 25 | fprintf(fid,' * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n'); 26 | fprintf(fid,' * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n'); 27 | fprintf(fid,' * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n'); 28 | fprintf(fid,' * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n'); 29 | fprintf(fid,' * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n'); 30 | fprintf(fid,' * THE SOFTWARE.\n'); 31 | fprintf(fid,' */\n'); 32 | fprintf(fid,'\n'); 33 | fprintf(fid,'//\n'); 34 | fprintf(fid,'// %s\n', comment); 35 | fprintf(fid,'//\n'); 36 | fprintf(fid,'\n'); 37 | fprintf(fid,'#include \n'); 38 | fprintf(fid,'\n'); 39 | 40 | -------------------------------------------------------------------------------- /examples/libliquid_example.c: -------------------------------------------------------------------------------- 1 | char __docstr__[] = "Test libliquid library versioning"; 2 | 3 | #include 4 | #include 5 | #include "liquid.h" 6 | #include "liquid.argparse.h" 7 | 8 | int main(int argc, char* argv[]) 9 | { 10 | // define variables and parse command-line arguments 11 | liquid_argparse_init(__docstr__); 12 | liquid_argparse_parse(argc,argv); 13 | 14 | // validate that the included header matches linked version 15 | LIQUID_VALIDATE_LIBVERSION; 16 | 17 | // print values 18 | printf("liquid version : %s\n", liquid_version); 19 | printf("liquid libversion : %s\n", liquid_libversion()); 20 | printf("liquid libversion number : 0x%.6x\n", liquid_libversion_number()); 21 | 22 | // consistent check for library versions given than starting with 1.7.0 version number 23 | // representation changed 24 | int liquid_version_major = 0; 25 | int liquid_version_minor = 0; 26 | int liquid_version_patch = 0; 27 | if (LIQUID_VERSION_NUMBER >= 1000000) { 28 | // strip major/minor/patch values using base-10 logic 29 | liquid_version_major = (LIQUID_VERSION_NUMBER / 1000000); 30 | liquid_version_minor = (LIQUID_VERSION_NUMBER - 1000000*liquid_version_major) / 1000; 31 | liquid_version_patch = (LIQUID_VERSION_NUMBER % 1000); 32 | } else { 33 | // strip major/minor/patch values using bit masks 34 | liquid_version_major = (LIQUID_VERSION_NUMBER >> 16) & 0xff; 35 | liquid_version_minor = (LIQUID_VERSION_NUMBER >> 8) & 0xff; 36 | liquid_version_patch = (LIQUID_VERSION_NUMBER ) & 0xff; 37 | // alterantively we could check for the existence of these macros 38 | //liquid_version_major = LIQUID_VERSION_MAJOR; 39 | //liquid_version_minor = LIQUID_VERSION_MINOR; 40 | //liquid_version_patch = LIQUID_VERSION_PATCH; 41 | } 42 | printf("major = %d, minor = %d, patch = %d\n", 43 | liquid_version_major, liquid_version_minor, liquid_version_patch); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /src/fft/tests/data/fft_data_6.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2015 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // autotest fft data for 6-point transform 25 | // 26 | 27 | #include 28 | 29 | float complex fft_test_x6[] = { 30 | -0.946868805918 + 0.048419613876*_Complex_I, 31 | -1.426556442325 + 1.356194807524*_Complex_I, 32 | 0.262357323076 + 1.594616904796*_Complex_I, 33 | -1.032912520662 + 0.046391595464*_Complex_I, 34 | -0.271359734201 + -2.390517158747*_Complex_I, 35 | -0.288151144041 + 0.071324517238*_Complex_I}; 36 | 37 | float complex fft_test_y6[] = { 38 | -3.703491324072 + 0.726430280150*_Complex_I, 39 | 3.797148775593 + 1.637413185851*_Complex_I, 40 | -3.456423352393 + 1.227102112087*_Complex_I, 41 | 1.791748889984 + -2.221391560299*_Complex_I, 42 | 1.220570696725 + -1.669098764217*_Complex_I, 43 | -5.330766521347 + 0.590062429687*_Complex_I}; 44 | 45 | -------------------------------------------------------------------------------- /src/filter/tests/ordfilt_autotest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2022 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #include "autotest/autotest.h" 24 | #include "liquid.h" 25 | 26 | // test copy method 27 | void autotest_ordfilt_copy() 28 | { 29 | // create base object 30 | ordfilt_rrrf q0 = ordfilt_rrrf_create(17, 5); 31 | 32 | // run samples through filter 33 | unsigned int i; 34 | float y0, y1; 35 | for (i=0; i<20; i++) { 36 | float v = randnf(); 37 | ordfilt_rrrf_execute_one(q0, v, &y0); 38 | } 39 | 40 | // copy object 41 | ordfilt_rrrf q1 = ordfilt_rrrf_copy(q0); 42 | 43 | // run samples through both filters in parallel 44 | for (i=0; i<60; i++) { 45 | float v = randnf(); 46 | ordfilt_rrrf_execute_one(q0, v, &y0); 47 | ordfilt_rrrf_execute_one(q1, v, &y1); 48 | 49 | CONTEND_EQUALITY(y0, y1); 50 | } 51 | 52 | // destroy objects 53 | ordfilt_rrrf_destroy(q0); 54 | ordfilt_rrrf_destroy(q1); 55 | } 56 | 57 | -------------------------------------------------------------------------------- /src/fec/src/fec_conv_poly.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2015 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // convolutional code polynomials 25 | // 26 | 27 | #include "liquid.internal.h" 28 | 29 | #if LIBFEC_ENABLED 30 | #include 31 | 32 | int fec_conv27_poly[2] = {V27POLYA, 33 | V27POLYB}; 34 | 35 | int fec_conv29_poly[2] = {V29POLYA, 36 | V29POLYB}; 37 | 38 | int fec_conv39_poly[3] = {V39POLYA, 39 | V39POLYB, 40 | V39POLYC}; 41 | 42 | int fec_conv615_poly[6] = {V615POLYA, 43 | V615POLYB, 44 | V615POLYC, 45 | V615POLYD, 46 | V615POLYE, 47 | V615POLYF}; 48 | 49 | #else 50 | 51 | int fec_conv27_poly[2] = {0,0}; 52 | int fec_conv29_poly[2] = {0,0}; 53 | int fec_conv39_poly[3] = {0,0,0}; 54 | int fec_conv615_poly[6] = {0,0,0,0,0,0}; 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /bench/example_benchmark.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2015 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // Example of a benchmark header 25 | // 26 | 27 | #include 28 | #include 29 | 30 | // strings parsed by benchmarkgen.py 31 | const char * mybench_opts[3] = { 32 | "opt1a opt1b", 33 | "opt2a opt2b opt2c", 34 | "opt3a opt3b opt3c" 35 | }; 36 | 37 | 38 | void benchmark_mybench( 39 | struct rusage *_start, 40 | struct rusage *_finish, 41 | unsigned long int *_num_iterations) 42 | // unsigned int argc, 43 | // char *argv[]) 44 | { 45 | // DSP initiazation goes here 46 | 47 | unsigned int i; 48 | float x, y, theta; 49 | getrusage(RUSAGE_SELF, _start); 50 | for (i=0; i<(*_num_iterations); i++) { 51 | // DSP execution goes here 52 | x = cosf(M_PI/2.0f); 53 | y = sinf(M_PI/2.0f); 54 | theta = atan2(y,x); 55 | } 56 | getrusage(RUSAGE_SELF, _finish); 57 | 58 | // DSP cleanup goes here 59 | } 60 | 61 | 62 | -------------------------------------------------------------------------------- /scripts/example_benchmark.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2015 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // Example of a benchmark header 25 | // 26 | 27 | #include 28 | #include 29 | 30 | // strings parsed by benchmarkgen.py 31 | const char * mybench_opts[3] = { 32 | "opt1a opt1b", 33 | "opt2a opt2b opt2c", 34 | "opt3a opt3b opt3c" 35 | }; 36 | 37 | 38 | void benchmark_mybench( 39 | struct rusage *_start, 40 | struct rusage *_finish, 41 | unsigned long int *_num_iterations) 42 | // unsigned int argc, 43 | // char *argv[]) 44 | { 45 | // DSP initiazation goes here 46 | 47 | unsigned int i; 48 | float x, y, theta; 49 | getrusage(RUSAGE_SELF, _start); 50 | for (i=0; i<(*_num_iterations); i++) { 51 | // DSP execution goes here 52 | x = cosf(M_PI/2.0f); 53 | y = sinf(M_PI/2.0f); 54 | theta = atan2(y,x); 55 | } 56 | getrusage(RUSAGE_SELF, _finish); 57 | 58 | // DSP cleanup goes here 59 | } 60 | 61 | 62 | -------------------------------------------------------------------------------- /src/matrix/src/matrix.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2022 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // Floating-point matrix (double precision) 25 | // 26 | 27 | #include "liquid.internal.h" 28 | 29 | #define MATRIX(name) LIQUID_CONCAT(matrix, name) 30 | #define MATRIX_NAME "matrix" 31 | 32 | #define T double // general type 33 | #define TP double // primitive type 34 | #define T_COMPLEX 0 // is type complex? 35 | 36 | #define T_ABS(X) fabs(X) 37 | #define TP_ABS(X) fabs(X) 38 | 39 | #define MATRIX_PRINT_ELEMENT(X,R,C,r,c) \ 40 | printf("%12.8f", matrix_access(X,R,C,r,c)); 41 | 42 | // prototypes 43 | #include "matrix.base.proto.c" 44 | #include "matrix.cgsolve.proto.c" 45 | #include "matrix.chol.proto.c" 46 | #include "matrix.gramschmidt.proto.c" 47 | #include "matrix.inv.proto.c" 48 | #include "matrix.linsolve.proto.c" 49 | #include "matrix.ludecomp.proto.c" 50 | #include "matrix.qrdecomp.proto.c" 51 | #include "matrix.math.proto.c" 52 | 53 | -------------------------------------------------------------------------------- /examples/interleaver_example.c: -------------------------------------------------------------------------------- 1 | char __docstr__[] = 2 | "This example demonstrates the functionality of the liquid" 3 | " interleaver object. Interleavers serve to distribute" 4 | " grouped bit errors evenly throughout a block of data. This" 5 | " aids certain forward error-correction codes in correcting" 6 | " bit errors. In this example, data bits are interleaved and" 7 | " de-interleaved; the resulting sequence is validated to" 8 | " match the original."; 9 | 10 | #include 11 | #include // for rand() 12 | 13 | #include "liquid.h" 14 | #include "liquid.argparse.h" 15 | 16 | int main(int argc, char*argv[]) 17 | { 18 | // define variables and parse command-line arguments 19 | liquid_argparse_init(__docstr__); 20 | //liquid_argparse_add(char*, filename, "interleaver_example.m", 'o', "output filename", NULL); 21 | liquid_argparse_add(unsigned, n, 64, 'n', "message length", NULL); 22 | liquid_argparse_parse(argc,argv); 23 | 24 | // create the interleaver 25 | interleaver q = interleaver_create(n); 26 | interleaver_set_depth(q, 4); 27 | interleaver_print(q); 28 | 29 | // create arrays 30 | unsigned char x[n]; // original message data 31 | unsigned char y[n]; // interleaved data 32 | unsigned char z[n]; // de-interleaved data 33 | 34 | // generate random data sequence 35 | unsigned int i; 36 | for (i=0; i 28 | 29 | float complex fft_test_x7[] = { 30 | 0.325737557343 + 0.347762560645*_Complex_I, 31 | -0.464568614672 + 1.344201995758*_Complex_I, 32 | -1.458140194879 + 0.983317270098*_Complex_I, 33 | 1.679041515327 + 1.025013762005*_Complex_I, 34 | -0.178483024495 + -0.711524629930*_Complex_I, 35 | 0.986194459374 + -1.709315563086*_Complex_I, 36 | 0.387998802736 + -1.150726066104*_Complex_I}; 37 | 38 | float complex fft_test_y7[] = { 39 | 1.277780500734 + 0.128729329387*_Complex_I, 40 | 4.360250363806 + 2.591163135631*_Complex_I, 41 | 1.609972293897 + 2.377175130550*_Complex_I, 42 | 0.436888889637 + -3.701058823864*_Complex_I, 43 | -0.903757801309 + 3.003131513942*_Complex_I, 44 | 1.797162255231 + -0.068636624441*_Complex_I, 45 | -6.298133600593 + -1.896165736688*_Complex_I}; 46 | 47 | -------------------------------------------------------------------------------- /src/matrix/src/matrixf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2022 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // Floating-point matrix (single precision) 25 | // 26 | 27 | #include "liquid.internal.h" 28 | 29 | #define MATRIX(name) LIQUID_CONCAT(matrixf, name) 30 | #define MATRIX_NAME "matrixf" 31 | 32 | #define T float // general type 33 | #define TP float // primitive type 34 | #define T_COMPLEX 0 // is type complex? 35 | 36 | #define T_ABS(X) fabsf(X) 37 | #define TP_ABS(X) fabsf(X) 38 | 39 | #define MATRIX_PRINT_ELEMENT(X,R,C,r,c) \ 40 | printf("%12.7f", matrix_access(X,R,C,r,c)); 41 | 42 | // prototypes 43 | #include "matrix.base.proto.c" 44 | #include "matrix.cgsolve.proto.c" 45 | #include "matrix.chol.proto.c" 46 | #include "matrix.gramschmidt.proto.c" 47 | #include "matrix.inv.proto.c" 48 | #include "matrix.linsolve.proto.c" 49 | #include "matrix.ludecomp.proto.c" 50 | #include "matrix.qrdecomp.proto.c" 51 | #include "matrix.math.proto.c" 52 | 53 | -------------------------------------------------------------------------------- /examples/kbd_window_example.c: -------------------------------------------------------------------------------- 1 | char __docstr__[] = "Kaiser-Bessel derived window example."; 2 | 3 | #include 4 | 5 | #include "liquid.h" 6 | #include "liquid.argparse.h" 7 | 8 | int main(int argc, char* argv[]) 9 | { 10 | // define variables and parse command-line arguments 11 | liquid_argparse_init(__docstr__); 12 | liquid_argparse_add(char*, filename, "kbd_window_example.m", 'o', "output filename", NULL); 13 | liquid_argparse_add(unsigned, n, 64, 'n', "window length (samples)", NULL); 14 | liquid_argparse_add(float, beta, 20, 'b', "Kaiser beta factor)", NULL); 15 | liquid_argparse_parse(argc,argv); 16 | 17 | unsigned int i; 18 | float w[n]; 19 | liquid_kbd_window(n,beta,w); 20 | 21 | FILE*fid = fopen(filename,"w"); 22 | fprintf(fid,"%% %s: auto-generated file\n\n", filename); 23 | fprintf(fid,"clear all;\n"); 24 | fprintf(fid,"close all;\n\n"); 25 | fprintf(fid,"n=%u;\n",n); 26 | 27 | for (i=0; i>num_bits, 0); 42 | 43 | x_hat = quantize_dac(q,num_bits); 44 | 45 | if (liquid_autotest_verbose) 46 | printf("%8.4f > 0x%2.2x > %8.4f\n", x, q, x_hat); 47 | 48 | // ensure original value is recovered within tolerance 49 | CONTEND_DELTA(x,x_hat,tol); 50 | 51 | x += dx; 52 | x = (x > 1.0f) ? 1.0f : x; 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /examples/repack_bytes_example.c: -------------------------------------------------------------------------------- 1 | char __docstr__[] = 2 | "This example demonstrates the repack_bytes() interface by packing a" 3 | " sequence of three 3-bit symbols into five 2-bit symbols. The results" 4 | " are printed to the screen. Because the total number of bits in the" 5 | " input is 9 and not evenly divisible by 2, the last of the 5 output" 6 | " symbols has a zero explicitly padded to the end."; 7 | 8 | #include 9 | 10 | #include "liquid.h" 11 | #include "liquid.argparse.h" 12 | 13 | // print symbol to screen, one bit at a time 14 | void print_symbol(unsigned char _sym, 15 | unsigned int _bits_per_symbol) 16 | { 17 | unsigned int i; 18 | unsigned int n; // shift amount 19 | for (i=0; i<_bits_per_symbol; i++) { 20 | n = _bits_per_symbol - i - 1; 21 | printf("%c", (_sym >> n) & 0x01 ? '1' : '0'); 22 | } 23 | } 24 | 25 | // print symbol array to screen 26 | void print_symbol_array(unsigned char * _sym, 27 | unsigned int _bits_per_symbol, 28 | unsigned int _num_symbols) 29 | { 30 | unsigned int i; 31 | for (i=0; i<_num_symbols; i++) { 32 | print_symbol(_sym[i], _bits_per_symbol); 33 | printf("%c", i < _num_symbols-1 ? ',' : '\n'); 34 | } 35 | } 36 | 37 | int main(int argc, char* argv[]) 38 | { 39 | // define variables and parse command-line arguments 40 | liquid_argparse_init(__docstr__); 41 | liquid_argparse_parse(argc,argv); 42 | 43 | // input symbols: 111 000 111 44 | // expected output: 11 10 00 11 1(0) 45 | unsigned char input[3] = { 46 | 0x07, // 111 47 | 0x00, // 000 48 | 0x07 // 111(0) 49 | }; 50 | 51 | // allocate memory for output array 52 | unsigned char output[5]; 53 | unsigned int N; 54 | 55 | // print input symbol array 56 | printf("input symbols: "); 57 | print_symbol_array(input,3,3); 58 | 59 | // repack bytes into output array 60 | liquid_repack_bytes( input, 3, 3, output, 2, 5, &N ); 61 | 62 | // print output array 63 | printf("output symbols: "); 64 | print_symbol_array(output,2,5); 65 | 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /examples/kaiser_window_example.c: -------------------------------------------------------------------------------- 1 | char __docstr__[] = "Kaiser-Bessel window example."; 2 | 3 | #include 4 | #include "liquid.h" 5 | #include "liquid.argparse.h" 6 | 7 | int main(int argc, char* argv[]) 8 | { 9 | // define variables and parse command-line arguments 10 | liquid_argparse_init(__docstr__); 11 | liquid_argparse_add(char*, filename, "kaiser_window_example.m", 'o', "output filename", NULL); 12 | liquid_argparse_add(unsigned, n, 51, 'n', "window length (samples)", NULL); 13 | liquid_argparse_add(float, beta, 10, 'b', "Kaiser beta factor)", NULL); 14 | liquid_argparse_parse(argc,argv); 15 | 16 | float w[n]; 17 | unsigned int i; 18 | for (i=0; i 4 | #include "liquid.h" 5 | #include "liquid.argparse.h" 6 | 7 | int main(int argc, char* argv[]) 8 | { 9 | // define variables and parse command-line arguments 10 | liquid_argparse_init(__docstr__); 11 | liquid_argparse_add(char*, filename,"polyfit_example.m",'o', "output filename", NULL); 12 | liquid_argparse_add(unsigned, n, 25, 'n', "number of samples to evaluate", NULL); 13 | liquid_argparse_add(unsigned, order, 2, 'p', "polynomial order", NULL); 14 | liquid_argparse_parse(argc,argv); 15 | 16 | // initialize data vectors 17 | float x[n]; 18 | float y[n]; 19 | unsigned int i; 20 | for (i=0; i %12.6f\n", x[i],y[i],polyf_val(p,order+1,x[i])); 32 | for (i=0; i<=order; i++) 33 | printf("p[%3u] = %12.8f\n", i, p[i]); 34 | 35 | // plot results 36 | FILE * fid = fopen(filename, "w"); 37 | fprintf(fid,"%% %s : auto-generated file\n\n", filename); 38 | fprintf(fid,"clear all; close all;\n"); 39 | fprintf(fid,"n = %u; order = %u;\n", n, order); 40 | fprintf(fid,"x = zeros(1,n); y = zeros(1,n); p = zeros(1,order+1);\n"); 41 | for (i=0; i 9 | #include 10 | 11 | #include "liquid.internal.h" 12 | 13 | int main() 14 | { 15 | // find the 17 symbols with a hamming distance of exactly 3 16 | 17 | unsigned int sym_org; // original symbol 18 | unsigned int sym_enc; // encoded symbol 19 | 20 | unsigned int n3; // counter for symbols with a Hamming distance 3 21 | unsigned char sym3[17]; // ... 22 | unsigned int i; 23 | 24 | printf("unsigned char fecsoft_hamming128_neighbors[256][17] = {\n"); 25 | for (sym_org=0; sym_org<256; sym_org++) { 26 | 27 | // 28 | printf(" {"); 29 | 30 | // reset counter 31 | n3=0; 32 | 33 | // encode symbol 34 | sym_enc = fec_hamming128_encode_symbol(sym_org); 35 | 36 | // look at all possible symbols... 37 | for (i=0; i<256; i++) { 38 | unsigned int sym_test = fec_hamming128_encode_symbol(i); 39 | 40 | // compute number of bit differences... 41 | unsigned int d = count_bit_errors(sym_enc, sym_test); 42 | 43 | // 44 | if (d==3) { 45 | if (n3 == 17) { 46 | fprintf(stderr,"error: expected no more than 17 symbols of distance 3\n"); 47 | exit(1); 48 | } 49 | sym3[n3++] = i; 50 | } 51 | 52 | // print results... 53 | //printf(" %3u : %3u\n", i, d); 54 | } 55 | 56 | //printf(" %3u : n3 =%3u\n", sym_org, n3); 57 | if (n3 != 17) { 58 | fprintf(stderr,"error: expected exactly 17 symbols of distance 3\n"); 59 | exit(1); 60 | } 61 | 62 | // print line 63 | for (i=0; i<17; i++) { 64 | printf("0x%.2x", sym3[i]); 65 | if (i != 16) 66 | printf(", "); 67 | } 68 | printf("}"); 69 | if (sym_org != 255) 70 | printf(",\n"); 71 | else 72 | printf("};\n"); 73 | } 74 | 75 | return 0; 76 | } 77 | 78 | -------------------------------------------------------------------------------- /src/optim/src/optim.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2015 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // Optimization 25 | // 26 | 27 | #ifndef __LIQUID_OPTIM_H__ 28 | #define __LIQUID_OPTIM_H__ 29 | 30 | // optim pattern set (struct) 31 | struct optim_ps_s { 32 | float *x, *y; 33 | unsigned int nx, ny, np; 34 | unsigned int na; // num allocated 35 | }; 36 | 37 | typedef struct optim_ps_s * optim_ps; 38 | 39 | optim_ps optim_ps_create(unsigned int _nx, unsigned int _ny); 40 | void optim_ps_destroy(optim_ps _ps); 41 | void optim_ps_print(optim_ps _ps); 42 | void optim_ps_append_pattern(optim_ps _ps, float *_x, float *_y); 43 | void optim_ps_append_patterns(optim_ps _ps, float *_x, float *_y, unsigned int _np); 44 | void optim_ps_delete_pattern(optim_ps _ps, unsigned int _i); 45 | void optim_ps_clear(optim_ps _ps); 46 | void optim_ps_access(optim_ps _ps, unsigned int _i, float **_x, float **_y); 47 | 48 | typedef void(*optim_target_function)(float *_x, float *_y, void *_p); 49 | typedef float(*optim_obj_function)(optim_ps _ps, void *_p, optim_target_function _f); 50 | 51 | #endif // __LIQUID_OPTIM_H__ 52 | -------------------------------------------------------------------------------- /src/multichannel/src/firpfbch_cccf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2022 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // multichannel API: complex floating-point 25 | // 26 | 27 | #include "liquid.internal.h" 28 | 29 | // naming extensions (useful for print statements) 30 | #define EXTENSION_SHORT "f" 31 | #define EXTENSION_FULL "cccf" 32 | 33 | // 34 | #define FIRPFBCH(name) LIQUID_CONCAT(firpfbch_cccf,name) 35 | 36 | #define T float complex // general 37 | #define TO float complex // output 38 | #define TC float complex // coefficients 39 | #define TI float complex // input 40 | #define WINDOW(name) LIQUID_CONCAT(windowcf,name) 41 | #define DOTPROD(name) LIQUID_CONCAT(dotprod_cccf,name) 42 | 43 | #define TO_COMPLEX 1 44 | #define TC_COMPLEX 1 45 | #define TI_COMPLEX 1 46 | 47 | #define PRINTVAL_TO(X,F) PRINTVAL_CFLOAT(X,F) 48 | #define PRINTVAL_TC(X,F) PRINTVAL_CFLOAT(X,F) 49 | #define PRINTVAL_TI(X,F) PRINTVAL_CFLOAT(X,F) 50 | 51 | // prototypes 52 | #include "firpfbch.proto.c" 53 | 54 | -------------------------------------------------------------------------------- /sandbox/chromosome_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // chromosome_example.c 3 | // 4 | 5 | #include 6 | #include 7 | 8 | #include "liquid.internal.h" 9 | 10 | int main() { 11 | unsigned int bits_per_trait[] = {4, 8, 8, 4}; 12 | chromosome p1 = chromosome_create(bits_per_trait, 4); 13 | chromosome p2 = chromosome_create(bits_per_trait, 4); 14 | chromosome c = chromosome_create(bits_per_trait, 4); 15 | 16 | // 0000 11111111 00000000 1111 17 | p1->traits[0] = 0x0; 18 | p1->traits[1] = 0xFF; 19 | p1->traits[2] = 0x00; 20 | p1->traits[3] = 0xF; 21 | 22 | // 0101 01010101 01010101 0101 23 | p2->traits[0] = 0x5; 24 | p2->traits[1] = 0x55; 25 | p2->traits[2] = 0x55; 26 | p2->traits[3] = 0x5; 27 | 28 | printf("parent [1]:\n"); 29 | chromosome_print(p1); 30 | 31 | printf("parent [2]:\n"); 32 | chromosome_print(p2); 33 | 34 | printf("\n\n"); 35 | 36 | // 37 | // test crossover 38 | // 39 | 40 | printf("testing crossover...\n"); 41 | 42 | chromosome_crossover(p1, p2, c, 0); 43 | // .... ........ ........ .... 44 | // 0101 01010101 01010101 0101 45 | chromosome_print(c); 46 | 47 | chromosome_crossover(p1, p2, c, 4); 48 | // 0000 ........ ........ .... 49 | // .... 01010101 01010101 0101 50 | chromosome_print(c); 51 | 52 | chromosome_crossover(p1, p2, c, 6); 53 | // 0000 11...... ........ .... 54 | // .... ..010101 01010101 0101 55 | chromosome_print(c); 56 | 57 | chromosome_crossover(p1, p2, c, 14); 58 | // 0000 11111111 00...... .... 59 | // .... ........ ..010101 0101 60 | chromosome_print(c); 61 | 62 | chromosome_crossover(p1, p2, c, 24); 63 | // 0000 11111111 00000000 1111 64 | // .... ........ ........ .... 65 | chromosome_print(c); 66 | 67 | // 68 | // test mutation 69 | // 70 | 71 | printf("testing mutation...\n"); 72 | 73 | unsigned int i; 74 | for (i=0; i<24; i++) { 75 | chromosome_reset(c); 76 | chromosome_mutate(c,i); 77 | // 0000 01000000 00000000 0000 78 | chromosome_print(c); 79 | } 80 | 81 | chromosome_destroy(p1); 82 | chromosome_destroy(p2); 83 | chromosome_destroy(c); 84 | 85 | return 0; 86 | } 87 | 88 | -------------------------------------------------------------------------------- /src/utility/bench/byte_utilities_benchmark.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2022 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include "liquid.h" 26 | 27 | void benchmark_count_ones(struct rusage * _start, 28 | struct rusage * _finish, 29 | unsigned long int * _num_iterations) 30 | { 31 | // allocate buffer of bytes and initialize 32 | unsigned int i, j; 33 | unsigned int buf_len = 1024; 34 | unsigned int * buf = (unsigned int *) malloc(buf_len*sizeof(unsigned int)); 35 | for (i=0; i 28 | #include 29 | 30 | // generator polynomial 31 | #define CRC32_POLY 0xEDB88320 // 0x04C11DB7 32 | 33 | int main() { 34 | unsigned int crc; 35 | unsigned int mask; 36 | unsigned int crcpoly = CRC32_POLY; 37 | 38 | unsigned int crc_gentab[256]; 39 | 40 | // generate table 41 | unsigned int i, j; 42 | for (i=0; i<256; i++) { 43 | crc = i; 44 | for (j=0; j<8; j++) { 45 | mask = -(crc & 0x01); 46 | crc = (crc >> 1) ^ (crcpoly & mask); 47 | } 48 | crc_gentab[i] = crc; 49 | } 50 | 51 | printf("\n"); 52 | printf("unsigned char crc_gentab[%u] = {\n ", 256); 53 | for (i=0; i<256; i++) { 54 | printf("0x%.2x", crc_gentab[i]); 55 | if (i==255) 56 | printf("};\n"); 57 | else if (((i+1)%8)==0) 58 | printf(",\n "); 59 | else 60 | printf(", "); 61 | } 62 | 63 | // test it... 64 | 65 | return 0; 66 | } 67 | 68 | -------------------------------------------------------------------------------- /sandbox/throttle_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // throttle_test.c 3 | // 4 | // Test throttling down processor to reach target rate by inserting sleep 5 | // statements in between processing blocks 6 | // 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "liquid.h" 15 | 16 | int main() { 17 | // options 18 | float target_rate = 200e3f; // target processing rate [samples/second] 19 | 20 | // design filter from prototype 21 | firfilt_crcf filter = firfilt_crcf_create_kaiser(25, 0.25f, 60.0f, 0.0f); 22 | 23 | // generate dummy buffers for processing 24 | unsigned int buf_len = 1024; 25 | float complex buf_0[buf_len]; 26 | float complex buf_1[buf_len]; 27 | memset(buf_0, 0x00, buf_len*sizeof(complex float)); 28 | 29 | // run with updates 30 | struct timespec t0, t1; 31 | float sleep_time = 200.0f; // initial guess 32 | unsigned int i; 33 | for (i=0; i<100; i++) { 34 | // run block of samples for 200 ms 35 | unsigned int num_samples_processed = 0; 36 | clock_gettime(CLOCK_REALTIME, &t0); 37 | float block_time = 0; 38 | while (block_time < 0.2) { 39 | // process a block of samples 40 | firfilt_crcf_execute_block(filter, buf_0, buf_len, buf_1); 41 | num_samples_processed += buf_len; 42 | 43 | // throttle by calling sleep 44 | usleep((unsigned int)sleep_time); 45 | 46 | // update time reference 47 | clock_gettime(CLOCK_REALTIME, &t1); 48 | block_time = t1.tv_sec - t0.tv_sec + 1e-9*(t1.tv_nsec - t0.tv_nsec); 49 | } 50 | 51 | // get processing rate 52 | float rate = (float)num_samples_processed / block_time; 53 | printf(" %6u, rate = %12.3f k (target = %12.3f k), sleep time = %12.1f us\r", 54 | i, rate*1e-3f, target_rate*1e-3f, sleep_time); 55 | fflush(stdout); 56 | 57 | // adjust sleep time proportional to deviation from target rate 58 | sleep_time *= expf(0.2f*logf(rate/target_rate)); 59 | } 60 | printf("\n"); 61 | 62 | // destroy filter object 63 | firfilt_crcf_destroy(filter); 64 | return 0; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /src/fft/tests/data/fft_data_8.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2015 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // autotest fft data for 8-point transform 25 | // 26 | 27 | #include 28 | 29 | float complex fft_test_x8[] = { 30 | 1.143832659273 + 0.058730029889*_Complex_I, 31 | -0.094390429919 + 0.229144161540*_Complex_I, 32 | -0.231936945111 + 0.250418514706*_Complex_I, 33 | 0.180568135767 + -0.869698396678*_Complex_I, 34 | -0.345282052584 + 1.176003338020*_Complex_I, 35 | 0.544428216952 + -0.610473584454*_Complex_I, 36 | 0.928035714223 + 0.647778401795*_Complex_I, 37 | 0.441211141066 + -1.176622015089*_Complex_I}; 38 | 39 | float complex fft_test_y8[] = { 40 | 2.566466439667 + -0.294719550271*_Complex_I, 41 | 1.635071437815 + 1.055386414782*_Complex_I, 42 | 1.767442826430 + 0.508277941207*_Complex_I, 43 | 2.964612333261 + -2.017902163711*_Complex_I, 44 | 0.422832311935 + 4.560580119089*_Complex_I, 45 | 0.548438211721 + -0.969987712376*_Complex_I, 46 | -1.562539151277 + 0.164794961607*_Complex_I, 47 | 0.808336864628 + -2.536589771219*_Complex_I}; 48 | 49 | -------------------------------------------------------------------------------- /src/matrix/src/matrixcf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2022 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // Complex floating-point matrix (single precision) 25 | // 26 | 27 | #include "liquid.internal.h" 28 | 29 | #define MATRIX(name) LIQUID_CONCAT(matrixcf, name) 30 | #define MATRIX_NAME "matrixcf" 31 | 32 | #define T float complex // general type 33 | #define TP float // primitive type 34 | #define T_COMPLEX 1 // is type complex? 35 | 36 | #define T_ABS(X) cabsf(X) 37 | #define TP_ABS(X) fabsf(X) 38 | 39 | #define MATRIX_PRINT_ELEMENT(X,R,C,r,c) \ 40 | printf("%7.2f+j%6.2f ", \ 41 | crealf(matrix_access(X,R,C,r,c)), \ 42 | cimagf(matrix_access(X,R,C,r,c))); 43 | 44 | // prototypes 45 | #include "matrix.base.proto.c" 46 | #include "matrix.cgsolve.proto.c" 47 | #include "matrix.chol.proto.c" 48 | #include "matrix.gramschmidt.proto.c" 49 | #include "matrix.inv.proto.c" 50 | #include "matrix.linsolve.proto.c" 51 | #include "matrix.ludecomp.proto.c" 52 | #include "matrix.qrdecomp.proto.c" 53 | #include "matrix.math.proto.c" 54 | 55 | -------------------------------------------------------------------------------- /src/filter/tests/iirdecim_autotest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2022 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #include "autotest/autotest.h" 24 | #include "liquid.h" 25 | 26 | // test copy method 27 | void autotest_iirdecim_copy() 28 | { 29 | // create base object 30 | iirdecim_crcf q0 = iirdecim_crcf_create_default(3, 7); 31 | 32 | // run samples through filter 33 | unsigned int i, j; 34 | float complex buf[3], y0, y1; 35 | for (i=0; i<20; i++) { 36 | for (j=0; j<3; j++) 37 | buf[j] = randnf() + _Complex_I*randnf(); 38 | iirdecim_crcf_execute(q0, buf, &y0); 39 | } 40 | 41 | // copy object 42 | iirdecim_crcf q1 = iirdecim_crcf_copy(q0); 43 | 44 | // run samples through both filters in parallel 45 | for (i=0; i<60; i++) { 46 | for (j=0; j<3; j++) 47 | buf[j] = randnf() + _Complex_I*randnf(); 48 | iirdecim_crcf_execute(q0, buf, &y0); 49 | iirdecim_crcf_execute(q1, buf, &y1); 50 | 51 | CONTEND_EQUALITY( y0, y1 ); 52 | } 53 | 54 | // destroy objects 55 | iirdecim_crcf_destroy(q0); 56 | iirdecim_crcf_destroy(q1); 57 | } 58 | 59 | -------------------------------------------------------------------------------- /src/fec/tests/fec_rep3_autotest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2015 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #include "autotest/autotest.h" 24 | #include "liquid.h" 25 | 26 | // 27 | // AUTOTEST: repeat/3 codec 28 | // 29 | void autotest_rep3_codec() 30 | { 31 | unsigned int n=4; 32 | unsigned char msg[] = {0x25, 0x62, 0x3F, 0x52}; 33 | fec_scheme fs = LIQUID_FEC_REP3; 34 | 35 | // create arrays 36 | unsigned int n_enc = fec_get_enc_msg_length(fs,n); 37 | unsigned char msg_dec[n]; 38 | unsigned char msg_enc[n_enc]; 39 | 40 | // create object 41 | fec q = fec_create(fs,NULL); 42 | if (liquid_autotest_verbose) 43 | fec_print(q); 44 | 45 | // encode message 46 | fec_encode(q, n, msg, msg_enc); 47 | 48 | // corrupt encoded message 49 | msg_enc[0] = ~msg_enc[0]; 50 | msg_enc[1] = ~msg_enc[1]; 51 | msg_enc[2] = ~msg_enc[2]; 52 | msg_enc[3] = ~msg_enc[3]; 53 | 54 | // decode message 55 | fec_decode(q, n, msg_enc, msg_dec); 56 | 57 | // validate data are the same 58 | CONTEND_SAME_DATA(msg, msg_dec, n); 59 | 60 | // clean up objects 61 | fec_destroy(q); 62 | } 63 | 64 | -------------------------------------------------------------------------------- /sandbox/minsearch_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // minsearch.c 3 | // 4 | // search to find minimum of a function using parabolic 5 | // interpolation 6 | // 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | double function(double _x) { 14 | #if 0 15 | // -sin(x) minimum at x = pi/2 16 | double y = 1.0f-sin(_x); 17 | #else 18 | // exp(-(x-pi/2)^2) 19 | double t = _x - M_PI/2; 20 | double y = -exp(-t*t); 21 | #endif 22 | return y; 23 | } 24 | 25 | int main() { 26 | // options 27 | unsigned int num_iterations = 10; 28 | double x0 = 0.3f; // lower value 29 | double x1; // middle value (ignored) 30 | double x2 = 3.1f; // upper value 31 | double tol = 1e-6f; // error tolerance 32 | 33 | // 34 | double y0 = function(x0); 35 | double y1; 36 | double y2 = function(x2); 37 | 38 | double x_hat; 39 | double del = 0.0f; 40 | unsigned int i; 41 | for (i=0; i x1); 55 | assert(x1 > x0); 56 | 57 | // compute minimum 58 | double t0 = y0*(x1*x1 - x2*x2) + 59 | y1*(x2*x2 - x0*x0) + 60 | y2*(x0*x0 - x1*x1); 61 | 62 | double t1 = y0*(x1 - x2) + 63 | y1*(x2 - x0) + 64 | y2*(x0 - x1); 65 | 66 | x_hat = 0.5f * t0 / t1; 67 | del = x_hat - x1; 68 | 69 | // print 70 | printf("%4u : %12.8f, e=%12.4e\n", i, x_hat, x_hat-M_PI/2); 71 | 72 | if (x_hat > x1) { 73 | // new minimum 74 | x0 = x1; 75 | y0 = y1; 76 | } else { 77 | // new maximum 78 | x2 = x1; 79 | y2 = y1; 80 | } 81 | 82 | if (fabs(del) < tol) 83 | break; 84 | } 85 | 86 | printf("estimated minimum : %f (%f)\n", x_hat, M_PI/2); 87 | 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /src/fft/src/spgramf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2022 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // spectral periodogram API: complex floating-point 25 | // 26 | 27 | #include "liquid.internal.h" 28 | 29 | // naming extensions (useful for print statements) 30 | #define EXTENSION "f" 31 | 32 | // name-mangling macros 33 | #define ASGRAM(name) LIQUID_CONCAT(asgramf,name) 34 | #define SPGRAM(name) LIQUID_CONCAT(spgramf,name) 35 | #define SPWATERFALL(name) LIQUID_CONCAT(spwaterfallf,name) 36 | #define WINDOW(name) LIQUID_CONCAT(windowf,name) 37 | #define FFT(name) LIQUID_CONCAT(fft,name) 38 | 39 | #define T float // primitive type (real) 40 | #define TC float complex // primitive type (complex) 41 | #define TI float // input type 42 | 43 | #define TI_COMPLEX 0 44 | 45 | #define PRINTVAL_T(X,F) PRINTVAL_FLOAT(X,F) 46 | #define PRINTVAL_TC(X,F) PRINTVAL_CFLOAT(X,F) 47 | #define PRINTVAL_TI(X,F) PRINTVAL_FLOAT(X,F) 48 | 49 | // prototypes 50 | #include "asgram.proto.c" 51 | #include "spgram.proto.c" 52 | #include "spwaterfall.proto.c" 53 | 54 | -------------------------------------------------------------------------------- /src/fft/src/spgramcf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2022 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // spectral periodogram API: complex floating-point 25 | // 26 | 27 | #include "liquid.internal.h" 28 | 29 | // naming extensions (useful for print statements) 30 | #define EXTENSION "cf" 31 | 32 | // name-mangling macros 33 | #define ASGRAM(name) LIQUID_CONCAT(asgramcf,name) 34 | #define SPGRAM(name) LIQUID_CONCAT(spgramcf,name) 35 | #define SPWATERFALL(name) LIQUID_CONCAT(spwaterfallcf,name) 36 | #define WINDOW(name) LIQUID_CONCAT(windowcf,name) 37 | #define FFT(name) LIQUID_CONCAT(fft,name) 38 | 39 | #define T float // primitive type (real) 40 | #define TC float complex // primitive type (complex) 41 | #define TI float complex // input type 42 | 43 | #define TI_COMPLEX 1 44 | 45 | #define PRINTVAL_T(X,F) PRINTVAL_FLOAT(X,F) 46 | #define PRINTVAL_TC(X,F) PRINTVAL_CFLOAT(X,F) 47 | #define PRINTVAL_TI(X,F) PRINTVAL_CFLOAT(X,F) 48 | 49 | // prototypes 50 | #include "asgram.proto.c" 51 | #include "spgram.proto.c" 52 | #include "spwaterfall.proto.c" 53 | 54 | -------------------------------------------------------------------------------- /src/filter/tests/data/firdecim_rrrf_data_M2h4x20.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2015 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | // 24 | // firdecim_rrrf_data_M2h4x20.c: autotest firdecim data 25 | // 26 | 27 | float firdecim_rrrf_data_M2h4x20_h[] = { 28 | 0.070782309250, 29 | -0.114245586699, 30 | 0.008215220382, 31 | -0.116718567037}; 32 | 33 | float firdecim_rrrf_data_M2h4x20_x[] = { 34 | 0.098311328839, 35 | -0.051405684088, 36 | -0.097846553674, 37 | 0.070744555579, 38 | -0.092569362020, 39 | 0.125743342560, 40 | -0.015936561579, 41 | 0.092440100110, 42 | -0.007046555447, 43 | -0.011409188742, 44 | 0.065796277764, 45 | 0.121624056526, 46 | 0.001291608019, 47 | -0.103251042400, 48 | -0.067174551288, 49 | -0.069262060525, 50 | 0.038107684731, 51 | -0.091432498375, 52 | 0.094339814736, 53 | 0.004969612518}; 54 | 55 | float firdecim_rrrf_data_M2h4x20_y[] = { 56 | 0.006958702881, 57 | -0.000245283250, 58 | -0.009438359685, 59 | -0.024511329437, 60 | -0.025867150062, 61 | -0.004886703086, 62 | -0.011931393613, 63 | -0.007143968697, 64 | 0.022109694637, 65 | 0.025520580844}; 66 | 67 | -------------------------------------------------------------------------------- /src/optim/tests/utility_autotest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 - 2023 Joseph Gaeddert 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #include "autotest/autotest.h" 24 | #include "liquid.h" 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "liquid.internal.h" 33 | 34 | void autotest_optim_rosenbrock() 35 | { 36 | #if LIQUID_STRICT_EXIT 37 | AUTOTEST_WARN("skipping rosenbrock config test with strict exit enabled\n"); 38 | return; 39 | #endif 40 | #if !LIQUID_SUPPRESS_ERROR_OUTPUT 41 | fprintf(stderr,"warning: ignore potential errors here; checking for invalid configurations\n"); 42 | #endif 43 | 44 | // optimum 45 | float v_ones[8] = {1,1,1,1,1,1,1,1}; 46 | CONTEND_DELTA( liquid_rosenbrock(NULL, v_ones, 8), 0.0f, 1e-6f ) 47 | CONTEND_DELTA( liquid_rosenbrock(NULL, v_ones, 1), 0.0f, 1e-6f ) 48 | 49 | // very far from optimum 50 | float v_misc[8] = {0.3, 1.0, 4.5,-2.2, 6.7,-0.2, 1.1,-0.9,}; 51 | CONTEND_GREATER_THAN( liquid_rosenbrock(NULL, v_misc, 8), 1000.0f ) 52 | 53 | // invalid configuration 54 | CONTEND_EQUALITY( liquid_rosenbrock(NULL, v_misc, 0), 0.0f ) 55 | } 56 | 57 | -------------------------------------------------------------------------------- /sandbox/fct_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // (Fast) discrete cosine transforms and equivalent FFTs 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | #include "liquid.h" 9 | 10 | int main() { 11 | unsigned int n=16; 12 | float x[n]; // time-domain 'signal' 13 | float y[n]; // fft(x) 14 | float z[n]; // ifft(y) 15 | 16 | unsigned int i; 17 | for (i=0; i 4 | #include 5 | #include 6 | #include "liquid.h" 7 | #include "liquid.argparse.h" 8 | 9 | int main(int argc, char* argv[]) 10 | { 11 | // define variables and parse command-line arguments 12 | liquid_argparse_init(__docstr__); 13 | liquid_argparse_add(char*, filename,"polyfit_comparison_example.m",'o', "output filename", NULL); 14 | liquid_argparse_add(unsigned, n, 51, 'n', "number of samples to evaluate", NULL); 15 | liquid_argparse_parse(argc,argv); 16 | 17 | // define x/y pairs 18 | float x[3] = {-1.0, 0.0, 1.0}; 19 | float y[3] = { 2.0, 7.0, 4.0}; 20 | float p0[3], p1[3]; 21 | 22 | // conventional 23 | polyf_fit (x,y,3,p0,3); 24 | polyf_fit_lagrange(x,y,3,p1); 25 | 26 | // evaluate 27 | float x_eval[n], y0[n], y1[n]; 28 | unsigned int i; 29 | for (i=0; i 6 | #include 7 | #include 8 | 9 | #include "liquid.h" 10 | #include "liquid.argparse.h" 11 | 12 | int main(int argc, char* argv[]) 13 | { 14 | // define variables and parse command-line options 15 | liquid_argparse_init(__docstr__); 16 | liquid_argparse_add(char*, filename, "firdespm_lowpass_example.m", 'o', "output filename", NULL); 17 | liquid_argparse_add(unsigned, n, 57, 'n', "filter length", NULL); 18 | liquid_argparse_add(float, fc, 0.2, 'f', "filter cutoff frequency", NULL); 19 | liquid_argparse_add(float, As, 60, 'a', "filter stop-band attenuation [dB]", NULL); 20 | liquid_argparse_parse(argc,argv); 21 | 22 | unsigned int i; 23 | printf("filter design parameters\n"); 24 | printf(" length : %12u\n", n); 25 | printf(" cutoff frequency : %12.8f Fs\n", fc); 26 | printf(" stop-band attenuation : %12.3f dB\n", As); 27 | 28 | // design the filter 29 | float h[n]; 30 | firdespm_lowpass(n,fc,As,0,h); 31 | 32 | // open output file 33 | FILE*fid = fopen(filename,"w"); 34 | fprintf(fid,"%% %s : auto-generated file\n", filename); 35 | fprintf(fid,"clear all;\n"); 36 | fprintf(fid,"close all;\n\n"); 37 | fprintf(fid,"h_len=%u;\n", n); 38 | fprintf(fid,"fc=%12.4e;\n",fc); 39 | fprintf(fid,"As=%12.4e;\n",As); 40 | 41 | for (i=0; i 28 | #include "liquid.internal.h" 29 | 30 | // naming extensions (useful for print statements) 31 | #define EXTENSION_SHORT "f" 32 | #define EXTENSION_FULL "cccf" 33 | 34 | #define CHANNEL(name) LIQUID_CONCAT(channel_cccf,name) 35 | #define DOTPROD(name) LIQUID_CONCAT(dotprod_cccf,name) 36 | #define FIRFILT(name) LIQUID_CONCAT(firfilt_cccf,name) 37 | #define IIRFILT(name) LIQUID_CONCAT(iirfilt_rrrf,name) 38 | #define NCO(name) LIQUID_CONCAT(nco_crcf,name) 39 | #define RESAMP(name) LIQUID_CONCAT(resamp_crcf,name) 40 | #define TVMPCH(name) LIQUID_CONCAT(tvmpch_cccf,name) 41 | #define WINDOW(name) LIQUID_CONCAT(windowcf,name) 42 | 43 | #define TO float complex // output type 44 | #define TC float complex // coefficients type 45 | #define TI float complex // input type 46 | #define T float // primitive type 47 | 48 | #define PRINTVAL_TC(X,F) PRINTVAL_CFLOAT(X,F) 49 | 50 | // prototypes 51 | #include "channel.proto.c" 52 | #include "tvmpch.proto.c" 53 | 54 | --------------------------------------------------------------------------------