├── .github
└── ISSUE_TEMPLATE
│ ├── application-note-not-compliant.md
│ ├── example-not-compliant.md
│ ├── missing-application-note.md
│ ├── missing-c-api.md
│ ├── missing-xcore-test.md
│ ├── test-not-compliant.md
│ └── top-level-readme-not-compliant.md
├── .gitignore
├── AN00209_xCORE-200_DSP_Library
├── README.rst
├── app_adaptive
│ ├── .cproject
│ ├── .project
│ ├── LICENSE.rst
│ ├── Makefile
│ └── src
│ │ └── app_adaptive.xc
├── app_atan2_hypot
│ ├── .cproject
│ ├── .project
│ ├── LICENSE.rst
│ ├── Makefile
│ └── src
│ │ └── app_atan2_hypot.xc
├── app_bfp
│ ├── .cproject
│ ├── .project
│ ├── LICENSE.rst
│ ├── Makefile
│ └── src
│ │ └── app_bfp.xc
├── app_complex
│ ├── LICENSE.rst
│ ├── Makefile
│ └── src
│ │ └── app_complex.xc
├── app_complex_fir
│ ├── LICENSE.rst
│ ├── Makefile
│ └── src
│ │ └── app_complex_filters.xc
├── app_dct
│ ├── .cproject
│ ├── .project
│ ├── LICENSE.rst
│ ├── Makefile
│ └── src
│ │ └── app_dct.xc
├── app_design
│ ├── .cproject
│ ├── .project
│ ├── LICENSE.rst
│ ├── Makefile
│ └── src
│ │ └── app_design.xc
├── app_fft
│ ├── .cproject
│ ├── .project
│ ├── LICENSE.rst
│ ├── Makefile
│ └── src
│ │ └── app_fft.xc
├── app_fft_dif
│ ├── LICENSE.rst
│ ├── Makefile
│ └── src
│ │ └── app_fft.xc
├── app_fft_double_buf
│ ├── .cproject
│ ├── .project
│ ├── .xproject
│ ├── LICENSE.rst
│ ├── Makefile
│ ├── config.xscope
│ ├── src
│ │ └── app_fft_double_buf.xc
│ └── xk-audio-216-mc.xn
├── app_fft_real_single
│ ├── .cproject
│ ├── .project
│ ├── LICENSE.rst
│ ├── Makefile
│ └── src
│ │ └── app_fft.xc
├── app_fft_timing
│ ├── .cproject
│ ├── .project
│ ├── LICENSE.rst
│ ├── Makefile
│ └── src
│ │ └── app_fft.xc
├── app_filters
│ ├── .cproject
│ ├── .project
│ ├── LICENSE.rst
│ ├── Makefile
│ └── src
│ │ └── app_filters.xc
├── app_math
│ ├── .cproject
│ ├── .project
│ ├── LICENSE.rst
│ ├── Makefile
│ └── src
│ │ └── app_math.xc
├── app_matrix
│ ├── .cproject
│ ├── .project
│ ├── LICENSE.rst
│ ├── Makefile
│ └── src
│ │ └── app_matrix.xc
├── app_statistics
│ ├── .cproject
│ ├── .project
│ ├── LICENSE.rst
│ ├── Makefile
│ └── src
│ │ └── app_statistics.xc
├── app_vector
│ ├── .cproject
│ ├── .project
│ ├── LICENSE.rst
│ ├── Makefile
│ └── src
│ │ └── app_vector.xc
├── app_window_post_fft
│ ├── LICENSE.rst
│ ├── Makefile
│ └── src
│ │ └── app_fft.xc
├── doc
│ └── rst
│ │ ├── AN00209.rst
│ │ └── xdoc.conf
└── src
│ └── .dummy
├── CHANGELOG.rst
├── Jenkinsfile
├── LICENSE.rst
├── README.rst
├── lib_dsp
├── .cproject
├── .makefile
├── .project
├── api
│ ├── dsp.h
│ ├── dsp_adaptive.h
│ ├── dsp_bfp.h
│ ├── dsp_complex.h
│ ├── dsp_dct.h
│ ├── dsp_design.h
│ ├── dsp_fast_float.h
│ ├── dsp_fft.h
│ ├── dsp_filters.h
│ ├── dsp_filters_fp.h
│ ├── dsp_float_type.h
│ ├── dsp_fp.h
│ ├── dsp_math.h
│ ├── dsp_math_int.h
│ ├── dsp_matrix.h
│ ├── dsp_qformat.h
│ ├── dsp_statistics.h
│ ├── dsp_testing.h
│ └── dsp_vector.h
├── doc
│ └── rst
│ │ ├── index.rst
│ │ └── xdoc.conf
├── lib_build_info.cmake
├── module_build_info
├── module_description
└── src
│ ├── bfp
│ ├── dsp_bfp.c
│ ├── dsp_bfp_bit_reverse_shl.S
│ ├── dsp_bfp_cls.S
│ ├── dsp_bfp_shl.S
│ └── dsp_bfp_vector.c
│ ├── dsp_adaptive.c
│ ├── dsp_biquad.S
│ ├── dsp_complex.xc
│ ├── dsp_complex_add_vector.S
│ ├── dsp_complex_fir.S
│ ├── dsp_complex_hann.S
│ ├── dsp_complex_mul_vector.S
│ ├── dsp_dct.xc
│ ├── dsp_design.c
│ ├── dsp_fast_atan.S
│ ├── dsp_fast_float.xc
│ ├── dsp_filters.c
│ ├── dsp_idct.xc
│ ├── dsp_logistics.S
│ ├── dsp_math.c
│ ├── dsp_math_int.xc
│ ├── dsp_matrix.c
│ ├── dsp_min_vector.S
│ ├── dsp_poly_eval.S
│ ├── dsp_sqrt.xc
│ ├── dsp_sqrt_xs2.S
│ ├── dsp_statistics.c
│ ├── dsp_tables.c
│ ├── dsp_vector.c
│ ├── fft
│ ├── dsp_fft.xc
│ ├── dsp_fft_bit_reverse.S
│ ├── dsp_fft_forward.S
│ ├── dsp_fft_gc.S
│ ├── dsp_fft_inverse.S
│ ├── dsp_fft_inverse_DIF.S
│ ├── dsp_fft_merge_spectra.S
│ ├── dsp_fft_real.xc
│ ├── dsp_fft_real_fix.S
│ ├── dsp_fft_split_spectrum.S
│ ├── dsp_fft_zero_reverse_forward.S
│ └── dsp_long_short_conversion.S
│ ├── float
│ ├── dsp_filters_fp.c
│ ├── dsp_fp_vector.c
│ ├── dsp_poly_eval_fp.c
│ └── floating_fft.xc
│ ├── gen
│ ├── generate_butter.py
│ ├── generate_window.py
│ └── generatesine.sh
│ ├── logistics_table.py
│ ├── poly_eval.c
│ └── testing
│ ├── crc32_c.xc
│ ├── dsp_testing_conv.c
│ ├── dsp_testing_diff.c
│ ├── dsp_testing_print.c
│ └── dsp_testing_rand.c
├── python
└── setup.py
├── requirements.txt
└── tests
├── adaptive_test.expect
├── bfp_test.expect
├── complex_fir_test.expect
├── complex_test.expect
├── design_test.expect
├── dsp_unit_tests
├── .cproject
├── .project
├── config.xscope
├── conftest.py
├── src
│ ├── fft.c
│ ├── fft.h
│ ├── test_bfp.c
│ ├── test_fft.c
│ ├── test_float.c
│ ├── test_poly_eval.c
│ ├── test_testing.c
│ └── test_vector_bfp.c
└── wscript
├── fft_real_single_test.expect
├── filters_test.expect
├── gen_test.py
├── hann_test.expect
├── math_test.expect
├── matrix_test.expect
├── measure_fft_performance.py
├── runtests.py
├── statistics_test.expect
├── test_adaptive.py
├── test_bfp.py
├── test_biquad
├── .cproject
├── .project
├── config.xscope
├── conftest.py
├── src
│ ├── generate_iirs.py
│ ├── iir.h
│ ├── iir.xc
│ └── test_biquad.xc
└── wscript
├── test_complex.py
├── test_complex_fir.py
├── test_design.py
├── test_fft_forward.expect
├── test_fft_forward
├── Makefile
├── config.xscope
├── src
│ └── test.xc
└── wscript
├── test_fft_forward_real
├── Makefile
├── config.xscope
├── src
│ └── test.xc
└── wscript
├── test_fft_index_bit_reverse.expect
├── test_fft_index_bit_reverse
├── Makefile
├── config.xscope
├── src
│ └── test.xc
└── wscript
├── test_fft_inverse.expect
├── test_fft_inverse
├── Makefile
├── config.xscope
├── src
│ └── test.xc
└── wscript
├── test_fft_inverse_blank_forward.expect
├── test_fft_inverse_blank_forward
├── Makefile
├── config.xscope
├── src
│ └── test.xc
└── wscript
├── test_fft_performance
├── Makefile
├── config.xscope
├── src
│ └── test.xc
└── wscript
├── test_fft_real_single.py
├── test_fft_short_long.expect
├── test_fft_short_long
├── Makefile
├── config.xscope
├── src
│ └── test.xc
└── wscript
├── test_fft_split_and_merge.expect
├── test_fft_split_and_merge
├── Makefile
├── config.xscope
├── src
│ └── test.xc
└── wscript
├── test_filters.py
├── test_hann.py
├── test_math.py
├── test_matrix.py
├── test_statistics.py
├── test_vector.py
└── vector_test.expect
/.github/ISSUE_TEMPLATE/application-note-not-compliant.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Application Note Issue
3 | about: Template for an Application note issue report
4 | title: examples/ANXXXXX Application Note not compliant
5 | labels: documentation
6 | assignees: ''
7 |
8 | ---
9 |
10 |
11 |
12 |
13 | **Issues:**
14 |
15 | - xdoc-custom RST directives used in the Application Note README
16 | - application note code not compiling for xcore-ai
17 | - application note code not running successfully on xcore-ai
18 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/example-not-compliant.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Example Issue
3 | about: Template for an example issue report
4 | title: examples/xxx Example not compliant
5 | labels: documentation
6 | assignees: ''
7 |
8 | ---
9 |
10 |
11 |
12 |
13 | **Issues:**
14 |
15 | - convert example to Application Note
16 | - xdoc-custom RST directives used in the README
17 | - example code not compiling for xcore-ai
18 | - example code not running successfully on xcore-ai
19 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/missing-application-note.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Missing Application Note
3 | about: Template for a Missing Application Note issue report
4 | title: Missing Application Note
5 | labels: documentation
6 | assignees: ''
7 |
8 | ---
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/missing-c-api.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Missing C API Issue
3 | about: Template for a Missing C API issue report
4 | title: Missing C API
5 | labels: enhancement
6 | assignees: ''
7 |
8 | ---
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/missing-xcore-test.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Missing xCore Test Issue
3 | about: Template for a Missing xCore test issue report
4 | title: Missing xCore test
5 | labels: testing
6 | assignees: ''
7 |
8 | ---
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/test-not-compliant.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Test Issue
3 | about: Template for a Test issue report
4 | title: tests/XXX does not build or fails
5 | labels: testing
6 | assignees: ''
7 |
8 | ---
9 |
10 |
11 |
12 |
13 | **Issues:**
14 |
15 | - Test not compiling for xcore-ai
16 | - Test not running successfully on xcore-ai
17 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/top-level-readme-not-compliant.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Top-level README Issue
3 | about: Template for the top-level README issue report
4 | title: Top-level README not compliant
5 | labels: documentation
6 | assignees: ''
7 |
8 | ---
9 |
10 |
11 | **Issues:**
12 |
13 | - xdoc-custom RST directives used in the README
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | **/.build*/*
2 | **/bin/*
3 | *.o
4 | *.xe
5 | *.vcd
6 | *.xi
7 | *.i
8 | **/_build/
9 | **/run_*.log
10 | **/pdf/*
11 | **/*.pyc
12 | **/test_results.csv
13 | **/.pytest_cache/
14 | **/.metadata/*
15 | *.prefs
16 |
17 | # waf files and folders
18 | .lock-waf_*
19 | .waf-*/
20 | build/
21 | **/*.egg-info/
22 | */.venv/*
23 | Pipfile.lock
24 |
25 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/README.rst:
--------------------------------------------------------------------------------
1 | xCORE-200 DSP Elements Library
2 | ==============================
3 |
4 | Summary
5 | -------
6 |
7 | The application note gives an overview of using the xCORE-200 DSP Elements Library.
8 |
9 | Required tools and libraries
10 | ............................
11 |
12 | * xTIMEcomposer Tools - Version 14.2.0 and above
13 | * XMOS DSP library - Version 3.0.0 and above
14 |
15 | Required hardware
16 | .................
17 |
18 | This application note is designed to run on any XMOS xCORE-200 multicore microcontroller or the XMOS simulator.
19 |
20 | Prerequisites
21 | .............
22 |
23 | - This document assumes familiarity with the XMOS xCORE architecture, xCONNECT interconnect communication, the XMOS tool chain and the xC language.
24 |
25 | - For descriptions of XMOS related terms found in this document please see the XMOS Glossary [#]_.
26 |
27 | .. [#] http://www.xmos.com/published/glossary
28 |
29 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_adaptive/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | app_adaptive
4 |
5 |
6 |
7 |
8 |
9 | com.xmos.cdt.core.LegacyProjectCheckerBuilder
10 |
11 |
12 |
13 |
14 | com.xmos.cdt.core.ProjectInfoSyncBuilder
15 |
16 |
17 |
18 |
19 | com.xmos.cdt.core.ModulePathBuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
25 | clean,full,incremental,
26 |
27 |
28 |
29 |
30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
31 | full,incremental,
32 |
33 |
34 |
35 |
36 |
37 | org.eclipse.cdt.core.cnature
38 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
39 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
40 | com.xmos.cdt.core.XdeProjectNature
41 |
42 |
43 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_adaptive/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS = -O2 -g
2 |
3 | XCOREAI ?= 0
4 | ifeq ($(XCOREAI),1)
5 | # Xcore.ai Builds
6 | # Use `xmake XCOREAI=1`
7 |
8 | # The TARGET variable determines what target system the application is
9 | # compiled for. It either refers to an XN file in the source directories
10 | # or a valid argument for the --target option when compiling
11 | TARGET = XCORE-AI-EXPLORER
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
16 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
17 | # xcc for the final link (mapping) stage.
18 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
19 |
20 | else
21 | # Xcore-200 Builds
22 | # Use `xmake`
23 | TARGET = XCORE-200-EXPLORER
24 | XCC_FLAGS = $(BUILD_FLAGS)
25 | endif
26 |
27 | # The APP_NAME variable determines the name of the final .xe file. It should
28 | # not include the .xe postfix. If left blank the name will default to
29 | # the project name
30 | APP_NAME = app_adaptive
31 |
32 | # The USED_MODULES variable lists other modules used by the application.
33 | USED_MODULES = lib_dsp(>=6.0.0)
34 |
35 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
36 | # project to create both xCORE and ARM binaries.
37 | XCORE_ARM_PROJECT = 0
38 |
39 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
40 | VERBOSE = 0
41 |
42 | XMOS_MAKE_PATH ?= ../..
43 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
44 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_atan2_hypot/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | app_atan2_hypot
4 |
5 |
6 |
7 |
8 |
9 | com.xmos.cdt.core.LegacyProjectCheckerBuilder
10 |
11 |
12 |
13 |
14 | com.xmos.cdt.core.ModulePathBuilder
15 |
16 |
17 |
18 |
19 | com.xmos.cdt.core.ProjectInfoSyncBuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
25 | clean,full,incremental,
26 |
27 |
28 |
29 |
30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
31 | full,incremental,
32 |
33 |
34 |
35 |
36 |
37 | org.eclipse.cdt.core.cnature
38 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
39 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
40 | com.xmos.cdt.core.XdeProjectNature
41 |
42 |
43 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_atan2_hypot/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS = -O2 -g
2 |
3 | XCOREAI ?= 0
4 | ifeq ($(XCOREAI),1)
5 | # Xcore.ai Builds
6 | # Use `xmake XCOREAI=1`
7 |
8 | # The TARGET variable determines what target system the application is
9 | # compiled for. It either refers to an XN file in the source directories
10 | # or a valid argument for the --target option when compiling
11 | TARGET = XCORE-AI-EXPLORER
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
16 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
17 | # xcc for the final link (mapping) stage.
18 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
19 |
20 | else
21 | # Xcore-200 Builds
22 | # Use `xmake`
23 | TARGET = XCORE-200-EXPLORER
24 | XCC_FLAGS = $(BUILD_FLAGS)
25 | endif
26 |
27 | # The APP_NAME variable determines the name of the final .xe file. It should
28 | # not include the .xe postfix. If left blank the name will default to
29 | # the project name
30 | APP_NAME =
31 |
32 | # The USED_MODULES variable lists other modules used by the application.
33 | USED_MODULES = lib_dsp(>=6.0.0)
34 |
35 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
36 | # project to create both xCORE and ARM binaries.
37 | XCORE_ARM_PROJECT = 0
38 |
39 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
40 | VERBOSE = 0
41 |
42 | XMOS_MAKE_PATH ?= ../..
43 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
44 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_atan2_hypot/src/app_atan2_hypot.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | // XMOS DSP Library - DCT Functions test program
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | static int atan2_fails = 0, atan2_tests = 0;
12 |
13 | static void single_atan2_test(int y, int x, unsigned hypot, int angle, int precision, int angle_precision) {
14 | int hypot_precision = 24 - precision;
15 | int z[2];
16 | z[0] = x;
17 | z[1] = y;
18 | dsp_math_atan2_hypot(z, precision);
19 | unsigned hypotdiff = abs(((unsigned)z[0]) - hypot);
20 | unsigned anglediff = abs(((unsigned)z[1]) - angle);
21 | unsigned hypotlimit = (hypot >> (hypot_precision)) + ((hypot >> (hypot_precision-1))&1) - 1;
22 | unsigned anglelimit = (0x60000000 >> angle_precision);
23 |
24 | if (hypotdiff > hypotlimit) {
25 | printf("%08x %08x; Hypot %08x expected %08x\n", y, x, z[0], hypot);
26 | printf("atan2_hypot: Hypot diff %u limit is %d\n", hypotdiff,hypotlimit);
27 | atan2_fails++;
28 | }
29 | if (anglediff > anglelimit) {
30 | printf("%08x %08x Angle %08x expected %08x\n", y, x, z[1], angle);
31 |
32 | printf("atan2_angle: Angle diff %u limit is %d\n", anglediff, anglelimit);
33 | atan2_fails++;
34 | }
35 | atan2_tests++;
36 | printf("atan2 test %d\n", atan2_tests);
37 |
38 | }
39 |
40 |
41 | static const unsigned random_poly = 0xEDB88320;
42 | static unsigned random_val = 0x12345678; //seed
43 | int get_random_number(void)
44 | {
45 | crc32(random_val, -1, random_poly);
46 | return (int)random_val;
47 | }
48 |
49 | #define SQRT2(X) ((unsigned)(1.414213562*(X)))
50 | void atan2_test(void) {
51 | single_atan2_test(1000,1000, SQRT2(1000), 0x10000000, 0, 25);
52 | single_atan2_test(0xFFFFFF,0xFFFFFF, SQRT2(0xFFFFFF), 0x10000000, 0, 25);
53 | single_atan2_test(0xFFFFFFF,0xFFFFFFF, SQRT2(0xFFFFFFF), 0x10000000, 0, 25);
54 | single_atan2_test(0x3FFFFFFF,0x3FFFFFFF, SQRT2(0x3FFFFFFF), 0x10000000, 0, 25);
55 | single_atan2_test(0x7FFFFFFF,0x7FFFFFFF, SQRT2(0x7FFFFFFF), 0x10000000, 0, 25);
56 | single_atan2_test(0x7FFFFFFF,-0x7FFFFFFF, SQRT2(0x7FFFFFFF), 0x30000000, 0, 25);
57 | single_atan2_test(-0x7FFFFFFF,0x7FFFFFFF, SQRT2(0x7FFFFFFF), -0x10000000, 0, 25);
58 | single_atan2_test(-0x7FFFFFFF,-0x7FFFFFFF, SQRT2(0x7FFFFFFF), -0x30000000, 0, 25);
59 | for(int i = 0; i < 23; i++) {
60 | single_atan2_test(1200000000, 1600000000, 2000000000, 0x0d1bfaf9, i, 24-i);
61 | }
62 |
63 | for(int i = 0; i < PI2_Q8_24; i += PI2_Q8_24/391) {
64 | int angle = (((long long) i) << 31) / PI2_Q8_24;
65 | if (angle >= (1 << 30)) {
66 | angle -= (1 << 31);
67 | }
68 | int s = dsp_math_sin(i);
69 | int c = dsp_math_cos(i);
70 | single_atan2_test(s*127, c*127, 127<<24, angle, 0, 24);
71 | single_atan2_test(s/13, c/13, (1<<24)/13, angle, 0, 22);
72 | }
73 |
74 | for(int i = 0; i < 100; i += 1){
75 | int x = get_random_number(); //Returns random number from INT_MIN to INT_MAX
76 | int y = get_random_number();
77 | if (x < -0x7FFFFFFF) x = -0x7FFFFFFF; //Clip as arctan2 cannot take INT_MIN
78 | if (y < -0x7FFFFFFF) y = -0x7FFFFFFF;
79 |
80 | int hypot = (int)( sqrt( (double)x * (double)x + (double)y * (double)y ) );
81 | int angle = (int)( (atan2((double)y, (double)x)) * (0x40000000 / 3.1415926536f) );
82 | single_atan2_test(y, x, hypot, angle, 0, 24); //We cannot quite reach 25b on random points so set limit to 24b
83 | }
84 | printf("Atan2: %d out of %d passes\n", atan2_tests-atan2_fails, atan2_tests);
85 | }
86 |
87 | int main(void) {
88 | atan2_test();
89 | return 0;
90 | }
91 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_bfp/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | app_bfp
4 |
5 |
6 |
7 |
8 |
9 | com.xmos.cdt.core.LegacyProjectCheckerBuilder
10 |
11 |
12 |
13 |
14 | com.xmos.cdt.core.ModulePathBuilder
15 |
16 |
17 |
18 |
19 | com.xmos.cdt.core.ProjectInfoSyncBuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
25 | clean,full,incremental,
26 |
27 |
28 |
29 |
30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
31 | full,incremental,
32 |
33 |
34 |
35 |
36 |
37 | org.eclipse.cdt.core.cnature
38 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
39 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
40 | com.xmos.cdt.core.XdeProjectNature
41 |
42 |
43 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_bfp/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS = -O2 -g
2 |
3 | XCOREAI ?= 0
4 | ifeq ($(XCOREAI),1)
5 | # Xcore.ai Builds
6 | # Use `xmake XCOREAI=1`
7 |
8 | # The TARGET variable determines what target system the application is
9 | # compiled for. It either refers to an XN file in the source directories
10 | # or a valid argument for the --target option when compiling
11 | TARGET = XCORE-AI-EXPLORER
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
16 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
17 | # xcc for the final link (mapping) stage.
18 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
19 |
20 | else
21 | # Xcore-200 Builds
22 | # Use `xmake`
23 | TARGET = XCORE-200-EXPLORER
24 | XCC_FLAGS = $(BUILD_FLAGS)
25 | endif
26 |
27 | APP_NAME =
28 | USED_MODULES = lib_dsp(>=6.0.0)
29 | XCORE_ARM_PROJECT = 0
30 | VERBOSE = 0
31 |
32 | XMOS_MAKE_PATH ?= ../..
33 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
34 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_complex/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS = -O2 -g
2 |
3 | XCOREAI ?= 0
4 | ifeq ($(XCOREAI),1)
5 | # Xcore.ai Builds
6 | # Use `xmake XCOREAI=1`
7 |
8 | # The TARGET variable determines what target system the application is
9 | # compiled for. It either refers to an XN file in the source directories
10 | # or a valid argument for the --target option when compiling
11 | TARGET = XCORE-AI-EXPLORER
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
16 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
17 | # xcc for the final link (mapping) stage.
18 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
19 |
20 | else
21 | # Xcore-200 Builds
22 | # Use `xmake`
23 | TARGET = XCORE-200-EXPLORER
24 | XCC_FLAGS = $(BUILD_FLAGS)
25 | endif
26 |
27 | APP_NAME =
28 | USED_MODULES = lib_dsp(>=6.0.0)
29 | XCORE_ARM_PROJECT = 0
30 | VERBOSE = 0
31 |
32 | XMOS_MAKE_PATH ?= ../..
33 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
34 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_complex_fir/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS = -O2 -g
2 |
3 | XCOREAI ?= 0
4 | ifeq ($(XCOREAI),1)
5 | # Xcore.ai Builds
6 | # Use `xmake XCOREAI=1`
7 |
8 | # The TARGET variable determines what target system the application is
9 | # compiled for. It either refers to an XN file in the source directories
10 | # or a valid argument for the --target option when compiling
11 | TARGET = XCORE-AI-EXPLORER
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
16 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
17 | # xcc for the final link (mapping) stage.
18 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
19 |
20 | else
21 | # Xcore-200 Builds
22 | # Use `xmake`
23 | TARGET = XCORE-200-EXPLORER
24 | XCC_FLAGS = $(BUILD_FLAGS)
25 | endif
26 |
27 | APP_NAME =
28 | USED_MODULES = lib_dsp(>=6.0.0)
29 | XCORE_ARM_PROJECT = 0
30 | VERBOSE = 0
31 |
32 | XMOS_MAKE_PATH ?= ../..
33 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
34 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_complex_fir/src/app_complex_filters.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | // XMOS DSP Library - Filtering Functions Test Program
4 | // Uses Q24 format
5 |
6 | // Include files
7 | #include
8 | #include
9 | #include
10 |
11 | dsp_complex_t data[4] = {
12 | {1000,-1000},
13 | {500,500},
14 | {-8000,1000},
15 | {100,0},
16 | };
17 |
18 | dsp_complex_t fir[4] = {
19 | {0x0100000,-0x0100000},
20 | {0x1000000, 0x1000000},
21 | {0x2000000,-0x1000000},
22 | {-0x0400000,0x0200000},
23 | };
24 |
25 | int main(void) {
26 | timer tmr;
27 | int t0, t1;
28 | tmr :> t0;
29 | dsp_complex_t x = dsp_complex_fir(data, fir, 4, 0, 24);
30 | tmr :> t1;
31 | // printf("%d\n", t1-t0);
32 | dsp_complex_t sum = {0,0};
33 | for(int i = 0; i < 4; i++) {
34 | sum = dsp_complex_add(sum, dsp_complex_mul(data[i], fir[i], 24));
35 | }
36 | printf("%d, %d %d,%d\n", x.re, x.im, sum.re, sum.im);
37 | if (x.re == sum.re && x.im == sum.im) {
38 | printf("PASS\n");
39 | } else {
40 | printf("FAIL\n");
41 | }
42 |
43 | return 0;
44 | }
45 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_dct/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | app_dct
4 |
5 |
6 |
7 |
8 |
9 | com.xmos.cdt.core.LegacyProjectCheckerBuilder
10 |
11 |
12 |
13 |
14 | com.xmos.cdt.core.ModulePathBuilder
15 |
16 |
17 |
18 |
19 | com.xmos.cdt.core.ProjectInfoSyncBuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
25 | clean,full,incremental,
26 |
27 |
28 |
29 |
30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
31 | full,incremental,
32 |
33 |
34 |
35 |
36 |
37 | org.eclipse.cdt.core.cnature
38 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
39 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
40 | com.xmos.cdt.core.XdeProjectNature
41 |
42 |
43 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_dct/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS = -O2 -g
2 |
3 | XCOREAI ?= 0
4 | ifeq ($(XCOREAI),1)
5 | # Xcore.ai Builds
6 | # Use `xmake XCOREAI=1`
7 |
8 | # The TARGET variable determines what target system the application is
9 | # compiled for. It either refers to an XN file in the source directories
10 | # or a valid argument for the --target option when compiling
11 | TARGET = XCORE-AI-EXPLORER
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
16 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
17 | # xcc for the final link (mapping) stage.
18 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
19 |
20 | else
21 | # Xcore-200 Builds
22 | # Use `xmake`
23 | TARGET = XCORE-200-EXPLORER
24 | XCC_FLAGS = $(BUILD_FLAGS)
25 | endif
26 |
27 | # The APP_NAME variable determines the name of the final .xe file. It should
28 | # not include the .xe postfix. If left blank the name will default to
29 | # the project name
30 | APP_NAME = app_dct
31 |
32 | # The USED_MODULES variable lists other modules used by the application.
33 | USED_MODULES = lib_dsp(>=6.0.0)
34 |
35 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
36 | # project to create both xCORE and ARM binaries.
37 | XCORE_ARM_PROJECT = 0
38 |
39 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
40 | VERBOSE = 0
41 |
42 | XMOS_MAKE_PATH ?= ../..
43 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
44 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_dct/src/app_dct.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | // XMOS DSP Library - DCT Functions test program
4 |
5 | #include
6 | #include
7 | #include
8 |
9 | int32_t data[24] = {
10 | 24000, 23000, 22000, 21000, 20000, 19000, 18000, 17000, 16000, 15000,
11 | 14000, 13000, 12000, 11000, 10000, 9000, 8000, 7000, 6000, 5000,
12 | 4000, 3000, 2000, 1000
13 | };
14 |
15 | int32_t correct[24] = {
16 | 300000, 116633,
17 | 0, 12883,
18 | 0, 4581,
19 | 0, 2291,
20 | 0, 1345,
21 | 0, 871,
22 | 0, 577,
23 | 0, 411,
24 | 0, 263,
25 | 0, 189,
26 | 0, 95,
27 | 0, 33
28 | };
29 |
30 | int main( void )
31 | {
32 | int32_t dcted[24];
33 |
34 | dsp_dct_forward24(dcted, data);
35 | for(int32_t i = 0; i < 24; i++) {
36 | printf("%5d %6d%s\n", data[i], dcted[i], dcted[i] != correct[i] ? " Wrong":"");
37 | }
38 | return 0;
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_design/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | app_design
4 |
5 |
6 |
7 |
8 |
9 | com.xmos.cdt.core.LegacyProjectCheckerBuilder
10 |
11 |
12 |
13 |
14 | com.xmos.cdt.core.ModulePathBuilder
15 |
16 |
17 |
18 |
19 | com.xmos.cdt.core.ProjectInfoSyncBuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
25 | clean,full,incremental,
26 |
27 |
28 |
29 |
30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
31 | full,incremental,
32 |
33 |
34 |
35 |
36 |
37 | org.eclipse.cdt.core.cnature
38 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
39 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
40 | com.xmos.cdt.core.XdeProjectNature
41 |
42 |
43 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_design/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS = -O2 -g
2 |
3 | XCOREAI ?= 0
4 | ifeq ($(XCOREAI),1)
5 | # Xcore.ai Builds
6 | # Use `xmake XCOREAI=1`
7 |
8 | # The TARGET variable determines what target system the application is
9 | # compiled for. It either refers to an XN file in the source directories
10 | # or a valid argument for the --target option when compiling
11 | TARGET = XCORE-AI-EXPLORER
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
16 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
17 | # xcc for the final link (mapping) stage.
18 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
19 |
20 | else
21 | # Xcore-200 Builds
22 | # Use `xmake`
23 | TARGET = XCORE-200-EXPLORER
24 | XCC_FLAGS = $(BUILD_FLAGS)
25 | endif
26 |
27 | # The APP_NAME variable determines the name of the final .xe file. It should
28 | # not include the .xe postfix. If left blank the name will default to
29 | # the project name
30 | APP_NAME = app_design
31 |
32 | # The USED_MODULES variable lists other modules used by the application.
33 | USED_MODULES = lib_dsp(>=6.0.0)
34 |
35 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
36 | # project to create both xCORE and ARM binaries.
37 | XCORE_ARM_PROJECT = 0
38 |
39 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
40 | VERBOSE = 0
41 |
42 | XMOS_MAKE_PATH ?= ../..
43 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
44 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_design/src/app_design.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | #include
5 | #include "dsp.h"
6 |
7 | // Results of biquad coeff generation ara normalized such that a0 == 1.
8 | // When using lib_dsp biquad functions that data arrays must be DWORD aligned.
9 | // Declaring coeffs/state data globablly ensures this while locally does not!
10 | // The biquad functions utilize coeffs arrays of length 5 but ...
11 | // The coeffs below are arraned as N x 6 to keep coeff arrays DWORD aligned.
12 |
13 | int32_t [[aligned(8)]]coeff[8][6]; // Coefficients for each filter
14 | //Note: array size of 6 is chosen to enforce 64 bit alignment for ldd and std
15 | int32_t [[aligned(8)]]state[8][4] = {{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
16 | {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}; // State data for each filter
17 |
18 | const char* names[] =
19 | {
20 | "notch ", "lowpass ", "highpass ", "allpass ",
21 | "bandpass ", "peaking ", "lowshelf ", "highshelf",
22 | };
23 |
24 | int main( void )
25 | {
26 | // Generate biquad filter coefficients for various filters
27 | // Frequency specifications are normalized to Fs (i.e. 0.25 = 1/4 Fs)
28 | // Q for filters is 0.707.
29 | // Gain for peaking/lowshelf/highshelf filters is 3.0 dB.
30 | // Q format Q28 (4-bit signed integer, 28-bit fraction) is used.
31 |
32 | dsp_design_biquad_notch ( 0.25, 0.707, coeff[0], 28 );
33 | dsp_design_biquad_lowpass ( 0.25, 0.9, coeff[1], 28 );
34 | dsp_design_biquad_highpass ( 0.25, 0.707, coeff[2], 28 );
35 | dsp_design_biquad_allpass ( 0.25, 0.707, coeff[3], 28 );
36 | dsp_design_biquad_bandpass ( 0.24, 0.26, coeff[4], 28 );
37 | dsp_design_biquad_peaking ( 0.25, 0.707, 3.0, coeff[5], 28 );
38 | dsp_design_biquad_lowshelf ( 0.25, 0.707, 3.0, coeff[6], 28 );
39 | dsp_design_biquad_highshelf( 0.25, 0.707, 3.0, coeff[7], 28 );
40 |
41 | // Initialize filter state data to zeros
42 |
43 | for( int32_t ii = 0; ii < 8; ++ii ) {
44 | for( int32_t jj = 0; jj < 4; ++jj ) state[ii][jj] = 0;
45 | }
46 |
47 | // Perform 8 passes through filters independently using step function
48 |
49 | for( int32_t ii = 0; ii < 8; ++ii )
50 | {
51 | int32_t sample;
52 | printf( "Impulse response of %s, ", names[ii] );
53 | for( int32_t jj = 0; jj < 8; ++jj ) {
54 | if(jj==0) { // Dirac delta function. 1 at 0, 0 otherwise
55 | sample = Q28( 1.0 );
56 | } else {
57 | sample = 0;
58 | }
59 | int32_t y = dsp_filters_biquad( sample, coeff[ii], state[ii], 28 );
60 | printf( "%+04.8f, ", F28(y) );
61 | }
62 | printf( "\n" );
63 | }
64 |
65 | return 0;
66 | }
67 |
68 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_fft/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | app_fft
4 |
5 |
6 |
7 |
8 |
9 | com.xmos.cdt.core.LegacyProjectCheckerBuilder
10 |
11 |
12 |
13 |
14 | com.xmos.cdt.core.ModulePathBuilder
15 |
16 |
17 |
18 |
19 | com.xmos.cdt.core.ProjectInfoSyncBuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
25 | clean,full,incremental,
26 |
27 |
28 |
29 |
30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
31 | full,incremental,
32 |
33 |
34 |
35 |
36 |
37 | org.eclipse.cdt.core.cnature
38 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
39 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
40 | com.xmos.cdt.core.XdeProjectNature
41 |
42 |
43 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_fft/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS_complex = -O2 -g -report
2 | BUILD_FLAGS_tworeals = -O2 -g -report -DTWOREALS=1
3 | BUILD_FLAGS_complex_int16_buf = -O2 -g -report -DINT16_BUFFERS=1
4 | BUILD_FLAGS_tworeals_int16_buf = -O2 -g -report -DTWOREALS=1 -DINT16_BUFFERS=1
5 |
6 | XCOREAI ?= 0
7 | ifeq ($(XCOREAI),1)
8 | # Xcore.ai Builds
9 | # Use `xmake XCOREAI=1`
10 |
11 | # The TARGET variable determines what target system the application is
12 | # compiled for. It either refers to an XN file in the source directories
13 | # or a valid argument for the --target option when compiling
14 | TARGET = XCORE-AI-EXPLORER
15 |
16 | # The flags passed to xcc when building the application
17 | # You can also set the following to override flags for a particular language:
18 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
19 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
20 | # xcc for the final link (mapping) stage.
21 | XCC_FLAGS_complex_xcoreai = $(BUILD_FLAGS_complex)
22 | XCC_FLAGS_tworeals_xcoreai = $(BUILD_FLAGS_tworeals)
23 |
24 | XCC_FLAGS_complex_int16_buf_xcoreai = $(BUILD_FLAGS_complex_int16_buf)
25 | XCC_FLAGS_tworeals_int16_buf_xcoreai = $(BUILD_FLAGS_tworeals_int16_buf)
26 |
27 | else
28 | # Xcore-200 Builds
29 | # Use `xmake`
30 | TARGET = XCORE-200-EXPLORER
31 | XCC_FLAGS_complex = $(BUILD_FLAGS_complex)
32 | XCC_FLAGS_tworeals = $(BUILD_FLAGS_tworeals)
33 |
34 | XCC_FLAGS_complex_int16_buf = $(BUILD_FLAGS_complex_int16_buf)
35 | XCC_FLAGS_tworeals_int16_buf = $(BUILD_FLAGS_tworeals_int16_buf)
36 | endif
37 |
38 |
39 | # The APP_NAME variable determines the name of the final .xe file. It should
40 | # not include the .xe postfix. If left blank the name will default to
41 | # the project name
42 | APP_NAME = app_fft
43 |
44 | # The USED_MODULES variable lists other modules used by the application.
45 | USED_MODULES = lib_dsp(>=6.0.0)
46 |
47 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
48 | # project to create both xCORE and ARM binaries.
49 | XCORE_ARM_PROJECT = 0
50 |
51 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
52 | VERBOSE = 0
53 |
54 | XMOS_MAKE_PATH ?= ../..
55 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
56 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_fft_dif/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS = -O2 -g -report
2 |
3 | XCOREAI ?= 0
4 | ifeq ($(XCOREAI),1)
5 | # Xcore.ai Builds
6 | # Use `xmake XCOREAI=1`
7 |
8 | # The TARGET variable determines what target system the application is
9 | # compiled for. It either refers to an XN file in the source directories
10 | # or a valid argument for the --target option when compiling
11 | TARGET = XCORE-AI-EXPLORER
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
16 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
17 | # xcc for the final link (mapping) stage.
18 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
19 |
20 | else
21 | # Xcore-200 Builds
22 | # Use `xmake`
23 | TARGET = XCORE-200-EXPLORER
24 | XCC_FLAGS = $(BUILD_FLAGS)
25 | endif
26 |
27 | APP_NAME =
28 |
29 | USED_MODULES = lib_dsp(>=6.0.0)
30 |
31 |
32 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
33 | # project to create both xCORE and ARM binaries.
34 | XCORE_ARM_PROJECT = 0
35 |
36 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
37 | VERBOSE = 0
38 |
39 | XMOS_MAKE_PATH ?= ../..
40 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
41 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_fft_double_buf/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | app_fft_double_buf
4 |
5 |
6 |
7 |
8 |
9 | com.xmos.cdt.core.LegacyProjectCheckerBuilder
10 |
11 |
12 |
13 |
14 | com.xmos.cdt.core.ModulePathBuilder
15 |
16 |
17 |
18 |
19 | com.xmos.cdt.core.ProjectInfoSyncBuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
25 | clean,full,incremental,
26 |
27 |
28 | ?children?
29 | ?name?=outputEntries\|?children?=?name?=entry\\\\|\\|\||
30 |
31 |
32 | ?name?
33 |
34 |
35 |
36 | org.eclipse.cdt.make.core.append_environment
37 | true
38 |
39 |
40 | org.eclipse.cdt.make.core.buildArguments
41 | CONFIG=Debug
42 |
43 |
44 | org.eclipse.cdt.make.core.buildCommand
45 | xmake
46 |
47 |
48 | org.eclipse.cdt.make.core.cleanBuildTarget
49 | clean
50 |
51 |
52 | org.eclipse.cdt.make.core.contents
53 | org.eclipse.cdt.make.core.activeConfigSettings
54 |
55 |
56 | org.eclipse.cdt.make.core.enableAutoBuild
57 | false
58 |
59 |
60 | org.eclipse.cdt.make.core.enableCleanBuild
61 | true
62 |
63 |
64 | org.eclipse.cdt.make.core.enableFullBuild
65 | true
66 |
67 |
68 | org.eclipse.cdt.make.core.stopOnError
69 | true
70 |
71 |
72 | org.eclipse.cdt.make.core.useDefaultBuildCmd
73 | false
74 |
75 |
76 |
77 |
78 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
79 | full,incremental,
80 |
81 |
82 |
83 |
84 |
85 | org.eclipse.cdt.core.cnature
86 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
87 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
88 | com.xmos.cdt.core.XdeProjectNature
89 |
90 |
91 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_fft_double_buf/.xproject:
--------------------------------------------------------------------------------
1 |
2 | 1.0.0
3 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_fft_double_buf/Makefile:
--------------------------------------------------------------------------------
1 | COMMON_FLAGS = -O2 -g -report
2 |
3 | BUILD_FLAGS_complex = $(COMMON_FLAGS) -DNUM_CHANS=3
4 | BUILD_FLAGS_tworeals = $(COMMON_FLAGS) -DTWOREALS=1 -DNUM_CHANS=4
5 |
6 | BUILD_FLAGS_complex_int16_buf = $(COMMON_FLAGS) -DINT16_BUFFERS=1 -DNUM_CHANS=6
7 | BUILD_FLAGS_tworeals_int16_buf = $(COMMON_FLAGS) -DTWOREALS=1 -DINT16_BUFFERS=1 -DNUM_CHANS=8
8 |
9 | XCOREAI ?= 0
10 | ifeq ($(XCOREAI),1)
11 | # Xcore.ai Builds
12 | # Use `xmake XCOREAI=1`
13 |
14 | # The TARGET variable determines what target system the application is
15 | # compiled for. It either refers to an XN file in the source directories
16 | # or a valid argument for the --target option when compiling
17 | TARGET = XCORE-AI-EXPLORER
18 |
19 | # The flags passed to xcc when building the application
20 | # You can also set the following to override flags for a particular language:
21 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
22 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
23 | # xcc for the final link (mapping) stage.
24 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
25 | XCC_FLAGS_complex_xcoreai = $(BUILD_FLAGS_complex)
26 | XCC_FLAGS_tworeals_xcoreai = $(BUILD_FLAGS_tworeals)
27 |
28 | XCC_FLAGS_complex_int16_buf_xcoreai = $(BUILD_FLAGS_complex_int16_buf)
29 | XCC_FLAGS_tworeals_int16_buf_xcoreai = $(BUILD_FLAGS_tworeals_int16_buf)
30 |
31 | else
32 | # Xcore-200 Builds
33 | # Use `xmake`
34 | TARGET = xk-audio-216-mc
35 |
36 | XCC_FLAGS_complex = $(BUILD_FLAGS_complex)
37 | XCC_FLAGS_tworeals = $(BUILD_FLAGS_tworeals)
38 |
39 | XCC_FLAGS_complex_int16_buf = $(BUILD_FLAGS_complex_int16_buf)
40 | XCC_FLAGS_tworeals_int16_buf = $(BUILD_FLAGS_tworeals_int16_buf)
41 | endif
42 |
43 | # The APP_NAME variable determines the name of the final .xe file. It should
44 | # not include the .xe postfix. If left blank the name will default to
45 | # the project name
46 |
47 | APP_NAME = app_fft_double_buf
48 |
49 | # The USED_MODULES variable lists other build module used by the application.
50 | USED_MODULES = lib_dsp(>=6.0.0)
51 |
52 | #=============================================================================
53 | # The following part of the Makefile includes the common build infrastructure
54 | # for compiling XMOS applications. You should not need to edit below here.
55 |
56 | XMOS_MAKE_PATH ?= ../..
57 | include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
58 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_fft_double_buf/config.xscope:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_fft_real_single/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | app_fft_real_single
4 |
5 |
6 |
7 |
8 |
9 | com.xmos.cdt.core.LegacyProjectCheckerBuilder
10 |
11 |
12 |
13 |
14 | com.xmos.cdt.core.ModulePathBuilder
15 |
16 |
17 |
18 |
19 | com.xmos.cdt.core.ProjectInfoSyncBuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
25 | clean,full,incremental,
26 |
27 |
28 |
29 |
30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
31 | full,incremental,
32 |
33 |
34 |
35 |
36 |
37 | org.eclipse.cdt.core.cnature
38 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
39 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
40 | com.xmos.cdt.core.XdeProjectNature
41 |
42 |
43 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_fft_real_single/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS = -O2 -g -report
2 |
3 | XCOREAI ?= 0
4 | ifeq ($(XCOREAI),1)
5 | # Xcore.ai Builds
6 | # Use `xmake XCOREAI=1`
7 |
8 | # The TARGET variable determines what target system the application is
9 | # compiled for. It either refers to an XN file in the source directories
10 | # or a valid argument for the --target option when compiling
11 | TARGET = XCORE-AI-EXPLORER
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
16 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
17 | # xcc for the final link (mapping) stage.
18 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
19 |
20 | else
21 | # Xcore-200 Builds
22 | # Use `xmake`
23 | TARGET = XCORE-200-EXPLORER
24 | XCC_FLAGS = $(BUILD_FLAGS)
25 | endif
26 |
27 | APP_NAME =
28 | USED_MODULES = lib_dsp(>=6.0.0)
29 |
30 | XMOS_MAKE_PATH ?= ../..
31 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
32 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_fft_timing/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | app_fft_timing
4 |
5 |
6 |
7 |
8 |
9 | com.xmos.cdt.core.LegacyProjectCheckerBuilder
10 |
11 |
12 |
13 |
14 | com.xmos.cdt.core.ModulePathBuilder
15 |
16 |
17 |
18 |
19 | com.xmos.cdt.core.ProjectInfoSyncBuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
25 | clean,full,incremental,
26 |
27 |
28 |
29 |
30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
31 | full,incremental,
32 |
33 |
34 |
35 |
36 |
37 | org.eclipse.cdt.core.cnature
38 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
39 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
40 | com.xmos.cdt.core.XdeProjectNature
41 |
42 |
43 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_fft_timing/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS = -O2 -g -report
2 |
3 | XCOREAI ?= 0
4 | ifeq ($(XCOREAI),1)
5 | # Xcore.ai Builds
6 | # Use `xmake XCOREAI=1`
7 |
8 | # The TARGET variable determines what target system the application is
9 | # compiled for. It either refers to an XN file in the source directories
10 | # or a valid argument for the --target option when compiling
11 | TARGET = XCORE-AI-EXPLORER
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
16 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
17 | # xcc for the final link (mapping) stage.
18 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
19 |
20 | else
21 | # Xcore-200 Builds
22 | # Use `xmake`
23 | TARGET = XCORE-200-EXPLORER
24 | XCC_FLAGS = $(BUILD_FLAGS)
25 | endif
26 |
27 | APP_NAME =
28 | USED_MODULES = lib_dsp(>=6.0.0)
29 |
30 | XCORE_ARM_PROJECT = 0
31 | VERBOSE = 0
32 |
33 | XMOS_MAKE_PATH ?= ../..
34 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
35 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_fft_timing/src/app_fft.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | // XMOS DSP Library - Example to use FFT and inverse FFT
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #define ONE(N) \
12 | tmr :> t0 ;\
13 | dsp_fft_bit_reverse(data, N); \
14 | dsp_fft_forward(data, N, FFT_SINE(N)); \
15 | tmr :> t1 ;\
16 | t1 -= t0;\
17 | printf("%4d %12d %5d %5d %10.2f\n", N, t1, t1*10/625, t1/N, t1 / (float) N / (31-clz(N)) );
18 |
19 | #define ONI(N) \
20 | tmr :> t0 ;\
21 | dsp_fft_bit_reverse(data, N); \
22 | dsp_fft_inverse(data, N, FFT_SINE(N)); \
23 | tmr :> t1 ;\
24 | t1 -= t0;\
25 | printf("%4d %12d %5d %5d %10.2f\n", N, t1, t1*10/625, t1/N, t1 / (float) N / (31-clz(N)) );
26 |
27 | extern int dsp_fft_bit_reverse_xs2(dsp_complex_t a[], unsigned N);
28 |
29 | dsp_complex_t data[8192];
30 | dsp_complex_t data2[8192];
31 |
32 | int main(void) {
33 | timer tmr;
34 | int t0, t1;
35 | printf("Forward FFT instruction count and timings @ 62.5 MIPS, includes bit-reverse operation\n");
36 | printf(" N instructions us ins/N ins/NlogN\n");
37 | ONE(4);
38 | ONE(8);
39 | ONE(16);
40 | ONE(32);
41 | ONE(64);
42 | ONE(128);
43 | ONE(256);
44 | ONE(512);
45 | ONE(1024);
46 | ONE(2048);
47 | ONE(4096);
48 | ONE(8192);
49 | printf("\nInverse FFT instruction count and timings @ 62.5 MIPS, includes bit-reverse operation\n");
50 | printf(" N instructions us ins/N ins/NlogN\n");
51 | ONI(4);
52 | ONI(8);
53 | ONI(16);
54 | ONI(32);
55 | ONI(64);
56 | ONI(128);
57 | ONI(256);
58 | ONI(512);
59 | ONI(1024);
60 | ONI(2048);
61 | ONI(4096);
62 | ONI(8192);
63 | return 0;
64 | }
65 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_filters/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | app_filters
4 |
5 |
6 |
7 |
8 |
9 | com.xmos.cdt.core.LegacyProjectCheckerBuilder
10 |
11 |
12 |
13 |
14 | com.xmos.cdt.core.ModulePathBuilder
15 |
16 |
17 |
18 |
19 | com.xmos.cdt.core.ProjectInfoSyncBuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
25 | clean,full,incremental,
26 |
27 |
28 |
29 |
30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
31 | full,incremental,
32 |
33 |
34 |
35 |
36 |
37 | org.eclipse.cdt.core.cnature
38 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
39 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
40 | com.xmos.cdt.core.XdeProjectNature
41 |
42 |
43 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_filters/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS = -O2 -g
2 |
3 | XCOREAI ?= 0
4 | ifeq ($(XCOREAI),1)
5 | # Xcore.ai Builds
6 | # Use `xmake XCOREAI=1`
7 |
8 | # The TARGET variable determines what target system the application is
9 | # compiled for. It either refers to an XN file in the source directories
10 | # or a valid argument for the --target option when compiling
11 | TARGET = XCORE-AI-EXPLORER
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
16 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
17 | # xcc for the final link (mapping) stage.
18 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
19 |
20 | else
21 | # Xcore-200 Builds
22 | # Use `xmake`
23 | TARGET = XCORE-200-EXPLORER
24 | XCC_FLAGS = $(BUILD_FLAGS)
25 | endif
26 |
27 | # The APP_NAME variable determines the name of the final .xe file. It should
28 | # not include the .xe postfix. If left blank the name will default to
29 | # the project name
30 | APP_NAME = app_filters
31 |
32 | # The USED_MODULES variable lists other modules used by the application.
33 | USED_MODULES = lib_dsp(>=6.0.0)
34 |
35 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
36 | # project to create both xCORE and ARM binaries.
37 | XCORE_ARM_PROJECT = 0
38 |
39 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
40 | VERBOSE = 0
41 |
42 | XMOS_MAKE_PATH ?= ../..
43 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
44 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_math/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | app_math
4 |
5 |
6 |
7 |
8 |
9 | com.xmos.cdt.core.ModulePathBuilder
10 |
11 |
12 |
13 |
14 | com.xmos.cdt.core.ProjectInfoSyncBuilder
15 |
16 |
17 |
18 |
19 | com.xmos.cdt.core.LegacyProjectCheckerBuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
25 | clean,full,incremental,
26 |
27 |
28 |
29 |
30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
31 | full,incremental,
32 |
33 |
34 |
35 |
36 |
37 | org.eclipse.cdt.core.cnature
38 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
39 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
40 | com.xmos.cdt.core.XdeProjectNature
41 |
42 |
43 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_math/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS = -O2 -g
2 |
3 | XCOREAI ?= 0
4 | ifeq ($(XCOREAI),1)
5 | # Xcore.ai Builds
6 | # Use `xmake XCOREAI=1`
7 |
8 | # The TARGET variable determines what target system the application is
9 | # compiled for. It either refers to an XN file in the source directories
10 | # or a valid argument for the --target option when compiling
11 | TARGET = XCORE-AI-EXPLORER
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
16 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
17 | # xcc for the final link (mapping) stage.
18 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
19 |
20 | else
21 | # Xcore-200 Builds
22 | # Use `xmake`
23 | TARGET = XCORE-200-EXPLORER
24 | XCC_FLAGS = $(BUILD_FLAGS)
25 | endif
26 |
27 | # The APP_NAME variable determines the name of the final .xe file. It should
28 | # not include the .xe postfix. If left blank the name will default to
29 | # the project name
30 | APP_NAME = app_math
31 |
32 | # The USED_MODULES variable lists other modules used by the application.
33 | USED_MODULES = lib_dsp(>=6.0.0)
34 |
35 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
36 | # project to create both xCORE and ARM binaries.
37 | XCORE_ARM_PROJECT = 0
38 |
39 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
40 | VERBOSE = 0
41 |
42 | XMOS_MAKE_PATH ?= ../..
43 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
44 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_matrix/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | app_matrix
4 |
5 |
6 |
7 |
8 |
9 | com.xmos.cdt.core.ProjectInfoSyncBuilder
10 |
11 |
12 |
13 |
14 | com.xmos.cdt.core.LegacyProjectCheckerBuilder
15 |
16 |
17 |
18 |
19 | com.xmos.cdt.core.ModulePathBuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
25 | clean,full,incremental,
26 |
27 |
28 |
29 |
30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
31 | full,incremental,
32 |
33 |
34 |
35 |
36 |
37 | org.eclipse.cdt.core.cnature
38 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
39 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
40 | com.xmos.cdt.core.XdeProjectNature
41 |
42 |
43 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_matrix/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS = -O3 -g
2 |
3 | XCOREAI ?= 0
4 | ifeq ($(XCOREAI),1)
5 | # Xcore.ai Builds
6 | # Use `xmake XCOREAI=1`
7 |
8 | # The TARGET variable determines what target system the application is
9 | # compiled for. It either refers to an XN file in the source directories
10 | # or a valid argument for the --target option when compiling
11 | TARGET = XCORE-AI-EXPLORER
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
16 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
17 | # xcc for the final link (mapping) stage.
18 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
19 |
20 | else
21 | # Xcore-200 Builds
22 | # Use `xmake`
23 | TARGET = XCORE-200-EXPLORER
24 | XCC_FLAGS = $(BUILD_FLAGS)
25 | endif
26 |
27 | # The APP_NAME variable determines the name of the final .xe file. It should
28 | # not include the .xe postfix. If left blank the name will default to
29 | # the project name
30 | APP_NAME = app_matrix
31 |
32 | # The USED_MODULES variable lists other modules used by the application.
33 | USED_MODULES = lib_dsp(>=4.0.0)
34 |
35 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
36 | # project to create both xCORE and ARM binaries.
37 | XCORE_ARM_PROJECT = 0
38 |
39 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
40 | VERBOSE = 0
41 |
42 | XMOS_MAKE_PATH ?= ../..
43 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
44 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_statistics/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | app_statistics
4 |
5 |
6 |
7 |
8 |
9 | com.xmos.cdt.core.ProjectInfoSyncBuilder
10 |
11 |
12 |
13 |
14 | com.xmos.cdt.core.ModulePathBuilder
15 |
16 |
17 |
18 |
19 | com.xmos.cdt.core.LegacyProjectCheckerBuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
25 | clean,full,incremental,
26 |
27 |
28 |
29 |
30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
31 | full,incremental,
32 |
33 |
34 |
35 |
36 |
37 | org.eclipse.cdt.core.cnature
38 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
39 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
40 | com.xmos.cdt.core.XdeProjectNature
41 |
42 |
43 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_statistics/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS = -O2 -g
2 |
3 | XCOREAI ?= 0
4 | ifeq ($(XCOREAI),1)
5 | # Xcore.ai Builds
6 | # Use `xmake XCOREAI=1`
7 |
8 | # The TARGET variable determines what target system the application is
9 | # compiled for. It either refers to an XN file in the source directories
10 | # or a valid argument for the --target option when compiling
11 | TARGET = XCORE-AI-EXPLORER
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
16 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
17 | # xcc for the final link (mapping) stage.
18 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
19 |
20 | else
21 | # Xcore-200 Builds
22 | # Use `xmake`
23 | TARGET = XCORE-200-EXPLORER
24 | XCC_FLAGS = $(BUILD_FLAGS)
25 | endif
26 |
27 | # The APP_NAME variable determines the name of the final .xe file. It should
28 | # not include the .xe postfix. If left blank the name will default to
29 | # the project name
30 | APP_NAME = app_statistics
31 |
32 | # The USED_MODULES variable lists other modules used by the application.
33 | USED_MODULES = lib_dsp(>=6.0.0)
34 |
35 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
36 | # project to create both xCORE and ARM binaries.
37 | XCORE_ARM_PROJECT = 0
38 |
39 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
40 | VERBOSE = 0
41 |
42 | XMOS_MAKE_PATH ?= ../..
43 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
44 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_statistics/src/app_statistics.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | // XMOS DSP Library - Statistics Functions Test Program
4 | // Uses Q24 format
5 |
6 | // Include files
7 | #include
8 | #include
9 | #include
10 |
11 | // Define constants
12 |
13 | #define Q_M 8
14 | #define Q_N 24
15 |
16 | #define SAMPLE_LENGTH 50
17 | #define SHORT_SAMPLE_LENGTH 5
18 |
19 | // Declare global variables and arrays
20 | int32_t Src[] = { Q24(.11), Q24(.12), Q24(.13), Q24(.14), Q24(.15), Q24(.16), Q24(.17), Q24(.18), Q24(.19), Q24(.20),
21 | Q24(.21), Q24(.22), Q24(.23), Q24(.24), Q24(.25), Q24(.26), Q24(.27), Q24(.28), Q24(.29), Q24(.30),
22 | Q24(.31), Q24(.32), Q24(.33), Q24(.34), Q24(.35), Q24(.36), Q24(.37), Q24(.38), Q24(.39), Q24(.40),
23 | Q24(.41), Q24(.42), Q24(.43), Q24(.44), Q24(.45), Q24(.46), Q24(.47), Q24(.48), Q24(.49), Q24(.50),
24 | Q24(.51), Q24(.52), Q24(.53), Q24(.54), Q24(.55), Q24(.56), Q24(.57), Q24(.58), Q24(.59), Q24(.60)};
25 | int32_t Src2[] = { Q24(.51), Q24(.52), Q24(.53), Q24(.54), Q24(.55)};
26 | int32_t Dst[SAMPLE_LENGTH];
27 |
28 | int main(void)
29 | {
30 | int32_t result;
31 |
32 | result =
33 | dsp_vector_mean (Src, // Input vector
34 | SAMPLE_LENGTH, // Vector length
35 | Q_N); // Q Format N
36 |
37 | printf ("Vector Mean = %lf\n", F24 (result));
38 |
39 | result =
40 | dsp_vector_power (Src, // Input vector
41 | SAMPLE_LENGTH, // Vector length
42 | Q_N); // Q Format N
43 |
44 | printf ("Vector Power (sum of squares) = %lf\n", F24 (result));
45 |
46 | result =
47 | dsp_vector_rms (Src, // Input vector
48 | SAMPLE_LENGTH, // Vector length
49 | Q_N); // Q Format N
50 |
51 | printf ("Vector Root Mean Square = %lf\n", F24 (result));
52 |
53 | result =
54 | dsp_vector_dotprod (Src, // Input vector 1
55 | Src2, // Input vector 2
56 | SHORT_SAMPLE_LENGTH, // Vector length
57 | Q_N); // Q Format N
58 |
59 | printf ("Vector Dot Product = %lf\n", F24 (result));
60 |
61 | return (0);
62 | }
63 |
64 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_vector/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | app_vector
4 |
5 |
6 |
7 |
8 |
9 | com.xmos.cdt.core.LegacyProjectCheckerBuilder
10 |
11 |
12 |
13 |
14 | com.xmos.cdt.core.ModulePathBuilder
15 |
16 |
17 |
18 |
19 | com.xmos.cdt.core.ProjectInfoSyncBuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
25 | clean,full,incremental,
26 |
27 |
28 |
29 |
30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
31 | full,incremental,
32 |
33 |
34 |
35 |
36 |
37 | org.eclipse.cdt.core.cnature
38 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
39 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
40 | com.xmos.cdt.core.XdeProjectNature
41 |
42 |
43 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_vector/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS = -O2 -g
2 |
3 | XCOREAI ?= 0
4 | ifeq ($(XCOREAI),1)
5 | # Xcore.ai Builds
6 | # Use `xmake XCOREAI=1`
7 |
8 | # The TARGET variable determines what target system the application is
9 | # compiled for. It either refers to an XN file in the source directories
10 | # or a valid argument for the --target option when compiling
11 | TARGET = XCORE-AI-EXPLORER
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
16 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
17 | # xcc for the final link (mapping) stage.
18 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
19 |
20 | else
21 | # Xcore-200 Builds
22 | # Use `xmake`
23 | TARGET = XCORE-200-EXPLORER
24 | XCC_FLAGS = $(BUILD_FLAGS)
25 | endif
26 |
27 | # The APP_NAME variable determines the name of the final .xe file. It should
28 | # not include the .xe postfix. If left blank the name will default to
29 | # the project name
30 | APP_NAME = app_vector
31 |
32 | # The USED_MODULES variable lists other modules used by the application.
33 | USED_MODULES = lib_dsp(>=6.0.0)
34 |
35 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
36 | # project to create both xCORE and ARM binaries.
37 | XCORE_ARM_PROJECT = 0
38 |
39 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
40 | VERBOSE = 0
41 |
42 | XMOS_MAKE_PATH ?= ../..
43 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
44 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_window_post_fft/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS = -O2 -g -report
2 |
3 | XCOREAI ?= 0
4 | ifeq ($(XCOREAI),1)
5 | # Xcore.ai Builds
6 | # Use `xmake XCOREAI=1`
7 |
8 | # The TARGET variable determines what target system the application is
9 | # compiled for. It either refers to an XN file in the source directories
10 | # or a valid argument for the --target option when compiling
11 | TARGET = XCORE-AI-EXPLORER
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
16 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
17 | # xcc for the final link (mapping) stage.
18 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
19 |
20 | else
21 | # Xcore-200 Builds
22 | # Use `xmake`
23 | TARGET = XCORE-200-EXPLORER
24 | XCC_FLAGS = $(BUILD_FLAGS)
25 | endif
26 |
27 | APP_NAME =
28 | USED_MODULES = lib_dsp(>=6.0.0)
29 |
30 | XCORE_ARM_PROJECT = 0
31 | VERBOSE = 0
32 |
33 | XMOS_MAKE_PATH ?= ../..
34 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
35 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/app_window_post_fft/src/app_fft.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | // XMOS DSP Library - Example to use FFT and inverse FFT
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #define N 16
13 |
14 | int data[N] = {10, 4, 0, -5, 7, 8, 10, 1,
15 | 10, 4, 3, -5, 7, 8, 10, 1};
16 |
17 | int window[N] = {
18 | 0,
19 | 2494,
20 | 9597,
21 | 20228,
22 | 32767,
23 | 45307,
24 | 55938,
25 | 63041,
26 | 65536,
27 | 63041,
28 | 55938,
29 | 45307,
30 | 32768,
31 | 20228,
32 | 9597,
33 | 2494,
34 | };
35 | dsp_complex_t fftdata[N];
36 | dsp_complex_t fftdata2[N];
37 |
38 | #define f16(x) ((x)*16/65536.0)
39 |
40 | int main(void) {
41 | int errors = 0;
42 | for(int i = 0; i < 16; i++) {
43 | fftdata[i].re = data[i] << 16;
44 | fftdata[i].im = 0;
45 | fftdata2[i].re = data[i] * window[i];
46 | fftdata2[i].im = 0;
47 | }
48 |
49 | dsp_fft_bit_reverse(fftdata, N);
50 | dsp_fft_forward(fftdata, N, dsp_sine_16);
51 | dsp_fft_split_spectrum(fftdata, N);
52 |
53 | dsp_fft_bit_reverse(fftdata2, N);
54 | dsp_fft_forward(fftdata2, N, dsp_sine_16);
55 | dsp_fft_split_spectrum(fftdata2, N);
56 |
57 | dsp_complex_window_hanning_post_fft_half(fftdata, N/2);
58 | for(int32_t i=0; i 3 || abs(diffre) > 3) {
62 | printf( "%2d: %8.4f, %8.4f %8.4f %8.4f %8.4f %8.4f\n", i, f16(fftdata[i].re), f16(fftdata[i].im), f16(fftdata2[i].re), f16(fftdata2[i].im), f16(diffre), f16(diffim));
63 | errors++;
64 | }
65 | }
66 | if (errors == 0) {
67 | printf("Pass\n");
68 | } else {
69 | printf("Fail\n");
70 | }
71 | return 0;
72 | }
73 |
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/doc/rst/xdoc.conf:
--------------------------------------------------------------------------------
1 | XMOSNEWSTYLE=1
2 | SOURCE_INCLUDE_DIRS=../../src
--------------------------------------------------------------------------------
/AN00209_xCORE-200_DSP_Library/src/.dummy:
--------------------------------------------------------------------------------
1 | 111
2 |
--------------------------------------------------------------------------------
/README.rst:
--------------------------------------------------------------------------------
1 | xCORE-200 DSP Library
2 | =====================
3 |
4 | Summary
5 | -------
6 |
7 | This API reference manual describes the XMOS fixed-point digital signal processing
8 | software library. The library implements of a suite of common signal processing functions
9 | for use on XMOS xCORE-200 multicore microcontrollers.
10 |
11 | Required tools
12 | ..............
13 |
14 | * xTIMEcomposer Tools Version 14.2.1 or later
15 |
16 | Required hardware
17 | .................
18 |
19 | Only XMOS xCORE-200 based multicore microcontrollers are supported with this library.
20 | The previous generation XS1 based multicore microntrollers are not supported.
21 |
22 | The xCORE-200 has a single cycle 32x32->64 bit multiply/accumulate unit,
23 | single cycle double-word load and store, dual issue instruction execution,
24 | and other instruction set enhancements.
25 | These features make xCORE-200 an efficient platform for executing
26 | digital signal processing algorithms.
27 |
28 | Prerequisites
29 | .............
30 |
31 | This document assumes familiarity with the XMOS xCORE architecture,
32 | the XMOS tool chain, the 'C' programming language,
33 | and digital signal processing concepts.
34 |
35 | Software version and dependencies
36 | .................................
37 |
38 | The CHANGELOG contains information about the current and previous versions.
39 | For a list of direct dependencies, look for DEPENDENT_MODULES in lib_dsp/module_build_info.
40 |
41 | Related application notes
42 | .........................
43 |
44 | The following application notes use this library:
45 |
46 | * AN00209 - xCORE-200 DSP Library
47 |
--------------------------------------------------------------------------------
/lib_dsp/.makefile:
--------------------------------------------------------------------------------
1 | all:
2 | @echo "** Module only - only builds as part of application **"
3 | clean:
4 | @echo "** Module only - only builds as part of application **"
5 |
--------------------------------------------------------------------------------
/lib_dsp/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | lib_dsp
4 |
5 |
6 |
7 |
8 |
9 | com.xmos.cdt.core.ModulePathBuilder
10 |
11 |
12 |
13 |
14 | com.xmos.cdt.core.LegacyProjectCheckerBuilder
15 |
16 |
17 |
18 |
19 | com.xmos.cdt.core.ProjectInfoSyncBuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
25 | clean,full,incremental,
26 |
27 |
28 |
29 |
30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
31 | full,incremental,
32 |
33 |
34 |
35 |
36 |
37 | org.eclipse.cdt.core.cnature
38 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
39 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
40 | com.xmos.cdt.core.XdeProjectNature
41 |
42 |
43 |
--------------------------------------------------------------------------------
/lib_dsp/api/dsp.h:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | #ifndef DSP_H_
5 | #define DSP_H_
6 |
7 | #include
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 |
23 | /* Macro to time function calls
24 | * After execution of this line the value in cycle_taken is valid.
25 | * The calling context must contain the variables tmr, start_time, end_time, overhead_time, cycle_time
26 | * overhead_time must have a valid value before the call.
27 | */
28 | #define TIME_FUNCTION(function_call) do {tmr :> start_time; function_call; tmr :> end_time; cycles_taken = end_time-start_time-overhead_time;} while(0)
29 |
30 |
31 | #endif
32 |
33 |
--------------------------------------------------------------------------------
/lib_dsp/api/dsp_filters_fp.h:
--------------------------------------------------------------------------------
1 | // Copyright 2019-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | #ifndef DSP_FILTERS_FP_H_
5 | #define DSP_FILTERS_FP_H_
6 |
7 | #include "dsp_filters.h"
8 |
9 | /** This function implements a second order IIR filter (direct form I).
10 | *
11 | * The function operates on a single sample of input and output data (i.e. and
12 | * each call to the function processes one sample).
13 | *
14 | * The IIR filter algorithm executes a difference equation on current and past input values x
15 | * and past output values y:
16 | * ``y[n] = x[n]*b0 + x[n-1]*b1 + x[n-2]*b2 + y[n-1]*-a1 + y[n-2]*-a2``
17 | *
18 | * The filter coefficients are stored in forward order (e.g. ``b0,b1,b2,-a1,-a2``).
19 | *
20 | * Example showing a single Biquad filter
21 | *
22 | * \code
23 | * double filter_coeff[DSP_NUM_COEFFS_PER_BIQUAD] = { +0.5, -0.1, -0.5, -0.1, 0.1) };
24 | * double filter_state[DSP_NUM_STATES_PER_BIQUAD] = { 0, 0, 0, 0 };
25 | * double result = dsp_filters_biquad_fp( sample, filter_coeff, filter_state, 28 );
26 | * \endcode
27 | *
28 | * The IIR algorithm involves multiplication between double precision filter
29 | * coefficients and double precision state data producing a double precision result for each
30 | * coefficient and state data pair.
31 | *
32 | *
33 | * \param input_sample The new sample to be processed.
34 | * \param filter_coeffs Pointer to biquad coefficients array arranged as ``[b0,b1,b2,-a1,-a2]``.
35 | * \param state_data Pointer to filter state data array (initialized at startup to zeros).
36 | * The length of the state data array is 4.
37 | * \returns The resulting filter output sample.
38 | */
39 |
40 | double dsp_filters_biquad_fp
41 | (
42 | double input_sample,
43 | const double filter_coeffs[],
44 | double state_data[]
45 | );
46 |
47 | /** This function implements a cascaded direct form I BiQuad filter
48 | *
49 | * The function operates on a single sample of input and output data
50 | * (i.e. and each call to the function processes one sample).
51 | *
52 | * The IIR filter algorithm executes a difference equation on current and past input values x
53 | * and past output values y:
54 | * ``y[n] = x[n]*b0 + x[n-1]*b1 + x[n-2]*b2 + y[n-1]*-a1 + y[n-2]*-a2``
55 | *
56 | * The filter coefficients are stored in forward order
57 | * (e.g. ``section1:b0,b1,b2,-a1,-a2,sectionN:b0,b1,b2,-a1,-a2``).
58 | *
59 | * Example showing a 4x cascaded Biquad filter
60 | *
61 | * \code
62 | * double filter_coeff[4*DSP_NUM_COEFFS_PER_BIQUAD] = {
63 | * +0.5, -0.1, -0.5, -0.1, 0.1,
64 | * +0.5, -0.1, -0.5, -0.1, 0.1,
65 | * +0.5, -0.1, -0.5, -0.1, 0.1,
66 | * +0.5, -0.1, -0.5, -0.1, 0.1) };
67 | * double filter_state[4*DSP_NUM_STATES_PER_BIQUAD] = { 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 };
68 | * double result = dsp_filters_biquads_fp( sample, filter_coeff, filter_state, 4, 28 );
69 | * \endcode
70 | *
71 | * The IIR algorithm involves multiplication between double precision filter
72 | * coefficients and double precision state data producing a double precision result for each
73 | * coefficient and state data pair.
74 | *
75 | * \param input_sample The new sample to be processed.
76 | * \param filter_coeffs Pointer to biquad coefficients array for all BiQuad sections.
77 | * Arranged as ``[section1:b0,b1,b2,-a1,-a2,...sectionN:b0,b1,b2,-a1,-a2]``.
78 | * \param state_data Pointer to filter state data array (initialized at startup to zeros).
79 | * The length of the state data array is ``num_sections`` * 4.
80 | * \param num_sections Number of BiQuad sections.
81 | * \returns The resulting filter output sample.
82 | */
83 |
84 | double dsp_filters_biquads_fp
85 | (
86 | double input_sample,
87 | const double filter_coeffs[],
88 | double state_data[],
89 | const uint32_t num_sections
90 | );
91 |
92 | #endif
93 |
--------------------------------------------------------------------------------
/lib_dsp/api/dsp_float_type.h:
--------------------------------------------------------------------------------
1 | // Copyright 2019-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | #ifndef DSP_FLOAT_TYPE_H_
5 | #define DSP_FLOAT_TYPE_H_
6 |
7 | typedef double dsp_float_t;
8 |
9 | #endif /* DSP_FLOAT_TYPE_H_ */
10 |
--------------------------------------------------------------------------------
/lib_dsp/api/dsp_fp.h:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | #ifndef DSP_FP_H_
5 | #define DSP_FP_H_
6 |
7 | #ifdef __XC__
8 | #define UNSAFE unsafe
9 | #else
10 | #define UNSAFE
11 | #endif //__XC_
12 |
13 | #include
14 |
15 | //#include
16 | //#include
17 | #include
18 | //#include
19 | //#include
20 | //#include
21 | //#include
22 | //#include
23 | //#include
24 | //#include
25 | //#include
26 | //#include
27 |
28 |
29 | double dsp_poly_eval_fp(const double x, const double * UNSAFE coefs, const unsigned n_coefs);
30 |
31 |
32 | /*
33 | * Double precision DTF
34 | */
35 | void dsp_float_fft_make_sine_table(double * sine_lut, unsigned proc_frame_length);
36 | void dsp_float_fft_bit_reverse ( dsp_complex_float_t pts[], const uint32_t N );
37 | void dsp_float_fft_forward_fft ( dsp_complex_float_t pts[], const uint32_t N, const double sine[]);
38 | void dsp_float_fft_inverse_fft ( dsp_complex_float_t pts[], const uint32_t N, const double sine[]);
39 | void dsp_float_fft_split_spectrum ( dsp_complex_float_t pts[], const uint32_t N );
40 | void dsp_float_fft_merge_spectra ( dsp_complex_float_t pts[], const uint32_t N );
41 |
42 | void dsp_sub_vect_float(
43 | double * UNSAFE a,
44 | double * UNSAFE b,
45 | double * UNSAFE c,
46 | unsigned length);
47 |
48 | void dsp_add_vect_float(
49 | double * UNSAFE a,
50 | double * UNSAFE b,
51 | double * UNSAFE c,
52 | unsigned length);
53 |
54 | void dsp_mul_vect_float(
55 | double * UNSAFE a,
56 | double * UNSAFE b,
57 | double * UNSAFE c,
58 | unsigned length);
59 |
60 | void dsp_mul_vect_complex_float(
61 | dsp_complex_float_t * UNSAFE a,
62 | dsp_complex_float_t * UNSAFE b,
63 | dsp_complex_float_t * UNSAFE c,
64 | unsigned length);
65 | #endif
66 |
67 |
--------------------------------------------------------------------------------
/lib_dsp/api/dsp_math_int.h:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | #ifndef DSP_MATH_INT_H_
5 | #define DSP_MATH_INT_H_
6 |
7 | #include "stdint.h"
8 |
9 | /** Integer square root 32 -> 16 bits
10 | *
11 | * This function computes the square root of an unsigned input value
12 | * use dsp_math_sqrt() for fixed point square roots.
13 | *
14 | * \param x Unsigned 32-bit integer value
15 | * \returns Unsigned 32-bit integer value
16 | */
17 | uint32_t dsp_math_int_sqrt(uint32_t x);
18 |
19 | /** Integer square root, 64 -> 32 bits
20 | *
21 | * This function computes the square root of an unsigned input value
22 | * use dsp_math_sqrt() for fixed point square roots.
23 | *
24 | * \param x Unsigned 64-bit integer value
25 | * \returns Unsigned 32-bit integer value
26 | */
27 | uint32_t dsp_math_int_sqrt64(uint64_t x);
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/lib_dsp/doc/rst/xdoc.conf:
--------------------------------------------------------------------------------
1 | XMOSNEWSTYLE = 1
2 | DOXYGEN_DIRS=../../api
--------------------------------------------------------------------------------
/lib_dsp/lib_build_info.cmake:
--------------------------------------------------------------------------------
1 | set(LIB_NAME lib_dsp)
2 | set(LIB_VERSION 6.3.0)
3 | set(LIB_INCLUDES api)
4 | set(LIB_DEPENDENT_MODULES "lib_logging(3.2.0)")
5 | set(LIB_OPTIONAL_HEADERS debug_conf.h xmos_dsp_elements.h)
6 |
7 | XMOS_REGISTER_MODULE()
8 |
--------------------------------------------------------------------------------
/lib_dsp/module_build_info:
--------------------------------------------------------------------------------
1 | VERSION = 6.3.0
2 |
3 | DEPENDENT_MODULES = lib_logging(>=3.2.0)
4 |
5 | MODULE_XCC_FLAGS = $(XCC_FLAGS)
6 |
7 | OPTIONAL_HEADERS += debug_conf.h \
8 | xmos_dsp_elements.h
9 |
10 | EXPORT_INCLUDE_DIRS = api
11 |
12 | INCLUDE_DIRS = $(EXPORT_INCLUDE_DIRS)
13 |
14 | SOURCE_DIRS = src \
15 | src/bfp \
16 | src/fft \
17 | src/float \
18 | src/gen \
19 | src/testing
20 |
--------------------------------------------------------------------------------
/lib_dsp/module_description:
--------------------------------------------------------------------------------
1 | One line module description.
2 |
--------------------------------------------------------------------------------
/lib_dsp/src/bfp/dsp_bfp_cls.S:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | #if (defined(__XS2A__) || defined (__XS3A__))
5 | #define NSTACKWORDS 2
6 | .text
7 | .issue_mode dual
8 | .globl dsp_bfp_cls
9 | .align 16
10 | .skip 4
11 | .type dsp_bfp_cls,@function
12 | .cc_top dsp_bfp_cls.function,dsp_bfp_cls
13 |
14 | dsp_bfp_cls:
15 | { dualentsp NSTACKWORDS ; ldc r11, 0 } // r11 collects mask
16 | { stw r4, sp[0] ; sub r0, r0, 8 } // r0[r1] now last element
17 |
18 | .Lloop:
19 | ldd r2, r3, r0[r1] // pick re/im from vector
20 | { sub r1, r1, 1 ; clz r4, r2 } // headroom if positive
21 | { bt r4, .Lr2pos ; clz r4, r3 } // check if re is negative
22 | { neg r2, r2 ; nop } // re headroom if negative
23 | .Lr2pos:
24 | { bt r4, .Lr3pos ; or r11, r11, r2 } // check if im is negative
25 | { neg r3, r3 ; nop } // im headroom if negative
26 | .Lr3pos:
27 | { or r11, r11, r3 ; bt r1, .Lloop } // combine headrooms
28 |
29 | { ldw r4, sp[0] ; nop }
30 | { retsp NSTACKWORDS ; clz r0, r11 }
31 |
32 | // RETURN_REG_HOLDER
33 | .cc_bottom dsp_bfp_cls.function
34 | .set dsp_bfp_cls.nstackwords, NSTACKWORDS
35 | .globl dsp_bfp_cls.nstackwords
36 | .set dsp_bfp_cls.maxcores,1
37 | .globl dsp_bfp_cls.maxcores
38 | .set dsp_bfp_cls.maxtimers,0
39 | .globl dsp_bfp_cls.maxtimers
40 | .set dsp_bfp_cls.maxchanends,0
41 | .globl dsp_bfp_cls.maxchanends
42 | .Ltmp0:
43 | .size dsp_bfp_cls, .Ltmp0-dsp_bfp_cls
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/lib_dsp/src/dsp_adaptive.c:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | #include
5 | #include "dsp_qformat.h"
6 | #include "dsp_math.h"
7 | #include "dsp_filters.h"
8 | #include "dsp_vector.h"
9 | #include "dsp_statistics.h"
10 | #include "dsp_adaptive.h"
11 |
12 |
13 |
14 | int32_t dsp_adaptive_lms
15 | (
16 | int32_t source_sample,
17 | int32_t reference_sample,
18 | int32_t* error_sample,
19 | const int32_t* filter_coeffs,
20 | int32_t* state_data,
21 | const int32_t num_taps,
22 | const int32_t mu,
23 | const int32_t q_format
24 | ) {
25 | int32_t output_sample, mu_err;
26 |
27 | // Output signal y[n] is computed via standard FIR filter:
28 | // y[n] = b[0] * x[n] + b[1] * x[n-1] + b[2] * x[n-2] + ...+ b[N-1] * x[n-N+1]
29 |
30 | output_sample = dsp_filters_fir( source_sample, filter_coeffs, state_data, num_taps, q_format );
31 |
32 | // Error equals difference between reference and filter output:
33 | // e[n] = d[n] - y[n]
34 |
35 | *error_sample = reference_sample - output_sample;
36 |
37 | // FIR filter coefficients b[k] are updated on a sample-by-sample basis:
38 | // b[k] = b[k] + mu_err * x[n-k] --- where mu_err = e[n] * mu
39 |
40 | mu_err = dsp_math_multiply( *error_sample, mu, q_format );
41 | dsp_vector_muls_addv( state_data, mu_err, (int32_t*) filter_coeffs, (int32_t*) filter_coeffs, num_taps, q_format );
42 |
43 | return output_sample;
44 | }
45 |
46 |
47 |
48 | int32_t dsp_adaptive_nlms
49 | (
50 | int32_t source_sample,
51 | int32_t reference_sample,
52 | int32_t* error_sample,
53 | const int32_t* filter_coeffs,
54 | int32_t* state_data,
55 | const int32_t num_taps,
56 | const int32_t mu,
57 | const int32_t q_format
58 | ) {
59 | int32_t output_sample, energy, adjustment, ee, qq;
60 |
61 | // Output signal y[n] is computed via standard FIR filter:
62 | // y[n] = b[0] * x[n] + b[1] * x[n-1] + b[2] * x[n-2] + ...+ b[N-1] * x[n-N+1]
63 |
64 | output_sample = dsp_filters_fir( source_sample, filter_coeffs, state_data, num_taps, q_format );
65 |
66 | // Error equals difference between reference and filter output:
67 | // e[n] = d[n] - y[n]
68 |
69 | *error_sample = reference_sample - output_sample;
70 |
71 | // Compute the instantaneous enegry: E = x[n]^2 + x[n-1]^2 + ... + x[n-N+1]^2
72 | energy = dsp_vector_power( state_data, num_taps, q_format );
73 | //printf( "E = %08x %f\n", energy, F31(energy) );
74 |
75 | // adjustment = error * mu / energy
76 |
77 | // Adjust energy q_format to account for range of reciprocal
78 | for( qq = q_format, ee = energy; qq >= 0 && !(ee & 0x80000000); --qq ) ee <<= 1;
79 | energy = energy >> (q_format - qq);
80 | // Saturate the reciprocal value to max value for the given q_format
81 | if( energy < (1 << (31-(31-qq)*2)) ) energy = (1 << (31-(31-qq)*2)) + 0;
82 |
83 | energy = dsp_math_divide( (1 << qq), energy, qq );
84 | adjustment = dsp_math_multiply( *error_sample, mu, q_format );
85 | adjustment = dsp_math_multiply( energy, adjustment, qq + q_format - q_format );
86 |
87 | // FIR filter coefficients b[k] are updated on a sample-by-sample basis:
88 | // b[k] = b[k] + mu_err * x[n-k] --- where mu_err = e[n] * mu
89 |
90 | dsp_vector_muls_addv( state_data, adjustment, (int32_t*) filter_coeffs, (int32_t*) filter_coeffs, num_taps, q_format );
91 |
92 | return output_sample;
93 | }
94 |
--------------------------------------------------------------------------------
/lib_dsp/src/dsp_biquad.S:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | #if (defined(__XS2A__) || defined (__XS3A__))
5 |
6 | #define NSTACKWORDS 8
7 |
8 | .text
9 | .issue_mode dual
10 | .align 4
11 | .globl dsp_filters_biquads
12 | .type dsp_filters_biquads,@function
13 | .cc_top dsp_filters_biquads.function,dsp_filters_biquads
14 |
15 | /*
16 | int32_t dsp_filters_biquads
17 | (
18 | int32_t input_sample,
19 | const int32_t filter_coeffs[],
20 | int32_t state_data[],
21 | const uint32_t num_sections,
22 | const uint32_t q_format
23 | );
24 | */
25 | #define s0 r0
26 | #define filter_coeffs r1
27 | #define state_data r2
28 | #define num_sections r3
29 | #define h r4
30 | #define l r5
31 | #define s1 r6
32 | #define s2 r7
33 | #define c0 r8
34 | #define c1 r9
35 |
36 | #define q r11
37 |
38 | dsp_filters_biquads:
39 | {dualentsp NSTACKWORDS}
40 | std r4, r5, sp[0]
41 | std r6, r7, sp[1]
42 | std r8, r9, sp[2]
43 | {ldw q, sp[NSTACKWORDS+1];sub num_sections, num_sections, 1}
44 | loop:
45 | {ldc h, 0; mkmsk l, q} //s0 = x[n]
46 | shr l, l, 1
47 | ldd c1, c0, filter_coeffs[0] // b0 and b1
48 | ldd s1, s2, state_data[0] // x[n-1] and x[n-2]
49 | std s0, s1, state_data[0]
50 |
51 | maccs h, l, s0, c0 // x[n] * b0
52 | maccs h, l, s1, c1 // x[n-1] * b1
53 |
54 | ldd c1, c0, filter_coeffs[1] // b2 and a1
55 |
56 | maccs h, l, s2, c0 // x[n-2] * b2
57 | ldd s1, s2, state_data[1] // y[n-1] and y[n-2]
58 | maccs h, l, s1, c1 // y[n-1] * a1
59 |
60 | ldd c0, c1, filter_coeffs[2] // a2 and b0(next round)
61 | maccs h, l, s2, c1 // y[n-2] * a2
62 |
63 | lsats h, l, q
64 | lextract s0, h, l, q, 32
65 | std s0, s1, state_data[1]
66 |
67 | {bf num_sections, done;sub num_sections, num_sections, 1}
68 |
69 | {ldc h, 0; mkmsk l, q} //s0 = x[n]
70 | shr l, l, 1
71 | ldd s1, s2, state_data[2] // x[n-1] and x[n-2]
72 | std s0, s1, state_data[2]
73 |
74 | maccs h, l, s0, c0 // x[n] * b0
75 | ldd c1, c0, filter_coeffs[3] // b1 and b2
76 |
77 | maccs h, l, s1, c0 // x[n-1] * b1
78 | maccs h, l, s2, c1 // x[n-2] * b2
79 |
80 | ldd c0, c1, filter_coeffs[4] // a1 and a2
81 |
82 | ldd s1, s2, state_data[3] // y[n-1] and y[n-2]
83 |
84 | maccs h, l, s1, c1 // y[n-1] * a1
85 | maccs h, l, s2, c0 // y[n-2] * a2
86 |
87 | lsats h, l, q
88 | lextract s0, h, l, q, 32
89 | std s0, s1, state_data[3]
90 |
91 | ldaw filter_coeffs, filter_coeffs[10]
92 | ldaw state_data, state_data[8]
93 |
94 | {bt num_sections, loop;sub num_sections, num_sections, 1}
95 |
96 | done:
97 | ldd r4, r5, sp[0]
98 | ldd r6, r7, sp[1]
99 | ldd r8, r9, sp[2]
100 | retsp NSTACKWORDS
101 |
102 | // RETURN_REG_HOLDER
103 | .cc_bottom dsp_filters_biquads.function
104 | .set dsp_filters_biquads.nstackwords,NSTACKWORDS
105 | .globl dsp_filters_biquads.nstackwords
106 | .set dsp_filters_biquads.maxcores,1
107 | .globl dsp_filters_biquads.maxcores
108 | .set dsp_filters_biquads.maxtimers,0
109 | .globl dsp_filters_biquads.maxtimers
110 | .set dsp_filters_biquads.maxchanends,0
111 | .globl dsp_filters_biquads.maxchanends
112 | .Ltmp0:
113 | .size dsp_filters_biquads, .Ltmp0-dsp_filters_biquads
114 |
115 |
116 | #endif
117 |
--------------------------------------------------------------------------------
/lib_dsp/src/dsp_complex_fir.S:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | #if (defined(__XS2A__) || defined (__XS3A__))
5 |
6 | .text
7 | .issue_mode dual
8 | .globl dsp_complex_fir
9 | .type dsp_complex_fir,@function
10 | .cc_top dsp_complex_fir.function,dsp_complex_fir
11 |
12 | dsp_complex_fir:
13 | dualentsp 8
14 | std r9, r10, sp[2]
15 | { nop ; stw r4, sp[6] }
16 | { ldw r11, sp[9] ; ldc r9, 0}
17 | { ldc r10, 0 ; shl r11, r11, 3}
18 | { add r1, r1, r11 ; ldc r11, 0}
19 | std r7, r8, sp[1]
20 | std r5, r6, sp[0]
21 | { ldc r4, 0 ; ldc r8, 0 }
22 | .Lloop:
23 | maccs r8, r9, r4, r6
24 | sub r3, r3, 1
25 | ldd r4, r5, r1[r3]
26 | ldd r6, r7, r2[r3]
27 | maccs r10, r11, r4, r7
28 | maccs r10, r11, r5, r6
29 | maccs r8, r9, r5, r7
30 | { neg r6, r6 ; bt r3, .Lloop }
31 |
32 | maccs r8, r9, r4, r6
33 | ldw r3, sp[10]
34 | lextract r8, r8, r9, r3, 32
35 | ldd r5, r6, sp[0]
36 | ldw r4, sp[6]
37 | lextract r9, r10, r11, r3, 32
38 |
39 | std r9, r8, r0[0]
40 | ldd r9, r10, sp[2]
41 | ldd r7, r8, sp[1]
42 | retsp 8
43 |
44 | // RETURN_REG_HOLDER
45 | .cc_bottom dsp_complex_fir.function
46 | .set dsp_complex_fir.nstackwords,8
47 | .globl dsp_complex_fir.nstackwords
48 | .set dsp_complex_fir.maxcores,1
49 | .globl dsp_complex_fir.maxcores
50 | .set dsp_complex_fir.maxtimers,0
51 | .globl dsp_complex_fir.maxtimers
52 | .set dsp_complex_fir.maxchanends,0
53 | .globl dsp_complex_fir.maxchanends
54 | .Ltmp0:
55 | .size dsp_complex_fir, .Ltmp0-dsp_complex_fir
56 |
57 | .issue_mode single
58 |
59 | #endif
60 |
--------------------------------------------------------------------------------
/lib_dsp/src/dsp_complex_hann.S:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | #if (defined(__XS2A__) || defined (__XS3A__))
5 |
6 | #define NSTACKWORDS 6
7 |
8 | .text
9 | .issue_mode dual
10 | .align 4
11 | .globl dsp_complex_window_hanning_post_fft_half
12 | .type dsp_complex_window_hanning_post_fft_half,@function
13 | .cc_top dsp_complex_window_hanning_post_fft_half.function,dsp_complex_window_hanning_post_fft_half
14 |
15 | // dsp_complex_window_hanning_post_fft_half(data, N)
16 | dsp_complex_window_hanning_post_fft_half:
17 | { dualentsp NSTACKWORDS ; sub r1, r1, 2 }
18 | std r4, r5, sp[0]
19 | std r6, r7, sp[1]
20 | std r8, r9, sp[2]
21 |
22 | // Invariant: r6/r7 term i+1
23 | // r8/r9 term i+2
24 | // Start: i is N-2
25 | // r6/r7 term N-1
26 | // r8/r9 0/NyquistReal
27 |
28 |
29 | { add r8, r1, 1 ; nop }
30 |
31 | ldd r6, r7, r0[r8] // R6/R7 IM/RE bin[n-1]
32 | ldw r9, r0[1] // R9: Nyquist real term, R8: 0 (NyIm)
33 | ashr r6, r6, 1
34 | ashr r7, r7, 1
35 | ashr r9, r9, 1
36 | { ldc r8, 0 ; add r11, r7, 0 }
37 | .Lloop:
38 | ldd r4, r5, r0[r1]
39 | ashr r4, r4, 1
40 | ashr r5, r5, 1
41 | { add r3, r5, r9 ; add r2, r4, r8 }
42 | ashr r2, r2, 1
43 | ashr r3, r3, 1
44 | { sub r3, r7, r3 ; sub r2, r6, r2 }
45 | { add r9, r1, 1 ; sub r1, r1, 1 }
46 | std r2, r3, r0[r9]
47 | { add r9, r7, 0 ; add r8, r6, 0 }
48 | { add r7, r5, 0 ; add r6, r4, 0 }
49 | bt r1, .Lloop
50 |
51 | ldd r4, r5, r0[0] // R5: DC term; R4: NYQ term
52 | ashr r4, r4, 1
53 | ashr r5, r5, 1
54 | { add r3, r5, r9 ; add r2, r8, 0 }
55 | ashr r2, r2, 1
56 | ashr r3, r3, 1
57 | { sub r3, r7, r3 ; sub r2, r6, r2 }
58 | std r2, r3, r0[1]
59 |
60 | { sub r4, r4, r11 ; sub r5, r5, r7 }
61 | std r4, r5, r0[0]
62 |
63 | ldd r4, r5, sp[0]
64 | ldd r6, r7, sp[1]
65 | ldd r8, r9, sp[2]
66 | retsp NSTACKWORDS
67 |
68 | // RETURN_REG_HOLDER
69 | .cc_bottom dsp_complex_window_hanning_post_fft_half.function
70 | .set dsp_complex_window_hanning_post_fft_half.nstackwords,NSTACKWORDS
71 | .globl dsp_complex_window_hanning_post_fft_half.nstackwords
72 | .set dsp_complex_window_hanning_post_fft_half.maxcores,1
73 | .globl dsp_complex_window_hanning_post_fft_half.maxcores
74 | .set dsp_complex_window_hanning_post_fft_half.maxtimers,0
75 | .globl dsp_complex_window_hanning_post_fft_half.maxtimers
76 | .set dsp_complex_window_hanning_post_fft_half.maxchanends,0
77 | .globl dsp_complex_window_hanning_post_fft_half.maxchanends
78 | .Ltmp3:
79 | .size dsp_complex_window_hanning_post_fft_half, .Ltmp3-dsp_complex_window_hanning_post_fft_half
80 |
81 | #endif
82 |
--------------------------------------------------------------------------------
/lib_dsp/src/dsp_idct.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | #include "dsp_dct.h"
5 |
6 | /* This is a very limited inverse DCT implementation.
7 | */
8 |
9 | static inline int32_t mulcos(int32_t x, int32_t cos) {
10 | long long r = cos * (long long) x;
11 | return r >> 31;
12 | }
13 |
14 |
15 | void dsp_dct_inverse4(int32_t output[4], int32_t input[4]) {
16 | int32_t z = input[0] >> 1;
17 | int32_t y1 = mulcos(input[1], 1984016189) ;
18 | int32_t y3 = mulcos(input[3], 1984016189);
19 | int32_t y1_ = mulcos(input[1], 821806413);
20 | int32_t y3_ = mulcos(input[3], 821806413);
21 | int32_t y2 = mulcos(input[2], 1518500250);
22 | output[0] = z + y1 + y2 + y3_;
23 | output[1] = z + y1_ - y2 - y3;
24 | output[2] = z - y1_ - y2 + y3;
25 | output[3] = z - y1 + y2 - y3_;
26 | }
27 |
28 | void dsp_dct_inverse3(int32_t output[3], int32_t input[3]) {
29 | int32_t z = input[0] >> 1;
30 | int32_t y = mulcos(input[1], 1859775393);
31 | int32_t x = mulcos(input[2], 1073741824);
32 | output[0] = y + x + z;
33 | output[1] = z-input[2];
34 | output[2] = -y + x + z;
35 | }
36 |
37 | void dsp_dct_inverse2(int32_t output[2], int32_t input[2]) {
38 | int32_t z = input[0] >> 1;
39 | int32_t s = mulcos(input[1], 1518500250);
40 | output[0] = z + s;
41 | output[1] = z - s;
42 | }
43 |
44 | void dsp_dct_inverse1(int32_t output[1], int32_t input[1]) {
45 | output[0] = input[0];
46 | }
47 |
48 | #ifdef INCLUDE_REFERENCE_DCT
49 | #include
50 |
51 | void referenceIDCT(int32_t output[], int32_t input[], int32_t N) {
52 | for(int32_t k = 0; k < N; k++) {
53 | double sum = input[0]/2.0;
54 | for(int32_t i = 1; i < N; i++) {
55 | double z = input[i] * cos(M_PI*i*(2*k+1)/(2*N));
56 | sum += z;
57 | }
58 | output[k] = sum;
59 | }
60 | }
61 |
62 | #endif
63 |
--------------------------------------------------------------------------------
/lib_dsp/src/dsp_logistics.S:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | #if (defined(__XS2A__) || defined (__XS3A__))
5 |
6 | #define NSTACKWORDS 0
7 |
8 | .text
9 | .issue_mode dual
10 | .globl dsp_math_logistics_fast
11 | .align 4
12 | .type dsp_math_logistics_fast,@function
13 | .cc_top dsp_math_logistics_fast.function,dsp_math_logistics_fast
14 |
15 |
16 | dsp_math_logistics_fast:
17 | dualentsp NSTACKWORDS
18 |
19 | { clz r11, r0 ; neg r1, r0 } // test on >= 0
20 | { bt r11, pos ; shr r2, r1, 24 } // get integer part
21 | { nop ; shr r11, r2, 3 } // test on >= 8
22 | { bt r11, zero ; ldap r11, .log_slope }
23 | { ldw r3, r11[r2] ; ldap r11, .log_offset }
24 | { ldw r2, r11[r2] ; mkmsk r0, 24 }
25 | maccu r2, r11, r3, r1
26 | { retsp NSTACKWORDS ; sub r0, r0, r2 }
27 |
28 | pos:
29 | { shr r1, r0, 24 ; add r2, r0, 0 } // get integer part
30 | { shr r11, r1, 3 ; nop } // test on >= 8: 1.0
31 | { bt r11, one ; ldap r11, .log_slope } // get first lookup
32 | { ldw r3, r11[r1] ; ldap r11, .log_offset } // get second lookup
33 | { ldw r0, r11[r1] ; nop }
34 | maccu r0, r11, r3, r2
35 | { retsp NSTACKWORDS ; nop }
36 | zero:
37 | { retsp NSTACKWORDS ; ldc r0, 0 }
38 | one:
39 | { retsp NSTACKWORDS ; mkmsk r0, 24 }
40 |
41 | .align 4
42 | .log_slope:
43 | .word 1015490930,640498971,297985800,120120271,46079377,17219453,6371555,3717288
44 | .log_offset:
45 | .word 8388608,9853420,12529304,14613666,15770555,16334225,16588473,16661050
46 |
47 | // RETURN_REG_HOLDER
48 | .cc_bottom dsp_math_logistics_fast.function
49 | .set dsp_math_logistics_fast.nstackwords,NSTACKWORDS
50 | .globl dsp_math_logistics_fast.nstackwords
51 | .set dsp_math_logistics_fast.maxcores,1
52 | .globl dsp_math_logistics_fast.maxcores
53 | .set dsp_math_logistics_fast.maxtimers,0
54 | .globl dsp_math_logistics_fast.maxtimers
55 | .set dsp_math_logistics_fast.maxchanends,0
56 | .globl dsp_math_logistics_fast.maxchanends
57 | .Ltmp0:
58 | .size dsp_math_logistics_fast, .Ltmp0-dsp_math_logistics_fast
59 |
60 | .issue_mode single
61 |
62 | #endif
63 |
64 |
65 |
--------------------------------------------------------------------------------
/lib_dsp/src/dsp_math_int.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | #include
4 | #include
5 | #include
6 | #include "dsp_math_int.h"
7 |
8 | uint32_t dsp_math_int_sqrt(uint32_t x) {
9 | int32_t zeroes;
10 | int32_t approx;
11 | int32_t corr;
12 |
13 | if (x < 2) {
14 | return x;
15 | }
16 | zeroes = clz(x);
17 |
18 | zeroes = zeroes & ~1;
19 | zeroes = (32-zeroes) >> 1;
20 | approx = x >> zeroes;
21 | for(uint32_t i = 0; i < 4; i++) {
22 | corr = ((((approx*approx) - (int)x) / approx)+1) >> 1;
23 | approx -= corr;
24 | }
25 | return approx;
26 | }
27 |
28 | uint32_t dsp_math_int_sqrt64(uint64_t hl) {
29 | uint32_t xh = hl >> 32;
30 | uint32_t xl = hl;
31 | uint32_t approx;
32 | int32_t corr;
33 |
34 | if (xh == 0) {
35 | return dsp_math_int_sqrt(xl);
36 | }
37 |
38 | approx = dsp_math_int_sqrt(xh);
39 | if (approx > 0xffff) {
40 | return ~0;
41 | }
42 | approx = approx << 16;
43 | xl = -xl;
44 | xh = -xh - 1;
45 | for(uint32_t i = 0; i < 4; i++) {
46 | int32_t h = xh;
47 | uint32_t l = xl;
48 | int32_t q, r;
49 | {h,l} = mac(approx, approx, h, l);
50 | if (h >= 0) {
51 | asm("ldivu %0,%1,%2,%3,%4" : "=r"(q), "=r"(r):"r" (h), "r"(l),"r"(approx));
52 | } else {
53 | l = -l;
54 | h = -h - 1;
55 | asm("ldivu %0,%1,%2,%3,%4" : "=r"(q), "=r"(r):"r" (h), "r"(l),"r"(approx));
56 | q = -q;
57 | }
58 | corr = (q+1) >> 1;
59 | approx -= corr;
60 | }
61 | return approx;
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/lib_dsp/src/dsp_min_vector.S:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | #if (defined(__XS2A__) || defined (__XS3A__))
5 |
6 | #define NSTACKWORDS 2
7 |
8 | .text
9 | .issue_mode dual
10 | .align 4
11 | .globl dsp_vector_minv
12 | .type dsp_vector_minv,@function
13 | .cc_top dsp_vector_minv.function,dsp_vector_minv
14 |
15 | dsp_vector_minv:
16 | { dualentsp NSTACKWORDS ; sub r2, r2, 1 }
17 | std r4, r5, sp[0]
18 | .Lloop:
19 | ldw r4, r0[r2]
20 | ldw r3, r1[r2]
21 | lsu r11, r4, r3
22 | bt r11, .Lnot
23 | stw r3, r0[r2]
24 | .Lnot:
25 | { sub r2, r2, 1 ; bt r2, .Lloop }
26 |
27 | ldd r4, r5, sp[0]
28 | retsp NSTACKWORDS
29 |
30 | // RETURN_REG_HOLDER
31 | .cc_bottom dsp_vector_minv.function
32 | .set dsp_vector_minv.nstackwords,NSTACKWORDS
33 | .globl dsp_vector_minv.nstackwords
34 | .set dsp_vector_minv.maxcores,1
35 | .globl dsp_vector_minv.maxcores
36 | .set dsp_vector_minv.maxtimers,0
37 | .globl dsp_vector_minv.maxtimers
38 | .set dsp_vector_minv.maxchanends,0
39 | .globl dsp_vector_minv.maxchanends
40 | .Ltmp0:
41 | .size dsp_vector_minv, .Ltmp0-dsp_vector_minv
42 |
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/lib_dsp/src/dsp_poly_eval.S:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | #if (defined(__XS2A__) || defined (__XS3A__))
5 |
6 | #define NSTACKWORDS 4
7 |
8 | .text
9 | .issue_mode dual
10 | .align 4
11 | .globl dsp_poly_eval_impl_xs2
12 | .type dsp_poly_eval_impl_xs2,@function
13 | .cc_top dsp_poly_eval_impl_xs2.function,dsp_poly_eval_impl_xs2
14 |
15 | /*
16 | int32_t dsp_poly_eval_impl_xs2
17 | (
18 | int32_t x,
19 | const int32_t * coefs,
20 | const unsigned n_coefs
21 | );
22 | */
23 | #define x r0
24 | #define coefs r1
25 | #define n_coefs r2
26 | #define thirty_one r3
27 |
28 | #define h r4
29 | #define l r5
30 | #define rounding r6
31 |
32 | #define t r11
33 |
34 | dsp_poly_eval_impl_xs2:
35 | {dualentsp NSTACKWORDS}
36 | std r4, r5, sp[0]
37 | std r6, r7, sp[1]
38 |
39 | {sub n_coefs, n_coefs, 1; ldc h, 1}
40 | {ldw t, coefs[n_coefs]; ldc l, 30}
41 | {shl rounding, h, l; ldc thirty_one, 31}
42 |
43 | {sub n_coefs, n_coefs, 1; nop}
44 | {ldc h, 0; mov l, rounding}
45 | loop:
46 | maccs h, l, x, t
47 | lextract t, h, l, thirty_one, 32
48 | {ldw h, coefs[n_coefs]; mov l, rounding}
49 | {add t, t, h; ldc h, 0}
50 | {sub n_coefs, n_coefs, 1; bt n_coefs, loop}
51 |
52 | done:
53 | ldd r4, r5, sp[0]
54 | ldd r6, r7, sp[1]
55 | {retsp NSTACKWORDS;mov r0, t}
56 |
57 | // RETURN_REG_HOLDER
58 | .cc_bottom dsp_poly_eval_impl_xs2.function
59 | .set dsp_poly_eval_impl_xs2.nstackwords,NSTACKWORDS
60 | .globl dsp_poly_eval_impl_xs2.nstackwords
61 | .set dsp_poly_eval_impl_xs2.maxcores,1
62 | .globl dsp_poly_eval_impl_xs2.maxcores
63 | .set dsp_poly_eval_impl_xs2.maxtimers,0
64 | .globl dsp_poly_eval_impl_xs2.maxtimers
65 | .set dsp_poly_eval_impl_xs2.maxchanends,0
66 | .globl dsp_poly_eval_impl_xs2.maxchanends
67 | .Ltmp0:
68 | .size dsp_poly_eval_impl_xs2, .Ltmp0-dsp_poly_eval_impl_xs2
69 |
70 |
71 | #endif
72 |
--------------------------------------------------------------------------------
/lib_dsp/src/dsp_sqrt.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2018-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | #include "dsp_math.h"
4 |
5 | void dsp_sqrt_calc_exp(const int exp, const unsigned hr, int * shl, int * e){
6 | int even_exp = exp - hr;
7 | if(even_exp & 1){
8 | even_exp += 1;
9 | if(hr){
10 | *shl = hr - 1;
11 | *e = even_exp/2 -14;
12 | } else {
13 | *shl = -1;
14 | *e = even_exp/2 -14;
15 | }
16 | } else {
17 | *shl = hr;
18 | *e = even_exp/2 -14;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/lib_dsp/src/fft/dsp_fft_bit_reverse.S:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | #if (defined(__XS2A__) || defined (__XS3A__))
5 |
6 | .text
7 | .issue_mode dual
8 | .globl dsp_fft_bit_reverse
9 | .align 4
10 | .type dsp_fft_bit_reverse,@function
11 | .cc_top dsp_fft_bit_reverse.function,dsp_fft_bit_reverse
12 |
13 | #define NSTACKWORDS 4
14 |
15 | dsp_fft_bit_reverse:
16 | { dualentsp NSTACKWORDS ; clz r2, r1}
17 | std r6, r7, sp[1]
18 | std r4, r5, sp[0]
19 | { add r2, r2, 1 ; shr r1, r1, 1 }
20 | { shl r1, r1, 1 ; nop }
21 |
22 | loop:
23 | { bitrev r3, r1 ; shl r11, r1, r2 }
24 | { lsu r11, r3, r11 ; shr r3, r3, r2 }
25 | { bf r11, dontswap ; sub r11, r1, 1 }
26 | ldd r4, r5, r0[r1]
27 | ldd r6, r7, r0[r3]
28 | std r4, r5, r0[r3]
29 | std r6, r7, r0[r1]
30 | dontswap:
31 | { bitrev r3, r11 ; shl r1, r11, r2 }
32 | { lsu r1, r3, r1 ; shr r3, r3, r2 }
33 | { bf r1, dontswap2 ; sub r1, r11, 1 }
34 | ldd r4, r5, r0[r11]
35 | ldd r6, r7, r0[r3]
36 | std r4, r5, r0[r3]
37 | std r6, r7, r0[r11]
38 | dontswap2:
39 | bt r1, loop
40 |
41 | ldd r6, r7, sp[1]
42 | ldd r4, r5, sp[0]
43 | retsp NSTACKWORDS
44 |
45 | // RETURN_REG_HOLDER
46 | .cc_bottom dsp_fft_bit_reverse.function
47 | .set dsp_fft_bit_reverse.nstackwords,NSTACKWORDS
48 | .globl dsp_fft_bit_reverse.nstackwords
49 | .set dsp_fft_bit_reverse.maxcores,1
50 | .globl dsp_fft_bit_reverse.maxcores
51 | .set dsp_fft_bit_reverse.maxtimers,0
52 | .globl dsp_fft_bit_reverse.maxtimers
53 | .set dsp_fft_bit_reverse.maxchanends,0
54 | .globl dsp_fft_bit_reverse.maxchanends
55 | .Ltmp0:
56 | .size dsp_fft_bit_reverse, .Ltmp0-dsp_fft_bit_reverse
57 |
58 | .issue_mode single
59 |
60 | #endif
61 |
--------------------------------------------------------------------------------
/lib_dsp/src/fft/dsp_fft_merge_spectra.S:
--------------------------------------------------------------------------------
1 | // Copyright 2016-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | .section .dp.data,"awd",@progbits
5 | .text
6 |
7 | #if (defined(__XS2A__) || defined (__XS3A__))
8 | .cc_top dsp_fft_merge_spectra_xs2.function
9 | .globl dsp_fft_merge_spectra_xs2
10 | .align 4
11 | .type dsp_fft_merge_spectra_xs2,@function
12 |
13 | #define NSTACKWORDS 6
14 | #define p r0
15 | #define j r1
16 | #define re0 r2
17 | #define re1 r3
18 |
19 | #define im0 r4
20 | #define im1 r5
21 |
22 | #define i r11
23 |
24 | // void dsp_fft_merge_spectra_xs2(fft_complex f[], unsigned N)
25 |
26 | dsp_fft_merge_spectra_xs2:
27 | .align 8
28 | .issue_mode dual
29 | DUALENTSP_lu6 NSTACKWORDS
30 | std r5, r4, sp[0]
31 | std r6, r7, sp[1]
32 | std r8, r9, sp[2]
33 |
34 | //reverse the second half
35 | {shr i, j, 1; mov r8, j}
36 | {add i, i, 1; sub j, j, 1}
37 | .Ltmp_second_half_reorder_loop:
38 | ldd re0, im0, p[i]
39 | ldd re1, im1, p[j]
40 | std re1, im1, p[i]
41 | std re0, im0, p[j]
42 | {add i, i, 1; sub j, j, 1}
43 | {eq im0, i, j;nop}
44 | {bf im0, .Ltmp_second_half_reorder_loop; nop}
45 |
46 | //fix the middle
47 | ldw im0, p[1]
48 | ldw re0, p[r8]
49 | stw re0, p[1]
50 | stw im0, p[r8]
51 |
52 | //merge the spectrum
53 | {ldc i, 1; sub j, r8, 1}
54 | .Ltmp_reorder_loop:
55 | ldd im0, re0, p[i]
56 | ldd im1, re1, p[j]
57 | {sub re0, re0, im1; add im1, im1, re0}
58 | {add im0, im0, re1; sub re1, re1, im0}
59 |
60 | std im0, re0, p[i]
61 | std re1, im1, p[j]
62 | {add i, i, 1; sub j, j, 1}
63 | {eq im0, i, j;nop}
64 | {bf im0, .Ltmp_reorder_loop; nop}
65 |
66 | ldd r5, r4, sp[0]
67 | ldd r6, r7, sp[1]
68 | ldd r8, r9, sp[2]
69 | retsp NSTACKWORDS
70 |
71 | .tmp_dsp_fft_merge_spectra_xs2:
72 | .size dsp_fft_merge_spectra_xs2, .tmp_dsp_fft_merge_spectra_xs2-dsp_fft_merge_spectra_xs2
73 | .align 4
74 | .cc_bottom dsp_fft_merge_spectra_xs2.function
75 |
76 | .set dsp_fft_merge_spectra_xs2.nstackwords,NSTACKWORDS
77 | .globl dsp_fft_merge_spectra_xs2.nstackwords
78 | .set dsp_fft_merge_spectra_xs2.maxcores,1
79 | .globl dsp_fft_merge_spectra_xs2.maxcores
80 | .set dsp_fft_merge_spectra_xs2.maxtimers,0
81 | .globl dsp_fft_merge_spectra_xs2.maxtimers
82 | .set dsp_fft_merge_spectra_xs2.maxchanends,0
83 | .globl dsp_fft_merge_spectra_xs2.maxchanends
84 | #endif
85 |
--------------------------------------------------------------------------------
/lib_dsp/src/fft/dsp_fft_split_spectrum.S:
--------------------------------------------------------------------------------
1 | // Copyright 2015-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | .section .dp.data,"awd",@progbits
5 | .text
6 |
7 | #if (defined(__XS2A__) || defined (__XS3A__))
8 | .cc_top dsp_fft_split_spectrum_xs2.function
9 | .globl dsp_fft_split_spectrum_xs2
10 | .align 4
11 | .type dsp_fft_split_spectrum_xs2,@function
12 |
13 | #define NSTACKWORDS 4
14 | #define p r0
15 | #define j r1
16 | #define re0 r2
17 | #define re1 r3
18 |
19 | #define im0 r4
20 | #define im1 r5
21 |
22 | #define i r11
23 |
24 | // void dsp_fft_split_spectrum_xs2(fft_complex f[], unsigned N)
25 |
26 | dsp_fft_split_spectrum_xs2:
27 | .align 8
28 | .issue_mode dual
29 | DUALENTSP_lu6 NSTACKWORDS
30 | std r5, r4, sp[0]
31 | std r6, r7, sp[1]
32 | mov r6, j
33 | {ldc i, 1; sub j, j, 1}
34 |
35 | .Ltmp_reorder_loop:
36 | ldd im0, re0, p[i]
37 | ldd im1, re1, p[j]
38 | ashr im0, im0, 1
39 | ashr im1, im1, 1
40 | ashr re0, re0, 1
41 | ashr re1, re1, 1
42 | {add re0, re0, re1; sub re1, re1, re0}
43 | {add im0, im0, im1; sub im1, im0, im1}
44 |
45 | std im1, re0, p[i]
46 | std re1, im0, p[j]
47 | {add i, i, 1; sub j, j, 1}
48 | {eq im0, i, j; nop}
49 | {bf im0, .Ltmp_reorder_loop; nop}
50 |
51 | {shr j, r6, 1} // j = N/2
52 | ldd re1, re0, p[0]
53 | ldd im1, im0, p[j]
54 | std im0, re0, p[0]
55 | std im1, re1, p[j]
56 | {add i, j, 1; sub j, r6, 1} //i = N/2+1, j= N-1
57 |
58 | .Ltmp_second_reorder_loop:
59 | ldd im0, re0, p[i]
60 | ldd im1, re1, p[j]
61 | std im1, re1, p[i]
62 | std im0, re0, p[j]
63 | {add i, i, 1; sub j, j, 1}
64 | {eq im0, i, j; nop}
65 | {bf im0, .Ltmp_second_reorder_loop; nop}
66 |
67 | ldd r5, r4, sp[0]
68 | ldd r6, r7, sp[1]
69 | retsp NSTACKWORDS
70 |
71 | .tmp_dsp_fft_split_spectrum_xs2:
72 | .size dsp_fft_split_spectrum_xs2, .tmp_dsp_fft_split_spectrum_xs2-dsp_fft_split_spectrum_xs2
73 | .align 4
74 | .cc_bottom dsp_fft_split_spectrum_xs2.function
75 |
76 | .set dsp_fft_split_spectrum_xs2.nstackwords,NSTACKWORDS
77 | .globl dsp_fft_split_spectrum_xs2.nstackwords
78 | .set dsp_fft_split_spectrum_xs2.maxcores,1
79 | .globl dsp_fft_split_spectrum_xs2.maxcores
80 | .set dsp_fft_split_spectrum_xs2.maxtimers,0
81 | .globl dsp_fft_split_spectrum_xs2.maxtimers
82 | .set dsp_fft_split_spectrum_xs2.maxchanends,0
83 | .globl dsp_fft_split_spectrum_xs2.maxchanends
84 | #endif
85 |
--------------------------------------------------------------------------------
/lib_dsp/src/fft/dsp_long_short_conversion.S:
--------------------------------------------------------------------------------
1 | // Copyright 2016-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 |
4 | .section .dp.data,"awd",@progbits
5 | .text
6 |
7 | #if (defined(__XS2A__) || defined (__XS3A__))
8 | .cc_top dsp_fft_short_to_long_xs2.function
9 | .globl dsp_fft_short_to_long_xs2
10 | .align 4
11 | .type dsp_fft_short_to_long_xs2,@function
12 |
13 | #define NSTACKWORDS 4
14 |
15 | #define SHIFT 16
16 | //void dsp_fft_short_to_long( const dsp_complex_short_t s[], dsp_complex_t l[], uint32_t N );
17 |
18 | dsp_fft_short_to_long_xs2:
19 | .align 4
20 | .issue_mode dual
21 | DUALENTSP_lu6 2
22 | {mkmsk r11, 16;sub r2, r2, 1}
23 | std r5, r4, sp[0]
24 |
25 | .align 8
26 | .Ltmp_loop2:
27 | ldw r4, r0[r2]
28 | {andnot r4, r11; shl r3, r4, 16}
29 | std r4, r3, r1[r2]
30 | {bt r2, .Ltmp_loop2; sub r2, r2, 1}
31 |
32 | ldd r5, r4, sp[0]
33 | retsp 2
34 |
35 | .tmp_dsp_fft_short_to_long_xs2:
36 | .size dsp_fft_short_to_long_xs2, .tmp_dsp_fft_short_to_long_xs2-dsp_fft_short_to_long_xs2
37 | .align 4
38 | .cc_bottom dsp_fft_short_to_long_xs2.function
39 |
40 | .set dsp_fft_short_to_long_xs2.nstackwords,2
41 | .globl dsp_fft_short_to_long_xs2.nstackwords
42 | .set dsp_fft_short_to_long_xs2.maxcores,1
43 | .globl dsp_fft_short_to_long_xs2.maxcores
44 | .set dsp_fft_short_to_long_xs2.maxtimers,0
45 | .globl dsp_fft_short_to_long_xs2.maxtimers
46 | .set dsp_fft_short_to_long_xs2.maxchanends,0
47 | .globl dsp_fft_short_to_long_xs2.maxchanends
48 |
49 |
50 | .cc_top dsp_fft_long_to_short_xs2.function
51 | .globl dsp_fft_long_to_short_xs2
52 | .align 4
53 | .type dsp_fft_long_to_short_xs2,@function
54 |
55 | //void dsp_fft_long_to_short( const dsp_complex_t l[], dsp_complex_short_t s[], uint32_t N );
56 |
57 | dsp_fft_long_to_short_xs2:
58 | .align 8
59 | .issue_mode dual
60 | DUALENTSP_lu6 2
61 | {ldc r3, 16;sub r2, r2, 1}
62 | std r5, r4, sp[0]
63 | loop:
64 | ldd r5, r4, r0[r2]
65 | {linsert r5, r4, r4, r3, 32};
66 | stw r5, r1[r2]
67 | {bt r2, loop; sub r2, r2, 1;}
68 | ldd r5, r4, sp[0]
69 | retsp 2
70 |
71 | .tmp_dsp_fft_long_to_short_xs2:
72 | .size dsp_fft_long_to_short_xs2, .tmp_dsp_fft_long_to_short_xs2-dsp_fft_long_to_short_xs2
73 | .align 4
74 | .cc_bottom dsp_fft_long_to_short_xs2.function
75 |
76 | .set dsp_fft_long_to_short_xs2.nstackwords,2
77 | .globl dsp_fft_long_to_short_xs2.nstackwords
78 | .set dsp_fft_long_to_short_xs2.maxcores,1
79 | .globl dsp_fft_long_to_short_xs2.maxcores
80 | .set dsp_fft_long_to_short_xs2.maxtimers,0
81 | .globl dsp_fft_long_to_short_xs2.maxtimers
82 | .set dsp_fft_long_to_short_xs2.maxchanends,0
83 | .globl dsp_fft_long_to_short_xs2.maxchanends
84 |
85 | #endif
86 |
--------------------------------------------------------------------------------
/lib_dsp/src/float/dsp_filters_fp.c:
--------------------------------------------------------------------------------
1 | // Copyright 2019-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | #include
4 |
5 |
6 | double dsp_filters_biquad_fp
7 | (
8 | double input_sample,
9 | const double filter_coeffs[],
10 | double state_data[]
11 | ){
12 | return dsp_filters_biquads_fp(input_sample, filter_coeffs, state_data, 1);
13 | }
14 |
15 | double dsp_filters_biquads_fp
16 | (
17 | double input_sample,
18 | const double filter_coeffs[],
19 | double state_data[],
20 | const uint32_t num_sections
21 | ){
22 | double carry = input_sample;
23 |
24 | for(unsigned s=0;s=0; i--){
7 | r = (coefs[i] + (r*x));
8 | }
9 | return r;
10 | }
11 |
--------------------------------------------------------------------------------
/lib_dsp/src/gen/generate_butter.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019-2021 XMOS LIMITED.
2 | # This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | import numpy as np
4 | import matplotlib.pyplot as plt
5 | from scipy import signal
6 |
7 | # show = True
8 | # if show:
9 | # w, h = signal.freqz_zpk(z, p, k, fs=rate)
10 | # plt.plot(w,20*np.log10(abs(h)))
11 | # plt.show()
12 |
13 | def butter_highpass(cutoff, fs, order):
14 | nyq = 0.5 * fs
15 | normal_cutoff = cutoff / nyq
16 | z, p, k = signal.butter(order, normal_cutoff, output = 'zpk', btype='high', analog=False)
17 | return z, p, k
18 |
19 | def butter_lowpass(cutoff, fs, order):
20 | nyq = 0.5 * fs
21 | normal_cutoff = cutoff / nyq
22 | z, p, k = signal.butter(order, normal_cutoff, output = 'zpk', btype='low', analog=False)
23 | return z, p, k
24 |
25 |
26 | rate = 16000
27 | cut_offs = [100., 200., 500., 1000., 2000., 4000., 5000., 6000.]
28 | orders = [1, 2, 3, 4, 5, 6, 7, 8]
29 |
30 | for order in orders:
31 |
32 | print("int32_t filter"+str(order) + "[" + str(len(cut_offs)*2) + "] = {")
33 | for cut_off in cut_offs:
34 |
35 | z, p, k = butter_highpass(cut_off, rate, order = order)
36 |
37 | sos = signal.zpk2sos(z, p, k)
38 | max_coef = np.amax(abs(sos))
39 | q_format_str = 'Q'+str(31-int(np.ceil(np.log2(max_coef))))
40 |
41 | print("{")
42 | for section_index in range(sos.shape[0]):
43 | for coef_index in range(3):
44 | print(q_format_str + '(' +str(sos[section_index, coef_index]) + '),'),
45 | for coef_index in range(4, 6):
46 | print(q_format_str + '(' +str(-sos[section_index, coef_index]) + '),'),
47 | print
48 | print("},")
49 |
50 | z, p, k = butter_lowpass(cut_off, rate, order = order)
51 |
52 | sos = signal.zpk2sos(z, p, k)
53 | max_coef = np.amax(abs(sos))
54 | q_format_str = 'Q'+str(31-int(np.ceil(np.log2(max_coef))))
55 |
56 | print("{"),
57 | for section_index in range(sos.shape[0]):
58 | for coef_index in range(3):
59 | print(q_format_str + '(' +str(sos[section_index, coef_index]) + '),'),
60 | for coef_index in range(4, 6):
61 | print(q_format_str + '(' +str(-sos[section_index, coef_index]) + '),'),
62 | print
63 | print("},")
64 |
65 |
66 | print("};")
67 |
68 |
--------------------------------------------------------------------------------
/lib_dsp/src/gen/generate_window.py:
--------------------------------------------------------------------------------
1 | # Copyright 2015-2021 XMOS LIMITED.
2 | # This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | import sys
4 | import numpy as np
5 | from scipy import signal
6 | import argparse
7 |
8 | def parse_arguments():
9 | parser = argparse.ArgumentParser(description="Generates Q31 LUTs from scipy windows")
10 | parser.add_argument("-o", "--output-file", type=str)
11 | parser.add_argument("-f", "--function", type=str)
12 | parser.add_argument("-l", "--length", type=int)
13 | return parser.parse_args()
14 |
15 |
16 | def main():
17 | args = parse_arguments()
18 | if args.length % 2 != 0:
19 | print("Error: Length must be even")
20 | sys.exit(1)
21 |
22 | window = signal.windows.get_window(args.function, args.length)
23 |
24 | # Split the window in half, then scale it to Q31
25 |
26 | # Window is not quite half - oddity with scipy windows, middle value is 1 so a
27 | # window with even length is non-symmetric
28 | half_int_window = np.array(
29 | window[:(args.length//2)+1] * np.iinfo(np.int32).max, dtype=np.int32
30 | )
31 |
32 | # Create a C array
33 | c_window = (
34 | f"// LUT for {args.function} window, generated by lib_dsp generate_window.py\n"
35 | f"const int window[{len(half_int_window)}] = "
36 | f"{{ {', '.join([str(i) for i in half_int_window])} }};"
37 | )
38 |
39 | # Write back to output file
40 | with open(args.output_file, 'w') as f:
41 | f.write(c_window + "\n")
42 |
43 |
44 | if __name__ == "__main__":
45 | main()
46 |
--------------------------------------------------------------------------------
/lib_dsp/src/gen/generatesine.sh:
--------------------------------------------------------------------------------
1 | awk '
2 | BEGIN {
3 | header = "sine.h";
4 | impl = "sine.c";
5 | max_points = 2^12
6 | #note: Twos complement means that MIN_INT - 1 is MAX_INT !
7 | min_int = 2^31
8 | min_short_int = 2^15
9 |
10 |
11 | printf("#ifndef SINE_H_\n") > header;
12 | printf("#define SINE_H_\n")> header;
13 | for(j = 2; j < max_points; j = j * 2) {
14 | printf("extern const int lib_dsp_sine_%d[%d];\n", 4*j, j+1) > header;
15 | }
16 | printf("\n") > header;
17 |
18 | for(j = 2; j < max_points; j = j * 2) {
19 | printf("extern const short lib_dsp_sine_short_%d[%d];\n", 4*j, j+1) > header;
20 | }
21 | printf("#endif\n") > header;
22 |
23 |
24 | printf("// Copyright (c) 2015, XMOS Ltd, All rights reserved\n") > impl;
25 | printf("\n") > impl;
26 |
27 |
28 | for(j = 2; j < max_points; j = j * 2) {
29 | printf("const int lib_dsp_sine_%d[%d] = {\n ", 4*j, j+1) > impl;
30 | for(i = 0; i < j; i++) {
31 | printf(" %10d,", sin(i*3.1415926535/2/j) * min_int) > impl;
32 | if (i % 4 == 3) printf("\n ") > impl;
33 | }
34 | printf(" %10d,", 1 * min_int-1) > impl;
35 | printf("\n};\n\n") > impl;
36 | }
37 | for(j = 2; j < max_points; j = j * 2) {
38 | printf("const short lib_dsp_sine_short_%d[%d] = {\n ", 4*j, j+1) > impl;
39 | for(i = 0; i < j; i++) {
40 | printf(" %5d,", sin(i*3.1415926535/2/j) * min_short_int) > impl;
41 | if (i % 4 == 3) printf("\n ") > impl;
42 | }
43 | printf(" %5d,", 1 * min_short_int-1) > impl;
44 | printf("\n};\n\n") > impl;
45 |
46 | }
47 | }
48 | '
49 |
--------------------------------------------------------------------------------
/lib_dsp/src/logistics_table.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017-2021 XMOS LIMITED.
2 | # This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | import numpy as np
4 | import matplotlib.pyplot as plt
5 |
6 | def logistics(x):
7 | return 1.0/(1.0 + np.exp(-x))
8 |
9 | last = 0.5
10 | errors = [0.0,
11 | 0.02,
12 | 0.04,
13 | 0.05,
14 | 0.05,
15 | 0.05,
16 | 0.05,
17 | 0.05,
18 | 0.05]
19 | slopes = []
20 | offsets = []
21 | for i in range(1,9):
22 | value = float(i)
23 | end = logistics(value)
24 | if i != 8:
25 | error = errors[i] * (1-end)
26 | end += error
27 | else:
28 | error = 1.0 - end
29 | end = 1.0
30 | slope = end - last
31 | midpointerror = logistics(value + 0.5) - (end + slope/2.0)
32 | print error,last, slope, midpointerror
33 | offsets.append(int((1<<24) * (last-slope * (i-1))))
34 | slopes.append(int((1<<32) * slope))
35 | last = end
36 |
37 | out = ' .word '
38 | for i in slopes:
39 | out += str(i) + ','
40 |
41 | out += '\n .word '
42 | for i in offsets:
43 | out += str(i) + ','
44 |
45 | print out
46 |
47 | pts = []
48 | for i in range(0,100):
49 | value = float(i)/10.0
50 | inte = int(value)
51 | correct = logistics(value)
52 | if inte < 8:
53 | frac = value - inte
54 | y = offsets[inte]/float(1<<24) + slopes[inte]/float(1<<32) * value
55 | pts.append((correct,y))
56 | else:
57 | pts.append((correct,1.0))
58 |
59 | plt.figure()
60 | plt.plot(pts)
61 | plt.grid(True)
62 | plt.title('a')
63 | plt.show()
64 |
--------------------------------------------------------------------------------
/lib_dsp/src/poly_eval.c:
--------------------------------------------------------------------------------
1 | // Copyright 2019-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | #include
4 |
5 | int32_t dsp_poly_eval_impl_xs2
6 | (
7 | const int32_t x,
8 | const int32_t * coefs,
9 | const unsigned n_coefs
10 | );
11 |
12 | int32_t dsp_poly_eval
13 | (
14 | const int32_t x,
15 | const int32_t * coefs,
16 | const unsigned n_coefs
17 | ){
18 |
19 | #if (defined(__XS2A__) || defined (__XS3A__))
20 | return dsp_poly_eval_impl_xs2(x, coefs, n_coefs);
21 | #else
22 | int32_t r = coefs[n_coefs-1];
23 | for(int i = n_coefs-2; i>=0; i--){
24 | r = (coefs[i] + (((int64_t)r*(int64_t)x)>>31));
25 | }
26 | return r;
27 | #endif
28 | }
29 |
--------------------------------------------------------------------------------
/lib_dsp/src/testing/crc32_c.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2019-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | #include
4 | #include
5 |
6 | void crc32_c(unsigned &checksum, unsigned data, unsigned poly){
7 | crc32(checksum, data, poly);
8 | }
9 |
--------------------------------------------------------------------------------
/lib_dsp/src/testing/dsp_testing_rand.c:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | #include
4 | #include
5 |
6 | #include
7 |
8 |
9 | // usnigned crc32_c(unsigned, unsigned, unsigned)
10 | /*
11 | * Random number generation
12 | */
13 |
14 | void crc32_c(unsigned *checksum, unsigned data, unsigned poly);
15 |
16 | #define CRC_POLY (0xEB31D82E)
17 |
18 | int8_t dsp_pseudo_rand_int8(unsigned *r){
19 | crc32_c(r, -1, CRC_POLY);
20 | return (int8_t)*r;
21 | }
22 |
23 | uint8_t dsp_pseudo_rand_uint8(unsigned *r){
24 | crc32_c(r, -1, CRC_POLY);
25 | return (uint8_t)*r;
26 | }
27 |
28 | int16_t dsp_pseudo_rand_int16(unsigned *r){
29 | crc32_c(r, -1, CRC_POLY);
30 | return (int16_t)*r;
31 | }
32 |
33 | uint16_t dsp_pseudo_rand_uint16(unsigned *r){
34 | crc32_c(r, -1, CRC_POLY);
35 | return (uint16_t)*r;
36 | }
37 |
38 | int32_t dsp_pseudo_rand_int32(unsigned *r){
39 | crc32_c(r, -1, CRC_POLY);
40 | return (int32_t)*r;
41 | }
42 |
43 | uint32_t dsp_pseudo_rand_uint32(unsigned *r){
44 | crc32_c(r, -1, CRC_POLY);
45 | return (uint32_t)*r;
46 | }
47 |
48 | int64_t dsp_pseudo_rand_int64(unsigned *r){
49 | crc32_c(r, -1, CRC_POLY);
50 | int64_t a = (int64_t)*r;
51 | crc32_c(r, -1, CRC_POLY);
52 | int64_t b = (int64_t)*r;
53 | return (int64_t)(a + (b<<32));
54 | }
55 |
56 | uint64_t dsp_pseudo_rand_uint64(unsigned *r){
57 | crc32_c(r, -1, CRC_POLY);
58 | int64_t a = (int64_t)*r;
59 | crc32_c(r, -1, CRC_POLY);
60 | int64_t b = (int64_t)*r;
61 | return (uint64_t)(a + (b<<32));
62 | }
63 |
64 | dsp_float_t dsp_pseudo_rand_float(unsigned *r){
65 | return (dsp_float_t)dsp_pseudo_rand_int64(r);
66 | }
67 |
68 | dsp_complex_int16_t dsp_pseudo_rand_complex_int16(unsigned *r){
69 | dsp_complex_int16_t v;
70 | v.re = dsp_pseudo_rand_int16(r);
71 | v.im = dsp_pseudo_rand_int16(r);
72 | return v;
73 | }
74 |
75 | dsp_complex_int32_t dsp_pseudo_rand_complex_int32(unsigned *r){
76 | dsp_complex_int32_t v;
77 | v.re = dsp_pseudo_rand_int32(r);
78 | v.im = dsp_pseudo_rand_int32(r);
79 | return v;
80 | }
81 |
82 | dsp_complex_float_t dsp_pseudo_rand_complex_float(unsigned *r){
83 | dsp_complex_float_t v;
84 | v.re = dsp_pseudo_rand_float(r);
85 | v.im = dsp_pseudo_rand_float(r);
86 | return v;
87 | }
88 |
89 | dsp_ch_pair_int16_t dsp_pseudo_rand_ch_pair_int16(unsigned *r){
90 | dsp_ch_pair_int16_t v;
91 | v.ch_a = dsp_pseudo_rand_int16(r);
92 | v.ch_b = dsp_pseudo_rand_int16(r);
93 | return v;
94 | }
95 |
96 | dsp_ch_pair_int32_t dsp_pseudo_rand_ch_pair_int32(unsigned *r){
97 | dsp_ch_pair_int32_t v;
98 | v.ch_a = dsp_pseudo_rand_int32(r);
99 | v.ch_b = dsp_pseudo_rand_int32(r);
100 | return v;
101 | }
102 |
103 | dsp_ch_pair_float_t dsp_pseudo_rand_ch_pair_float(unsigned *r){
104 | dsp_ch_pair_float_t v;
105 | v.ch_a = dsp_pseudo_rand_float(r);
106 | v.ch_b = dsp_pseudo_rand_float(r);
107 | return v;
108 | }
109 |
--------------------------------------------------------------------------------
/python/setup.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020-2024 XMOS LIMITED.
2 | # This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | import setuptools
4 |
5 | # Another repository might depend on python code defined in this one. The
6 | # procedure to set up a suitable python environment for that repository may
7 | # pip-install this one as editable using this setup.py file. To minimise the
8 | # chance of version conflicts while ensuring a minimal degree of conformity,
9 | # the 3rd-party modules listed here require the same major version and at
10 | # least the same minor version as specified in the requirements.txt file.
11 | # The same modules should appear in the requirements.txt file as given below.
12 | setuptools.setup(
13 | name='lib_dsp',
14 | packages=setuptools.find_packages(),
15 | install_requires=[
16 | "flake8~=3.8",
17 | "matplotlib~=3.3",
18 | "numpy~=1.18",
19 | "pylint~=2.5",
20 | "pytest~=6.0",
21 | "pytest-xdist~=1.34",
22 | "scipy~=1.4",
23 | ],
24 |
25 | dependency_links=[
26 | './../lib_logging#egg=lib_logging',
27 | ],
28 | )
29 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | # python_version 3.7.6
2 | # pip_version 20.*
3 | #
4 | # The parse_version_from_requirements() function in the installPipfile.groovy
5 | # file of the Jenkins Shared Library uses the python_version comment to set
6 | # the version of python used.
7 |
8 | # Distributed (released) dependencies
9 | #
10 | # The python modules listed below specify a known working combination required
11 | # by the python code in this repository. The procedure used to set up a
12 | # suitable python environment for it installs the version of each module in
13 | # the list. Using a specific version ensures a controlled infrastructure for
14 | # development, testing and release of this repository.
15 | #
16 | # Another repository might depend on python code defined in this one. The
17 | # procedure to set up a suitable python environment for that repository may
18 | # pip-install this one as editable using this repository's setup.py file. The
19 | # same modules should appear in the setup.py list as given below.
20 | flake8==3.8.3
21 | # Pin importlib-metadata to <5 due to https://github.com/python/importlib_metadata/issues/409.
22 | importlib-metadata==4.13.0
23 | matplotlib==3.3.1
24 |
25 | # Pin numpy to 1.18.5 due to tensorflow v2.1.1 hard pinning it to that version.
26 | numpy==1.18.5
27 | pylint==2.5.3
28 | pytest==6.0.0
29 | pytest-xdist==1.34.0
30 |
31 | # Pin scipy to 1.4.1 due to tensorflow v2.1.1 hard pinning it to that version.
32 | scipy==1.4.1
33 |
34 | # Development dependencies
35 | #
36 | # Each link listed below specifies the path to a setup.py file which are
37 | # installed in editable mode with '-e $PATH' (without the quotes).
38 | #
39 | # If python code in this repository depends on python code under development
40 | # in another repository, then an entry for that other respository should
41 | # appear in this list instead of the released dependencies list.
42 | #
43 | # If this repository uses the setup functionality (e.g., script entry points)
44 | # of its own setup.py file, then this list must include an entry for that
45 | # setup.py file, e.g., '-e .' or '-e ./python' (without the quotes).
46 |
--------------------------------------------------------------------------------
/tests/adaptive_test.expect:
--------------------------------------------------------------------------------
1 | LMS 5
2 | +0.003133 +0.096867
3 | +0.009405 +0.090595
4 | +0.010949 +0.089051
5 | +0.012192 +0.087808
6 | +0.009736 +0.090264
7 | +0.009765 +0.090235
8 | +0.009793 +0.090207
9 | +0.009822 +0.090178
10 | +0.009851 +0.090149
11 | +0.009880 +0.090120
12 | +0.009909 +0.090091
13 | +0.009938 +0.090062
14 | +0.009966 +0.090034
15 | +0.009995 +0.090005
16 | +0.010024 +0.089976
17 | +0.010053 +0.089947
18 | +0.010082 +0.089918
19 | +0.010110 +0.089890
20 | +0.010139 +0.089861
21 | +0.010168 +0.089832
22 | +0.010197 +0.089803
23 | +0.010225 +0.089775
24 | +0.010254 +0.089746
25 | +0.010283 +0.089717
26 | +0.010312 +0.089688
27 | +0.010340 +0.089660
28 | +0.010369 +0.089631
29 | +0.010398 +0.089602
30 | +0.010426 +0.089574
31 | +0.010455 +0.089545
32 | +0.010484 +0.089516
33 | +0.010512 +0.089488
34 | +0.010541 +0.089459
35 | +0.010570 +0.089430
36 | +0.010598 +0.089402
37 |
38 | Normalized LMS 5
39 | +0.003133 +0.096867
40 | +0.010367 +0.089633
41 | +0.012796 +0.087204
42 | +0.014894 +0.085106
43 | +0.013266 +0.086734
44 | +0.014134 +0.085866
45 | +0.014992 +0.085008
46 | +0.015842 +0.084158
47 | +0.016684 +0.083316
48 | +0.017517 +0.082483
49 | +0.018342 +0.081658
50 | +0.019159 +0.080841
51 | +0.019967 +0.080033
52 | +0.020767 +0.079233
53 | +0.021560 +0.078440
54 | +0.022344 +0.077656
55 | +0.023121 +0.076879
56 | +0.023889 +0.076111
57 | +0.024651 +0.075349
58 | +0.025404 +0.074596
59 | +0.026150 +0.073850
60 | +0.026888 +0.073112
61 | +0.027620 +0.072380
62 | +0.028343 +0.071657
63 | +0.029060 +0.070940
64 | +0.029769 +0.070231
65 | +0.030472 +0.069528
66 | +0.031167 +0.068833
67 | +0.031855 +0.068145
68 | +0.032537 +0.067463
69 | +0.033211 +0.066789
70 | +0.033879 +0.066121
71 | +0.034540 +0.065460
72 | +0.035195 +0.064805
73 | +0.035843 +0.064157
74 |
--------------------------------------------------------------------------------
/tests/bfp_test.expect:
--------------------------------------------------------------------------------
1 | dsp_bfp_clz() passed
2 | dsp_bfp_...(..., 2, ...) passed
3 | dsp_bfp_...(..., 4, ...) passed
4 | dsp_bfp_...(..., 8, ...) passed
5 | dsp_bfp_...(..., 16, ...) passed
6 | dsp_bfp_...(..., 32, ...) passed
7 | dsp_bfp_...(..., 64, ...) passed
8 |
--------------------------------------------------------------------------------
/tests/complex_fir_test.expect:
--------------------------------------------------------------------------------
1 | -15025, 10887 -15025,10887
2 | PASS
3 |
--------------------------------------------------------------------------------
/tests/complex_test.expect:
--------------------------------------------------------------------------------
1 | Vector complex length 3 pass
2 | Vector complex length 4 pass
3 | Vector complex length 5 pass
4 | Combined Complex Array = 1, 10, 2, 20, 3, 30, 4, 40, 5, 50, 6, 60, 7, 70, 8, 80, 9, 90, 10, 100, 11, 110, 12, 120,
5 | Split arrays (real) = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
6 | (imag) = 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120,
7 |
--------------------------------------------------------------------------------
/tests/design_test.expect:
--------------------------------------------------------------------------------
1 | Impulse response of notch , +0.58574980, +0.00000000, +0.48529395, +0.00000000, -0.08322771, +0.00000000, +0.01427352, +0.00000000,
2 | Impulse response of lowpass , +0.32142857, +0.64285713, +0.22959183, -0.18367347, -0.06559767, +0.05247814, +0.01874219, -0.01499375,
3 | Impulse response of highpass , +0.29287490, -0.58574980, +0.24264698, +0.10045585, -0.04161385, -0.01722813, +0.00713676, +0.00295462,
4 | Impulse response of allpass , +0.17149958, +0.00000000, +0.97058789, +0.00000000, -0.16645541, +0.00000000, +0.02854703, +0.00000000,
5 | Impulse response of bandpass , +0.49385133, +0.06137681, -0.96985737, -0.18064277, +0.92734140, +0.29215727, -0.87184580, -0.39446755,
6 | Impulse response of peaking , +1.15390074, +0.00000000, -0.19297346, +0.00000000, +0.04899254, +0.00000000, -0.01243834, +0.00000000,
7 | Impulse response of lowshelf , +1.18850219, +0.22258205, +0.02084252, -0.01744701, -0.00345022, +0.00119748, +0.00041283, -0.00006571,
8 | Impulse response of highshelf, +1.18850219, -0.22258205, +0.02084252, +0.01744701, -0.00345022, -0.00119748, +0.00041283, +0.00006571,
9 |
--------------------------------------------------------------------------------
/tests/dsp_unit_tests/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | dsp_unit_tests
4 |
5 |
6 |
7 |
8 |
9 | com.xmos.cdt.core.LegacyProjectCheckerBuilder
10 |
11 |
12 |
13 |
14 | com.xmos.cdt.core.ModulePathBuilder
15 |
16 |
17 |
18 |
19 | com.xmos.cdt.core.ProjectInfoSyncBuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
25 | clean,full,incremental,
26 |
27 |
28 |
29 |
30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
31 | full,incremental,
32 |
33 |
34 |
35 |
36 |
37 | org.eclipse.cdt.core.cnature
38 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
39 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
40 | com.xmos.cdt.core.XdeProjectNature
41 |
42 |
43 |
--------------------------------------------------------------------------------
/tests/dsp_unit_tests/config.xscope:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/tests/dsp_unit_tests/src/fft.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Free FFT and convolution (C)
3 | *
4 | * Copyright (c) 2018 Project Nayuki. (MIT License)
5 | * https://www.nayuki.io/page/free-small-fft-in-multiple-languages
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | * - The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | * - The Software is provided "as is", without warranty of any kind, express or
16 | * implied, including but not limited to the warranties of merchantability,
17 | * fitness for a particular purpose and noninfringement. In no event shall the
18 | * authors or copyright holders be liable for any claim, damages or other
19 | * liability, whether in an action of contract, tort or otherwise, arising from,
20 | * out of or in connection with the Software or the use or other dealings in the
21 | * Software.
22 | */
23 |
24 | #include
25 | #include
26 |
27 |
28 | /*
29 | * Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
30 | * The vector can have any length. This is a wrapper function. Returns true if successful, false otherwise (out of memory).
31 | */
32 | int Fft_transform(double real[], double imag[], size_t n);
33 |
34 |
35 | /*
36 | * Computes the inverse discrete Fourier transform (IDFT) of the given complex vector, storing the result back into the vector.
37 | * The vector can have any length. This is a wrapper function.
38 | * Returns true if successful, false otherwise (out of memory).
39 | */
40 | int Fft_inverseTransform(double real[], double imag[], size_t n);
41 |
42 |
--------------------------------------------------------------------------------
/tests/dsp_unit_tests/src/test_poly_eval.c:
--------------------------------------------------------------------------------
1 | // Copyright 2019-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | #include "unity.h"
4 |
5 | #include
6 | #include
7 | #include
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 |
16 | #define MAX_LEN 32
17 | void test_poly_eval(){
18 | unsigned rand_seed = 11;
19 |
20 | const unsigned n_coefs_7 = 8;
21 | const int coefs_exp = -31;
22 | const int32_t coefs_7_rev[] = {2147483647, 1488522224, 515882292, 119192660, 20649056,
23 | 2851237, 316192, 23243, };
24 | double coefs_7_rev_fp[MAX_LEN];
25 |
26 | for(unsigned i=0;i0) x=-x;
35 |
36 | int error = 0;
37 | double x_fp = dsp_conv_int32_to_float(x, exp, &error);
38 | int32_t y = dsp_poly_eval(x, coefs_7_rev, n_coefs_7);
39 |
40 | double y_fp = dsp_poly_eval_fp(x_fp, coefs_7_rev_fp, n_coefs_7);
41 |
42 | int32_t expected = dsp_conv_float_to_int32(y_fp, coefs_exp, &error);
43 |
44 | TEST_ASSERT_FALSE_MESSAGE(error, "Conversion error");
45 |
46 | TEST_ASSERT_INT32_WITHIN_MESSAGE(4, expected, y, "Output not close enough");
47 | }
48 |
49 | }
50 |
51 |
--------------------------------------------------------------------------------
/tests/fft_real_single_test.expect:
--------------------------------------------------------------------------------
1 | Real FFT forward and backwards: PASS
2 |
--------------------------------------------------------------------------------
/tests/gen_test.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # Copyright 2016-2021 XMOS LIMITED.
3 | # This Software is subject to the terms of the XMOS Public Licence: Version 1.
4 |
5 | import argparse
6 | import os.path
7 | import numpy
8 | import ctypes
9 | import datetime
10 |
11 | ###############################################################################
12 |
13 | def parseArguments():
14 | parser = argparse.ArgumentParser(description="FFT result builder")
15 |
16 | parser.add_argument('--length_log2', type=int, default=3,
17 | help='Length of the FFT log 2')
18 |
19 | parser.add_argument('--storage', type=int, default=180,
20 | help='Space avaliable for fft results in memory (kB)')
21 |
22 | parser.add_argument('--shift', type=int, default=1,
23 | help='The shift applied to the input to the fft to scale the inputs to avoid overflow')
24 |
25 | parser.add_argument('--seed', type=int, default=1380144756,
26 | help='The seed of the crc32')
27 |
28 | args = parser.parse_args()
29 |
30 | return args
31 |
32 | ###############################################################################
33 |
34 | def crc32(d, x, poly):
35 | crc = d
36 | data = x
37 | for bit in range(32):
38 | xorBit = (crc & 1)
39 | crc = ((crc >> 1) & 0x7fffffff) | ((data & 1) << 31)
40 | data = (data >> 1) & 0x7fffffff
41 | if (xorBit != 0):
42 | crc = crc ^ poly
43 | return crc
44 |
45 |
46 |
47 | ###############################################################################
48 |
49 | def generate(storage, length_log2, shift, seed, directory):
50 | header = open (os.path.join(directory, "generated.h"), 'w')
51 |
52 | year = datetime.datetime.now().year
53 | header.write("// Copyright (c) " +str(year) +", XMOS Ltd, All rights reserved\n")
54 |
55 | fft_length = 1<>shift
74 | data = crc32(data, -1, poly)
75 | im = ctypes.c_int32(data).value>>shift
76 | fft_input.append(complex(re, im))
77 |
78 | sp = numpy.fft.fft(fft_input)
79 | header.write( "{\n")
80 | for i in range(fft_length):
81 | re = int(sp[i].real/fft_length)
82 | im = int(sp[i].imag/fft_length)
83 | header.write( "{" + str(re)+", " + str(im) + "},\n")
84 | header.write( "},\n")
85 | header.write( "};\n")
86 | return
87 |
88 | if __name__ == "__main__":
89 | args = parseArguments()
90 | generate(args.storage, args.length_log2, args.shift, args.seed, '.');
91 |
92 |
93 |
--------------------------------------------------------------------------------
/tests/hann_test.expect:
--------------------------------------------------------------------------------
1 | Pass
2 |
--------------------------------------------------------------------------------
/tests/matrix_test.expect:
--------------------------------------------------------------------------------
1 | Matrix multiplication: R = X * Y
2 | Input column vector X[2] (30 degrees from x axis):
3 | 0.86602539
4 | 0.50000000
5 | Result of multiplying column vector X[2] with rotation matrix Y[2][2] (90 degrees rotation):
6 | -0.49999994
7 | 0.86602545
8 |
9 | Matrix negation: R = -X
10 | -0.110000, -0.120000, -0.130000
11 | -0.210000, -0.220000, -0.230000
12 | -0.310000, -0.320000, -0.330000
13 |
14 | Matrix / scalar addition: R = X + a
15 | 2.110000, 2.120000, 2.130000
16 | 2.210000, 2.220000, 2.230000
17 | 2.310000, 2.320000, 2.330000
18 |
19 | Matrix / scalar multiplication: R = X + a
20 | 0.220000, 0.240000, 0.260000
21 | 0.420000, 0.440000, 0.460000
22 | 0.620000, 0.640000, 0.660000
23 |
24 | Matrix / matrix addition: R = X + Y
25 | 0.520000, 0.540000, 0.560000
26 | 0.720000, 0.740000, 0.760000
27 | 0.920000, 0.940000, 0.960000
28 |
29 | Matrix / matrix subtraction: R = X - Y
30 | -0.300000, -0.300000, -0.300000
31 | -0.300000, -0.300000, -0.300000
32 | -0.300000, -0.300000, -0.300000
33 |
34 | Matrix transposition
35 | 0.110000, 0.210000, 0.310000
36 | 0.120000, 0.220000, 0.320000
37 | 0.130000, 0.230000, 0.330000
38 |
39 |
40 |
--------------------------------------------------------------------------------
/tests/measure_fft_performance.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # Copyright 2016-2021 XMOS LIMITED.
3 | # This Software is subject to the terms of the XMOS Public Licence: Version 1.
4 | import xmostest
5 | import sys
6 | sys.path.insert(0, 'test_fft_correctness/src')
7 | import gen_test
8 | import shutil
9 | import os.path
10 | import random
11 | import tempfile
12 |
13 | def do_fft_test(length_log2, testlevel, test_dir_name, test_name):
14 |
15 | seed = random.randrange(4294967294);
16 |
17 | directory_name = tempfile.mkdtemp(prefix='temp_fft_dir_', dir='.')
18 |
19 | source_directory = os.path.join(directory_name, 'src')
20 |
21 | os.mkdir(source_directory)
22 |
23 | gen_test.generate(180, length_log2, 1, seed, source_directory)
24 | shutil.copy(os.path.join(test_dir_name,'src','test.xc'), source_directory)
25 | shutil.copy(os.path.join(test_dir_name,'Makefile'), directory_name)
26 |
27 | resources = xmostest.request_resource("xsim")
28 |
29 | binary = os.path.join(directory_name, 'bin', 'test.xe')
30 |
31 | # tester = DeletyComparisonTester(open(test_dir_name + '.expect'),
32 | # 'lib_dsp',
33 | # 'fft_performance_tests',
34 | # test_name, directory_name,
35 | # {'FFT length':(1<
2 |
3 | test_biquad
4 |
5 |
6 |
7 |
8 |
9 | com.xmos.cdt.core.LegacyProjectCheckerBuilder
10 |
11 |
12 |
13 |
14 | com.xmos.cdt.core.ProjectInfoSyncBuilder
15 |
16 |
17 |
18 |
19 | com.xmos.cdt.core.ModulePathBuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
25 | clean,full,incremental,
26 |
27 |
28 |
29 |
30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
31 | full,incremental,
32 |
33 |
34 |
35 |
36 |
37 | org.eclipse.cdt.core.cnature
38 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
39 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
40 | com.xmos.cdt.core.XdeProjectNature
41 |
42 |
43 |
--------------------------------------------------------------------------------
/tests/test_biquad/config.xscope:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/tests/test_biquad/src/iir.h:
--------------------------------------------------------------------------------
1 | // Copyright 2019-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | #include "dsp.h"
4 | #define IIR_ORDERS 8
5 | #define MAX_BIQUAD_ORDER 4
6 | #define IIRS_PER_ORDER 16
7 | extern unsigned biquad_orders[IIR_ORDERS][IIRS_PER_ORDER];
8 | extern int32_t filter[IIR_ORDERS][IIRS_PER_ORDER][DSP_NUM_COEFFS_PER_BIQUAD*MAX_BIQUAD_ORDER];
9 | extern unsigned q_factors[IIR_ORDERS][IIRS_PER_ORDER];
10 |
--------------------------------------------------------------------------------
/tests/test_biquad/src/test_biquad.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | #include "unity.h"
4 |
5 | #include
6 | #include
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #include "iir.h"
14 |
15 | {double, double} biquad_measure(unsigned order, const int q_format, int32_t * filter_coeffs){
16 |
17 | unsafe {
18 | double filter_coeffs_fp[MAX_BIQUAD_ORDER*DSP_NUM_COEFFS_PER_BIQUAD];
19 | for(unsigned s=0;s>1;
41 | int error = 0;
42 | dsp_float_t x_fp = dsp_conv_int32_to_float(x, x_exp, (int * unsafe) &error);
43 | TEST_ASSERT_FALSE_MESSAGE(error, "Conversion error");
44 |
45 | int32_t y = dsp_filters_biquads(x, filter_coeffs, state_data, order, q_format);
46 | double y_fp = dsp_filters_biquads_fp(x_fp, filter_coeffs_fp, state_data_fp, order);
47 |
48 | for(unsigned i=0;i=4.0.0)
13 |
14 | # The flags passed to xcc when building the application
15 | # You can also set the following to override flags for a particular language:
16 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
17 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
18 | # xcc for the final link (mapping) stage.
19 | XCC_FLAGS = -O2 -g -report -DDEBUG_PRINT_ENABLE=1
20 |
21 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
22 | # project to create both xCORE and ARM binaries.
23 | XCORE_ARM_PROJECT = 0
24 |
25 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
26 | VERBOSE = 0
27 |
28 | XMOS_MAKE_PATH ?= ../..
29 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
30 |
--------------------------------------------------------------------------------
/tests/test_fft_forward/config.xscope:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/tests/test_fft_forward/src/test.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2016-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include "dsp_fft.h"
9 | #include "generated.h"
10 |
11 | int random(unsigned &x){
12 | crc32(x, -1, 0xEB31D82E);
13 | return (int)x;
14 | }
15 |
16 | void test_forward_fft(){
17 | unsigned x=SEED;
18 |
19 | unsigned max_error = 0;
20 | unsigned average_error = 0;
21 | unsigned test_count = 2;
22 |
23 | for(unsigned t=0;t>DATA_SHIFT;
28 | f[i].im = random(x)>>DATA_SHIFT;
29 | }
30 | dsp_fft_bit_reverse(f, FFT_LENGTH);
31 | dsp_fft_forward(f, FFT_LENGTH, FFT_SINE_LUT);
32 |
33 | for(unsigned i=0;i FFT_LENGTH * 4){
37 | printf("Error: error in forward FFT (real)\n");
38 | _Exit(1);
39 | }
40 | average_error += e;
41 | if(e > max_error)
42 | max_error = e;
43 | e = f[i].im - output[t][i].im;
44 | if (e<0) e=-e;
45 | if(e > FFT_LENGTH * 4){
46 | printf("Error: error in forward FFT (imaginary)\n");
47 | _Exit(1);
48 | }
49 | average_error += e;
50 | if(e > max_error)
51 | max_error = e;
52 | }
53 | }
54 | printf("Forward FFT: Pass.\n");
55 | }
56 |
57 | unsafe int main(){
58 | test_forward_fft();
59 | _Exit(0);
60 | return 0;
61 | }
62 |
--------------------------------------------------------------------------------
/tests/test_fft_forward/wscript:
--------------------------------------------------------------------------------
1 | def configure(conf):
2 | conf.load('xwaf.compiler_xcc')
3 |
4 |
5 | def build(bld):
6 | bld.env.TARGET_ARCH = 'XCORE-200-EXPLORER'
7 | bld.env.XCC_FLAGS = ['-O2', '-g', '-report', '-DDEBUG_PRINT_ENABLE=1']
8 |
9 | # Build our program
10 | prog = bld.program(target='bin/test.xe', depends_on='lib_dsp(>=4.0.0)')
11 |
--------------------------------------------------------------------------------
/tests/test_fft_forward_real/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS = -O2 -g -report -DDEBUG_PRINT_ENABLE=1
2 |
3 | XCOREAI ?= 0
4 | ifeq ($(XCOREAI),1)
5 | # Xcore.ai Builds
6 | # Use `xmake XCOREAI=1`
7 |
8 | # The TARGET variable determines what target system the application is
9 | # compiled for. It either refers to an XN file in the source directories
10 | # or a valid argument for the --target option when compiling
11 | TARGET = XCORE-AI-EXPLORER
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
16 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
17 | # xcc for the final link (mapping) stage.
18 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
19 |
20 | else
21 | # Xcore-200 Builds
22 | # Use `xmake`
23 | TARGET = XCORE-200-EXPLORER
24 | XCC_FLAGS = $(BUILD_FLAGS)
25 | endif
26 |
27 | # The APP_NAME variable determines the name of the final .xe file. It should
28 | # not include the .xe postfix. If left blank the name will default to
29 | # the project name
30 | APP_NAME = test
31 |
32 | # The USED_MODULES variable lists other modules used by the application.
33 | USED_MODULES = lib_dsp(>=6.0.0)
34 |
35 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
36 | # project to create both xCORE and ARM binaries.
37 | XCORE_ARM_PROJECT = 0
38 |
39 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
40 | VERBOSE = 0
41 |
42 | XMOS_MAKE_PATH ?= ../..
43 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
44 |
--------------------------------------------------------------------------------
/tests/test_fft_forward_real/config.xscope:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/tests/test_fft_forward_real/src/test.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2016-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #include "dsp_fft.h"
10 |
11 | int random(unsigned &x){
12 | crc32(x, -1, 0xEB31D82E);
13 | return (int)x;
14 | }
15 |
16 | #define FFT_LENGTH 16
17 | #define ONE 65536
18 |
19 | void test_linear() {
20 | dsp_complex_t f[FFT_LENGTH];
21 | int32_t sig[FFT_LENGTH*3/2+4] = {0, 7071, 10000, 7071, 0, -7071, -10000, -7071, 0, 7071, 10000, 7071, 0, -7071, -10000, -7071};
22 | dsp_complex_t conv[FFT_LENGTH] = {{ONE,0},{ONE,0},{ONE,0},{ONE,0},{0,0},{0,0},{0,0},{0,0}};
23 | for(int i = 0; i < FFT_LENGTH * 3/2; i++) {
24 | sig[i] = sin(6.283 / 10 * i) * 10000;
25 | }
26 | dsp_fft_bit_reverse(conv, FFT_LENGTH);
27 | dsp_fft_forward(conv, FFT_LENGTH, dsp_sine_8);
28 | for(int j = 0; j < FFT_LENGTH; j += FFT_LENGTH/2) {
29 | for(unsigned i=0;i>16;
45 | f[i].im = ((re0*im1 + im0*re1)*FFT_LENGTH)>>16;
46 | }
47 | dsp_fft_bit_reverse(f, FFT_LENGTH);
48 | dsp_fft_inverse(f, FFT_LENGTH, dsp_sine_8);
49 | for(unsigned i=0;i t0;
68 | dsp_fft_bit_reverse(f, FFT_LENGTH);
69 | dsp_fft_forward(f, FFT_LENGTH, dsp_sine_16);
70 | tmr :> t1;
71 | dsp_fft_bit_reverse_and_forward_real(sig, FFT_LENGTH, dsp_sine_8, dsp_sine_16);
72 | tmr :> t2;
73 |
74 | printf("%d for normal vs %d for fast\n", t1-t0, t2-t1);
75 | printf("%6d,%6d %6d,%6d\n", f[0].re, f[0].im, sig[0], 0);
76 | for(unsigned i=1;i=4.0.0)
13 |
14 | # The flags passed to xcc when building the application
15 | # You can also set the following to override flags for a particular language:
16 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
17 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
18 | # xcc for the final link (mapping) stage.
19 | XCC_FLAGS = -O2 -g -report -DDEBUG_PRINT_ENABLE=1
20 |
21 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
22 | # project to create both xCORE and ARM binaries.
23 | XCORE_ARM_PROJECT = 0
24 |
25 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
26 | VERBOSE = 0
27 |
28 | XMOS_MAKE_PATH ?= ../..
29 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
30 |
--------------------------------------------------------------------------------
/tests/test_fft_index_bit_reverse/config.xscope:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/tests/test_fft_index_bit_reverse/src/test.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2016-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include "dsp_fft.h"
9 | #include "generated.h"
10 |
11 | int random(unsigned &x){
12 | crc32(x, -1, 0xEB31D82E);
13 | return (int)x;
14 | }
15 |
16 | void test_index_bit_reverse(){
17 | dsp_complex_t f[FFT_LENGTH];
18 | for(unsigned i=0;i>(clz(FFT_LENGTH)+1);
27 | if(f[i].re != j){
28 | printf("Error: error in bit reverse (real)\n");
29 | _Exit(1);
30 | }
31 | if(f[i].im != j+FFT_LENGTH){
32 | printf("Error: error in bit reverse (imaginary)\n");
33 | _Exit(1);
34 | }
35 | }
36 | printf("Bit reverse: Pass.\n");
37 | }
38 |
39 | unsafe int main(){
40 | test_index_bit_reverse();
41 | _Exit(0);
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/tests/test_fft_index_bit_reverse/wscript:
--------------------------------------------------------------------------------
1 | def configure(conf):
2 | conf.load('xwaf.compiler_xcc')
3 |
4 |
5 | def build(bld):
6 | bld.env.TARGET_ARCH = 'XCORE-200-EXPLORER'
7 | bld.env.XCC_FLAGS = ['-O2', '-g', '-report', '-DDEBUG_PRINT_ENABLE=1']
8 |
9 | # Build our program
10 | prog = bld.program(target='bin/test.xe', depends_on='lib_dsp(>=4.0.0)')
11 |
--------------------------------------------------------------------------------
/tests/test_fft_inverse.expect:
--------------------------------------------------------------------------------
1 | Inverse FFT: Pass.
2 |
--------------------------------------------------------------------------------
/tests/test_fft_inverse/Makefile:
--------------------------------------------------------------------------------
1 | # The TARGET variable determines what target system the application is
2 | # compiled for. It either refers to an XN file in the source directories
3 | # or a valid argument for the --target option when compiling
4 | TARGET = XCORE-200-EXPLORER
5 |
6 | # The APP_NAME variable determines the name of the final .xe file. It should
7 | # not include the .xe postfix. If left blank the name will default to
8 | # the project name
9 | APP_NAME = test
10 |
11 | # The USED_MODULES variable lists other modules used by the application.
12 | USED_MODULES = lib_dsp(>=4.0.0)
13 |
14 | # The flags passed to xcc when building the application
15 | # You can also set the following to override flags for a particular language:
16 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
17 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
18 | # xcc for the final link (mapping) stage.
19 | XCC_FLAGS = -O2 -g -report -DDEBUG_PRINT_ENABLE=1
20 |
21 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
22 | # project to create both xCORE and ARM binaries.
23 | XCORE_ARM_PROJECT = 0
24 |
25 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
26 | VERBOSE = 0
27 |
28 | XMOS_MAKE_PATH ?= ../..
29 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
30 |
--------------------------------------------------------------------------------
/tests/test_fft_inverse/config.xscope:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/tests/test_fft_inverse/src/test.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2016-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include "dsp_fft.h"
9 | #include "generated.h"
10 |
11 | int random(unsigned &x){
12 | crc32(x, -1, 0xEB31D82E);
13 | return (int)x;
14 | }
15 |
16 | void test_inverse_fft(){
17 | unsigned x=SEED;
18 | unsigned test_count = 2;
19 | unsigned max_error = 0;
20 | unsigned average_error = 0;
21 | for(unsigned t=0;t>DATA_SHIFT;
34 | int im = random(x)>>DATA_SHIFT;
35 |
36 | int e = f[i].re - re;
37 | if (e<0) e=-e;
38 | if(e > FFT_LENGTH * 4){
39 | printf("Error: error in inverse FFT (real)\n");
40 | _Exit(1);
41 | }
42 | average_error += e;
43 | if(e > max_error)
44 | max_error = e;
45 | e = f[i].im - im;
46 | if (e<0) e=-e;
47 | if(e > FFT_LENGTH * 4){
48 | printf("Error: error in inverse FFT (imaginary)\n");
49 | _Exit(1);
50 | }
51 | average_error += e;
52 | if(e > max_error)
53 | max_error = e;
54 | }
55 | }
56 | printf("Inverse FFT: Pass.\n");
57 | }
58 |
59 |
60 | unsafe int main(){
61 | test_inverse_fft();
62 | _Exit(0);
63 | return 0;
64 | }
65 |
--------------------------------------------------------------------------------
/tests/test_fft_inverse/wscript:
--------------------------------------------------------------------------------
1 | def configure(conf):
2 | conf.load('xwaf.compiler_xcc')
3 |
4 |
5 | def build(bld):
6 | bld.env.TARGET_ARCH = 'XCORE-200-EXPLORER'
7 | bld.env.XCC_FLAGS = ['-O2', '-g', '-report', '-DDEBUG_PRINT_ENABLE=1']
8 |
9 | # Build our program
10 | prog = bld.program(target='bin/test.xe', depends_on='lib_dsp(>=4.0.0)')
11 |
--------------------------------------------------------------------------------
/tests/test_fft_inverse_blank_forward.expect:
--------------------------------------------------------------------------------
1 | test FFT inverse blank forward PASS
2 |
--------------------------------------------------------------------------------
/tests/test_fft_inverse_blank_forward/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_FLAGS = -O2 -g -report -DDEBUG_PRINT_ENABLE=1
2 |
3 | XCOREAI ?= 0
4 | ifeq ($(XCOREAI),1)
5 | # Xcore.ai Builds
6 | # Use `xmake XCOREAI=1`
7 |
8 | # The TARGET variable determines what target system the application is
9 | # compiled for. It either refers to an XN file in the source directories
10 | # or a valid argument for the --target option when compiling
11 | TARGET = XCORE-AI-EXPLORER
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
16 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
17 | # xcc for the final link (mapping) stage.
18 | XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
19 |
20 | else
21 | # Xcore-200 Builds
22 | # Use `xmake`
23 | TARGET = XCORE-200-EXPLORER
24 | XCC_FLAGS = $(BUILD_FLAGS)
25 | endif
26 |
27 | # The APP_NAME variable determines the name of the final .xe file. It should
28 | # not include the .xe postfix. If left blank the name will default to
29 | # the project name
30 | APP_NAME = test
31 |
32 | # The USED_MODULES variable lists other modules used by the application.
33 | USED_MODULES = lib_dsp(>=6.0.0)
34 |
35 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
36 | # project to create both xCORE and ARM binaries.
37 | XCORE_ARM_PROJECT = 0
38 |
39 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
40 | VERBOSE = 0
41 |
42 | XMOS_MAKE_PATH ?= ../..
43 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
44 |
--------------------------------------------------------------------------------
/tests/test_fft_inverse_blank_forward/config.xscope:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/tests/test_fft_inverse_blank_forward/src/test.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2016-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #include "dsp_fft.h"
11 |
12 | #define M 3
13 | #define FFT_LENGTH 512
14 | #define FFT_SI dsp_sine_512
15 |
16 | int random(unsigned &x){
17 | crc32(x, -1, 0xEB31D82E);
18 | return (int)x;
19 | }
20 |
21 | extern void dsp_fft_zero_reverse_forward(dsp_complex_t f[], int l,
22 | const int32_t sine[]);
23 | extern void dsp_fft_inverse_xs2(dsp_complex_t f[], int l,
24 | const int32_t sine[]);
25 |
26 | void gc1( dsp_complex_t g[FFT_LENGTH]) {
27 | timer tmr;
28 | int r0, r1;
29 | tmr:>r0;
30 | dsp_fft_bit_reverse(g, FFT_LENGTH);
31 | dsp_fft_inverse_xs2(g, FFT_LENGTH, FFT_SI);
32 | dsp_fft_zero_reverse_forward(g, FFT_LENGTH, FFT_SI);
33 | tmr:>r1;
34 | // printf("%d ticks for integrated\n", r1-r0);
35 | }
36 |
37 | void gc2( dsp_complex_t g[FFT_LENGTH]) {
38 | timer tmr;
39 | int r0, r1;
40 | tmr:>r0;
41 | dsp_fft_bit_reverse(g, FFT_LENGTH);
42 | dsp_fft_inverse_xs2(g, FFT_LENGTH, FFT_SI);
43 | for(int i = FFT_LENGTH/2; i < FFT_LENGTH; i++) {
44 | g[i].re = 0;
45 | g[i].im = 0;
46 | }
47 | dsp_fft_bit_reverse(g, FFT_LENGTH);
48 | dsp_fft_forward(g, FFT_LENGTH, FFT_SI);
49 | tmr:>r1;
50 | // printf("%d ticks for separate\n", r1-r0);
51 | }
52 |
53 | dsp_complex_t f[FFT_LENGTH], g[FFT_LENGTH];
54 |
55 | int main(void) {
56 | int error = 0;
57 | for(int i = 0; i < FFT_LENGTH; i++) {
58 | g[i].re = f[i].re = i*i-1000;
59 | g[i].im = f[i].im = 1000-i;
60 | }
61 | gc1(f);
62 | gc2(g);
63 | for(int i = 0; i < FFT_LENGTH; i++) {
64 | if (g[i].re != f[i].re) {
65 | printf("%d: re %08x not %08x\n", i, g[i].re, f[i].re);
66 | error++;
67 | }
68 | if (g[i].im != f[i].im) {
69 | printf("%d: im %08x not %08x\n", i, g[i].im, f[i].im);
70 | error++;
71 | }
72 | }
73 | if (error == 0) {
74 | printf("test FFT inverse blank forward PASS\n");
75 | } else {
76 | printf("test FFT inverse blank forward failure count: %d\n");
77 | }
78 | return 0;
79 | }
80 |
--------------------------------------------------------------------------------
/tests/test_fft_inverse_blank_forward/wscript:
--------------------------------------------------------------------------------
1 | def options(opt):
2 | opt.load('xwaf.xcommon')
3 |
4 | def configure(conf):
5 | conf.load('xwaf.xcommon')
6 |
7 | def build(bld):
8 | bld.do_xcommon()
9 |
10 | def dist(ctx):
11 | ctx.load('xwaf.xcommon')
12 |
13 | def distcheck(ctx):
14 | ctx.load('xwaf.xcommon')
15 |
--------------------------------------------------------------------------------
/tests/test_fft_performance/Makefile:
--------------------------------------------------------------------------------
1 | # The TARGET variable determines what target system the application is
2 | # compiled for. It either refers to an XN file in the source directories
3 | # or a valid argument for the --target option when compiling
4 | TARGET = XCORE-200-EXPLORER
5 |
6 | # The APP_NAME variable determines the name of the final .xe file. It should
7 | # not include the .xe postfix. If left blank the name will default to
8 | # the project name
9 | APP_NAME = test
10 |
11 | # The USED_MODULES variable lists other modules used by the application.
12 | USED_MODULES = lib_dsp(>=4.0.0)
13 |
14 | # The flags passed to xcc when building the application
15 | # You can also set the following to override flags for a particular language:
16 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
17 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
18 | # xcc for the final link (mapping) stage.
19 | XCC_FLAGS = -O2 -g -report -DDEBUG_PRINT_ENABLE=1
20 |
21 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
22 | # project to create both xCORE and ARM binaries.
23 | XCORE_ARM_PROJECT = 0
24 |
25 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
26 | VERBOSE = 0
27 |
28 | XMOS_MAKE_PATH ?= ../..
29 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
30 |
--------------------------------------------------------------------------------
/tests/test_fft_performance/config.xscope:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/tests/test_fft_performance/src/test.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2016-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include "dsp_fft.h"
9 | #include "generated.h"
10 |
11 | #define PRINT_STATS 0
12 |
13 | int random(unsigned &x){
14 | crc32(x, -1, 0xEB31D82E);
15 | return (int)x;
16 | }
17 |
18 |
19 |
20 | void test_forward_speed(){
21 | unsigned x=SEED;
22 |
23 | //unsigned reps = 1<<16;
24 | unsigned reps = 1;
25 | unsigned now, then;
26 | timer t;
27 |
28 | dsp_complex_t f[FFT_LENGTH];
29 | for(unsigned i=0;i then;
35 | for(unsigned t=0;t now;
38 |
39 | printf("Time for one forward FFT(%d points): %.2f ns\n", FFT_LENGTH, (float)(now - then)*8.0 / (float)reps);
40 | }
41 |
42 | void test_inverse_speed(){
43 | unsigned x=SEED;
44 |
45 | //unsigned reps = 1<<16;
46 | unsigned reps = 1;
47 | unsigned now, then;
48 | timer t;
49 |
50 | dsp_complex_t f[FFT_LENGTH];
51 | for(unsigned i=0;i then;
57 | for(unsigned t=0;t now;
60 |
61 | printf("Time for one inverse FFT(%d points): %.2f ns\n", FFT_LENGTH, (float)(now - then)*8.0 / (float)reps);
62 | }
63 |
64 |
65 | unsafe int main(){
66 | test_forward_speed();
67 | test_inverse_speed();
68 | _Exit(0);
69 | return 0;
70 | }
71 |
--------------------------------------------------------------------------------
/tests/test_fft_performance/wscript:
--------------------------------------------------------------------------------
1 | def configure(conf):
2 | conf.load('xwaf.compiler_xcc')
3 |
4 |
5 | def build(bld):
6 | bld.env.TARGET_ARCH = 'XCORE-200-EXPLORER'
7 | bld.env.XCC_FLAGS = ['-O2', '-g', '-report', '-DDEBUG_PRINT_ENABLE=1']
8 |
9 | # Build our program
10 | prog = bld.program(target='bin/test.xe', depends_on='lib_dsp(>=4.0.0)')
11 |
--------------------------------------------------------------------------------
/tests/test_fft_real_single.py:
--------------------------------------------------------------------------------
1 | # Copyright 2015-2021 XMOS LIMITED.
2 | # This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | import xmostest
4 |
5 | def runtest():
6 | resources = xmostest.request_resource("xsim")
7 |
8 | tester = xmostest.ComparisonTester(open('fft_real_single_test.expect'),
9 | 'lib_dsp', 'simple_tests',
10 | 'app_fft_real_single', {})
11 |
12 | xmostest.run_on_simulator(resources['xsim'],
13 | '../AN00209_xCORE-200_DSP_Library/app_fft_real_single/bin/app_fft_real_single.xe',
14 | tester=tester, timeout=1200)
15 |
--------------------------------------------------------------------------------
/tests/test_fft_short_long.expect:
--------------------------------------------------------------------------------
1 | Long to short conversion: Pass.
2 | Short to long conversion: Pass.
3 |
--------------------------------------------------------------------------------
/tests/test_fft_short_long/Makefile:
--------------------------------------------------------------------------------
1 | # The TARGET variable determines what target system the application is
2 | # compiled for. It either refers to an XN file in the source directories
3 | # or a valid argument for the --target option when compiling
4 | TARGET = XCORE-200-EXPLORER
5 |
6 | # The APP_NAME variable determines the name of the final .xe file. It should
7 | # not include the .xe postfix. If left blank the name will default to
8 | # the project name
9 | APP_NAME = test
10 |
11 | # The USED_MODULES variable lists other modules used by the application.
12 | USED_MODULES = lib_dsp(>=4.0.0)
13 |
14 | # The flags passed to xcc when building the application
15 | # You can also set the following to override flags for a particular language:
16 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
17 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
18 | # xcc for the final link (mapping) stage.
19 | XCC_FLAGS = -O2 -g -report -DDEBUG_PRINT_ENABLE=1
20 |
21 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
22 | # project to create both xCORE and ARM binaries.
23 | XCORE_ARM_PROJECT = 0
24 |
25 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
26 | VERBOSE = 0
27 |
28 | XMOS_MAKE_PATH ?= ../..
29 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
30 |
--------------------------------------------------------------------------------
/tests/test_fft_short_long/config.xscope:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/tests/test_fft_short_long/src/test.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2016-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include "dsp_fft.h"
9 | #include "generated.h"
10 |
11 | int random(unsigned &x){
12 | crc32(x, -1, 0xEB31D82E);
13 | return (int)x;
14 | }
15 |
16 | void test_short_long_conversion(){
17 | unsigned x=SEED;
18 | dsp_complex_t f[FFT_LENGTH];
19 | dsp_complex_t g[FFT_LENGTH];
20 | dsp_complex_short_t h[FFT_LENGTH];
21 |
22 | for(unsigned i=0; i < FFT_LENGTH; i++){
23 | f[i].re = random(x);
24 | f[i].im = random(x);
25 | g[i].re = f[i].re;
26 | g[i].im = f[i].im;
27 | h[i].re = 0;
28 | h[i].im = 0;
29 | }
30 |
31 | dsp_fft_long_to_short(f, h, FFT_LENGTH);
32 |
33 | for(unsigned i=0; i < FFT_LENGTH; i++){
34 | if((f[i].re>>16) != h[i].re){
35 | printf("Error in long to short(real)\n");
36 | _Exit(1);
37 | }
38 | if((f[i].im>>16) != h[i].im){
39 | printf("Error in long to short(imaginary)\n");
40 | _Exit(1);
41 | }
42 | }
43 | printf("Long to short conversion: Pass.\n");
44 |
45 | for(unsigned i=0; i < FFT_LENGTH; i++){
46 | f[i].re = 0;
47 | f[i].im = 0;
48 | }
49 |
50 | dsp_fft_short_to_long(h, f, FFT_LENGTH);
51 |
52 | for(unsigned i=0; i < FFT_LENGTH; i++){
53 | if(f[i].re != (g[i].re&0xffff0000)){
54 | printf("Error in short to long(real)\n");
55 | _Exit(1);
56 | }
57 | if(f[i].im != (g[i].im&0xffff0000)){
58 | printf("Error in short to long(imaginary)\n");
59 | _Exit(1);
60 | }
61 | }
62 |
63 | printf("Short to long conversion: Pass.\n");
64 | }
65 |
66 | unsafe int main(){
67 | test_short_long_conversion();
68 | _Exit(0);
69 | return 0;
70 | }
71 |
--------------------------------------------------------------------------------
/tests/test_fft_short_long/wscript:
--------------------------------------------------------------------------------
1 | def configure(conf):
2 | conf.load('xwaf.compiler_xcc')
3 |
4 |
5 | def build(bld):
6 | bld.env.TARGET_ARCH = 'XCORE-200-EXPLORER'
7 | bld.env.XCC_FLAGS = ['-O2', '-g', '-report', '-DDEBUG_PRINT_ENABLE=1']
8 |
9 | # Build our program
10 | prog = bld.program(target='bin/test.xe', depends_on='lib_dsp(>=4.0.0)')
11 |
--------------------------------------------------------------------------------
/tests/test_fft_split_and_merge.expect:
--------------------------------------------------------------------------------
1 | Split spectrum: Pass.
2 | Merge spectra: Pass.
3 |
--------------------------------------------------------------------------------
/tests/test_fft_split_and_merge/Makefile:
--------------------------------------------------------------------------------
1 | # The TARGET variable determines what target system the application is
2 | # compiled for. It either refers to an XN file in the source directories
3 | # or a valid argument for the --target option when compiling
4 | TARGET = XCORE-200-EXPLORER
5 |
6 | # The APP_NAME variable determines the name of the final .xe file. It should
7 | # not include the .xe postfix. If left blank the name will default to
8 | # the project name
9 | APP_NAME = test
10 |
11 | # The USED_MODULES variable lists other modules used by the application.
12 | USED_MODULES = lib_dsp(>=4.0.0)
13 |
14 | # The flags passed to xcc when building the application
15 | # You can also set the following to override flags for a particular language:
16 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
17 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
18 | # xcc for the final link (mapping) stage.
19 | XCC_FLAGS = -O2 -g -report -DDEBUG_PRINT_ENABLE=1
20 |
21 | # The XCORE_ARM_PROJECT variable, if set to 1, configures this
22 | # project to create both xCORE and ARM binaries.
23 | XCORE_ARM_PROJECT = 0
24 |
25 | # The VERBOSE variable, if set to 1, enables verbose output from the make system.
26 | VERBOSE = 0
27 |
28 | XMOS_MAKE_PATH ?= ../..
29 | -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
30 |
--------------------------------------------------------------------------------
/tests/test_fft_split_and_merge/config.xscope:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/tests/test_fft_split_and_merge/src/test.xc:
--------------------------------------------------------------------------------
1 | // Copyright 2016-2021 XMOS LIMITED.
2 | // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include "dsp_fft.h"
9 | #include "generated.h"
10 |
11 | int random(unsigned &x){
12 | crc32(x, -1, 0xEB31D82E);
13 | return (int)x;
14 | }
15 |
16 | void test_split_and_merge(){
17 | unsigned x=SEED;
18 | dsp_complex_t f[FFT_LENGTH];
19 | dsp_complex_t g[FFT_LENGTH];
20 | unsigned test_count = 2;
21 | for(unsigned i=0;i>DATA_SHIFT;
24 | f[i].im = 0;
25 | g[i].re = f[i].re;
26 | g[i].im = f[i].im;
27 | }
28 |
29 | dsp_fft_forward(f, FFT_LENGTH, FFT_SINE_LUT);
30 | dsp_fft_forward(g, FFT_LENGTH, FFT_SINE_LUT);
31 |
32 | dsp_fft_split_spectrum(f, FFT_LENGTH);
33 |
34 | for(unsigned i=1;i FFT_LENGTH_LOG2){
38 | printf("Error: error in split spectrum operation(real)\n");
39 | _Exit(1);
40 | }
41 | e = g[i].im - f[i].im;
42 | if (e<0) e=-e;
43 | if(e > FFT_LENGTH_LOG2){
44 | printf("Error: error in split spectrum operation(imaginary)\n");
45 | _Exit(1);
46 | }
47 | }
48 | for(unsigned i=FFT_LENGTH/2 ;i FFT_LENGTH_LOG2){
52 | printf("Error: error in split spectrum operation(real)\n");
53 | _Exit(1);
54 | }
55 | e = 0 - f[i].im;
56 | if (e<0) e=-e;
57 | if(e > FFT_LENGTH_LOG2){
58 | printf("Error: error in split spectrum operation(imaginary)\n");
59 | _Exit(1);
60 | }
61 | }
62 | }
63 | printf("Split spectrum: Pass.\n");
64 |
65 | unsigned average_error = 0;
66 | //Merge spectrum is correct iff it is the inverse of the split operation.
67 | for(unsigned i=0;i>DATA_SHIFT;
70 | f[i].im = random(x)>>DATA_SHIFT;
71 | g[i].re = f[i].re;
72 | g[i].im = f[i].im;
73 | }
74 |
75 | dsp_fft_split_spectrum(f, FFT_LENGTH);
76 | dsp_fft_merge_spectra(f, FFT_LENGTH);
77 |
78 | for(unsigned i=0; i < FFT_LENGTH; i++){
79 | int e = g[i].re - f[i].re;
80 | if (e<0) e=-e;
81 | average_error += e;
82 | if(e > 1){
83 | printf("Error: error in merge spectrum operation(real)\n");
84 | _Exit(1);
85 | }
86 | e = g[i].im - f[i].im;
87 | if (e<0) e=-e;
88 | average_error += e;
89 |
90 | if(e > 1){
91 | printf("Error: error in merge spectrum operation(imaginary)\n");
92 | _Exit(1);
93 | }
94 | }
95 | }
96 | printf("Merge spectra: Pass.\n");
97 | }
98 |
99 | unsafe int main(){
100 | test_split_and_merge();
101 | _Exit(0);
102 | return 0;
103 | }
104 |
--------------------------------------------------------------------------------
/tests/test_fft_split_and_merge/wscript:
--------------------------------------------------------------------------------
1 | def configure(conf):
2 | conf.load('xwaf.compiler_xcc')
3 |
4 |
5 | def build(bld):
6 | bld.env.TARGET_ARCH = 'XCORE-200-EXPLORER'
7 | bld.env.XCC_FLAGS = ['-O2', '-g', '-report', '-DDEBUG_PRINT_ENABLE=1']
8 |
9 | # Build our program
10 | prog = bld.program(target='bin/test.xe', depends_on='lib_dsp(>=4.0.0)')
11 |
--------------------------------------------------------------------------------
/tests/test_filters.py:
--------------------------------------------------------------------------------
1 | # Copyright 2015-2021 XMOS LIMITED.
2 | # This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | import xmostest
4 |
5 | def runtest():
6 | resources = xmostest.request_resource("xsim")
7 |
8 | tester = xmostest.ComparisonTester(open('filters_test.expect'),
9 | 'lib_dsp', 'simple_tests',
10 | 'app_filters', {})
11 |
12 | xmostest.run_on_simulator(resources['xsim'],
13 | '../AN00209_xCORE-200_DSP_Library/app_filters/bin/app_filters.xe',
14 | tester=tester)
15 |
--------------------------------------------------------------------------------
/tests/test_hann.py:
--------------------------------------------------------------------------------
1 | # Copyright 2015-2021 XMOS LIMITED.
2 | # This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | import xmostest
4 |
5 | def runtest():
6 | resources = xmostest.request_resource("xsim")
7 |
8 | tester = xmostest.ComparisonTester(open('hann_test.expect'),
9 | 'lib_dsp', 'simple_tests',
10 | 'app_window_post_fft', {})
11 |
12 | xmostest.run_on_simulator(resources['xsim'],
13 | '../AN00209_xCORE-200_DSP_Library/app_window_post_fft/bin/app_window_post_fft.xe',
14 | tester=tester, timeout=1200)
15 |
--------------------------------------------------------------------------------
/tests/test_math.py:
--------------------------------------------------------------------------------
1 | # Copyright 2015-2021 XMOS LIMITED.
2 | # This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | import xmostest
4 |
5 | def runtest():
6 | resources = xmostest.request_resource("xsim")
7 |
8 | tester = xmostest.ComparisonTester(open('math_test.expect'),
9 | 'lib_dsp', 'simple_tests',
10 | 'app_math', {})
11 |
12 | xmostest.run_on_simulator(resources['xsim'],
13 | '../AN00209_xCORE-200_DSP_Library/app_math/bin/app_math.xe',
14 | tester=tester, timeout=1200)
15 |
--------------------------------------------------------------------------------
/tests/test_matrix.py:
--------------------------------------------------------------------------------
1 | # Copyright 2015-2021 XMOS LIMITED.
2 | # This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | import xmostest
4 |
5 | def runtest():
6 | resources = xmostest.request_resource("xsim")
7 |
8 | tester = xmostest.ComparisonTester(open('matrix_test.expect'),
9 | 'lib_dsp', 'simple_tests',
10 | 'app_matrix', {})
11 |
12 | xmostest.run_on_simulator(resources['xsim'],
13 | '../AN00209_xCORE-200_DSP_Library/app_matrix/bin/app_matrix.xe',
14 | tester=tester)
15 |
--------------------------------------------------------------------------------
/tests/test_statistics.py:
--------------------------------------------------------------------------------
1 | # Copyright 2015-2021 XMOS LIMITED.
2 | # This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | import xmostest
4 |
5 | def runtest():
6 | resources = xmostest.request_resource("xsim")
7 |
8 | tester = xmostest.ComparisonTester(open('statistics_test.expect'),
9 | 'lib_dsp', 'simple_tests',
10 | 'app_statistics', {})
11 |
12 | xmostest.run_on_simulator(resources['xsim'],
13 | '../AN00209_xCORE-200_DSP_Library/app_statistics/bin/app_statistics.xe',
14 | tester=tester)
15 |
--------------------------------------------------------------------------------
/tests/test_vector.py:
--------------------------------------------------------------------------------
1 | # Copyright 2015-2021 XMOS LIMITED.
2 | # This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 | import xmostest
4 |
5 | def runtest():
6 | resources = xmostest.request_resource("xsim")
7 |
8 | tester = xmostest.ComparisonTester(open('vector_test.expect'),
9 | 'lib_dsp', 'simple_tests',
10 | 'app_vector', {})
11 |
12 | xmostest.run_on_simulator(resources['xsim'],
13 | '../AN00209_xCORE-200_DSP_Library/app_vector/bin/app_vector.xe',
14 | tester=tester)
15 |
--------------------------------------------------------------------------------
/tests/vector_test.expect:
--------------------------------------------------------------------------------
1 | Minimum location = 0
2 | Minimum = 0.110000
3 | Maximum location = 49
4 | Maximum = 0.600000
5 | Vector Negate Result
6 | Dst[0] = -0.110000
7 | Dst[1] = 0.120000
8 | Dst[2] = 0
9 | Dst[3] = -2147483647
10 | Dst[4] = 2147483647
11 | Vector Absolute Result
12 | Dst[0] = 0.110000
13 | Dst[1] = 0.120000
14 | Dst[2] = 0
15 | Dst[3] = 2147483647
16 | Dst[4] = 2147483647
17 | Vector / scalar addition Result
18 | Dst[0] = 2.110000
19 | Dst[1] = 2.120000
20 | Dst[2] = 2.130000
21 | Dst[3] = 2.140000
22 | Dst[4] = 2.150000
23 | Vector / scalar multiplication Result
24 | Dst[0] = 0.220000
25 | Dst[1] = 0.240000
26 | Dst[2] = 0.260000
27 | Dst[3] = 0.280000
28 | Dst[4] = 0.300000
29 | Vector / vector addition Result
30 | Dst[0] = 0.620000
31 | Dst[1] = 0.640000
32 | Dst[2] = 0.660000
33 | Dst[3] = 0.680000
34 | Dst[4] = 0.700000
35 | Vector / vector subtraction Result
36 | Dst[0] = -0.400000
37 | Dst[1] = -0.400000
38 | Dst[2] = -0.400000
39 | Dst[3] = -0.400000
40 | Dst[4] = -0.400000
41 | Vector / vector multiplication Result
42 | Dst[0] = 0.056100
43 | Dst[1] = 0.062400
44 | Dst[2] = 0.068900
45 | Dst[3] = 0.075600
46 | Dst[4] = 0.082500
47 | Vector multiplication and scalar addition Result
48 | Dst[0] = 2.056100
49 | Dst[1] = 2.062400
50 | Dst[2] = 2.068900
51 | Dst[3] = 2.075600
52 | Dst[4] = 2.082500
53 | Vector / Scalar multiplication and vector addition Result
54 | Dst[0] = 0.730000
55 | Dst[1] = 0.760000
56 | Dst[2] = 0.790000
57 | Dst[3] = 0.820000
58 | Dst[4] = 0.850000
59 | Vector / Scalar multiplication and vector subtraction Result
60 | Dst[0] = -0.453900
61 | Dst[1] = -0.457600
62 | Dst[2] = -0.461100
63 | Dst[3] = -0.464400
64 | Dst[4] = -0.467500
65 | Vector / Vector multiplication and vector addition Result
66 | Dst[0] = 0.666100
67 | Dst[1] = 0.682400
68 | Dst[2] = 0.698900
69 | Dst[3] = 0.715600
70 | Dst[4] = 0.732500
71 | Vector / Vector multiplication and vector subtraction Result
72 | Dst[0] = -0.553900
73 | Dst[1] = -0.557600
74 | Dst[2] = -0.561100
75 | Dst[3] = -0.564400
76 | Dst[4] = -0.567500
77 | Complex vector / Vector multiplication Result
78 | C_real = -22.000000, -28.000000, -34.000000, -40.000000, -42.000000, -20.000000, -22.000000, -40.000000, -9.000000, -14.000000, -17.000000, -22.000000,
79 | C_imag = 20.000000, 36.000000, 56.000000, 80.000000, 76.000000, 20.000000, 20.000000, 60.000000, 17.000000, 48.000000, 65.000000, 104.000000,
80 |
--------------------------------------------------------------------------------