├── .gitignore ├── .pylintrc ├── .readthedocs.yml ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.rst ├── docs ├── _static │ └── favicon.ico ├── api.rst ├── conf.py ├── examples.rst └── index.rst ├── examples ├── fft_simpletest.py └── verification │ ├── README.md │ ├── cp_fft.py │ ├── cp_fft_verification_in_py3.py │ ├── cp_ifft.py │ └── cp_samples.py ├── requirements.txt ├── setup.py └── teaandtechtime_fft.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.mpy 2 | .idea 3 | __pycache__ 4 | _build 5 | *.pyc 6 | .env 7 | build* 8 | bundles 9 | *.DS_Store 10 | .eggs 11 | dist 12 | **/*.egg-info 13 | .vscode 14 | -------------------------------------------------------------------------------- /.pylintrc: -------------------------------------------------------------------------------- 1 | [MASTER] 2 | 3 | # A comma-separated list of package or module names from where C extensions may 4 | # be loaded. Extensions are loading into the active Python interpreter and may 5 | # run arbitrary code 6 | extension-pkg-whitelist= 7 | 8 | # Add files or directories to the blacklist. They should be base names, not 9 | # paths. 10 | ignore=CVS 11 | 12 | # Add files or directories matching the regex patterns to the blacklist. The 13 | # regex matches against base names, not paths. 14 | ignore-patterns= 15 | 16 | # Python code to execute, usually for sys.path manipulation such as 17 | # pygtk.require(). 18 | #init-hook= 19 | 20 | # Use multiple processes to speed up Pylint. 21 | # jobs=1 22 | jobs=2 23 | 24 | # List of plugins (as comma separated values of python modules names) to load, 25 | # usually to register additional checkers. 26 | load-plugins= 27 | 28 | # Pickle collected data for later comparisons. 29 | persistent=yes 30 | 31 | # Specify a configuration file. 32 | #rcfile= 33 | 34 | # Allow loading of arbitrary C extensions. Extensions are imported into the 35 | # active Python interpreter and may run arbitrary code. 36 | unsafe-load-any-extension=no 37 | 38 | 39 | [MESSAGES CONTROL] 40 | 41 | # Only show warnings with the listed confidence levels. Leave empty to show 42 | # all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED 43 | confidence= 44 | 45 | # Disable the message, report, category or checker with the given id(s). You 46 | # can either give multiple identifiers separated by comma (,) or put this 47 | # option multiple times (only on the command line, not in the configuration 48 | # file where it should appear only once).You can also use "--disable=all" to 49 | # disable everything first and then reenable specific checks. For example, if 50 | # you want to run only the similarities checker, you can use "--disable=all 51 | # --enable=similarities". If you want to run only the classes checker, but have 52 | # no Warning level messages displayed, use"--disable=all --enable=classes 53 | # --disable=W" 54 | # disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call 55 | disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error 56 | 57 | # Enable the message, report, category or checker with the given id(s). You can 58 | # either give multiple identifier separated by comma (,) or put this option 59 | # multiple time (only on the command line, not in the configuration file where 60 | # it should appear only once). See also the "--disable" option for examples. 61 | enable= 62 | 63 | 64 | [REPORTS] 65 | 66 | # Python expression which should return a note less than 10 (10 is the highest 67 | # note). You have access to the variables errors warning, statement which 68 | # respectively contain the number of errors / warnings messages and the total 69 | # number of statements analyzed. This is used by the global evaluation report 70 | # (RP0004). 71 | evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) 72 | 73 | # Template used to display messages. This is a python new-style format string 74 | # used to format the message information. See doc for all details 75 | #msg-template= 76 | 77 | # Set the output format. Available formats are text, parseable, colorized, json 78 | # and msvs (visual studio).You can also give a reporter class, eg 79 | # mypackage.mymodule.MyReporterClass. 80 | output-format=text 81 | 82 | # Tells whether to display a full report or only the messages 83 | reports=no 84 | 85 | # Activate the evaluation score. 86 | score=yes 87 | 88 | 89 | [REFACTORING] 90 | 91 | # Maximum number of nested blocks for function / method body 92 | max-nested-blocks=5 93 | 94 | 95 | [LOGGING] 96 | 97 | # Logging modules to check that the string format arguments are in logging 98 | # function parameter format 99 | logging-modules=logging 100 | 101 | 102 | [SPELLING] 103 | 104 | # Spelling dictionary name. Available dictionaries: none. To make it working 105 | # install python-enchant package. 106 | spelling-dict= 107 | 108 | # List of comma separated words that should not be checked. 109 | spelling-ignore-words= 110 | 111 | # A path to a file that contains private dictionary; one word per line. 112 | spelling-private-dict-file= 113 | 114 | # Tells whether to store unknown words to indicated private dictionary in 115 | # --spelling-private-dict-file option instead of raising a message. 116 | spelling-store-unknown-words=no 117 | 118 | 119 | [MISCELLANEOUS] 120 | 121 | # List of note tags to take in consideration, separated by a comma. 122 | # notes=FIXME,XXX,TODO 123 | notes=FIXME,XXX 124 | 125 | 126 | [TYPECHECK] 127 | 128 | # List of decorators that produce context managers, such as 129 | # contextlib.contextmanager. Add to this list to register other decorators that 130 | # produce valid context managers. 131 | contextmanager-decorators=contextlib.contextmanager 132 | 133 | # List of members which are set dynamically and missed by pylint inference 134 | # system, and so shouldn't trigger E1101 when accessed. Python regular 135 | # expressions are accepted. 136 | generated-members= 137 | 138 | # Tells whether missing members accessed in mixin class should be ignored. A 139 | # mixin class is detected if its name ends with "mixin" (case insensitive). 140 | ignore-mixin-members=yes 141 | 142 | # This flag controls whether pylint should warn about no-member and similar 143 | # checks whenever an opaque object is returned when inferring. The inference 144 | # can return multiple potential results while evaluating a Python object, but 145 | # some branches might not be evaluated, which results in partial inference. In 146 | # that case, it might be useful to still emit no-member and other checks for 147 | # the rest of the inferred objects. 148 | ignore-on-opaque-inference=yes 149 | 150 | # List of class names for which member attributes should not be checked (useful 151 | # for classes with dynamically set attributes). This supports the use of 152 | # qualified names. 153 | ignored-classes=optparse.Values,thread._local,_thread._local 154 | 155 | # List of module names for which member attributes should not be checked 156 | # (useful for modules/projects where namespaces are manipulated during runtime 157 | # and thus existing member attributes cannot be deduced by static analysis. It 158 | # supports qualified module names, as well as Unix pattern matching. 159 | ignored-modules=board 160 | 161 | # Show a hint with possible names when a member name was not found. The aspect 162 | # of finding the hint is based on edit distance. 163 | missing-member-hint=yes 164 | 165 | # The minimum edit distance a name should have in order to be considered a 166 | # similar match for a missing member name. 167 | missing-member-hint-distance=1 168 | 169 | # The total number of similar names that should be taken in consideration when 170 | # showing a hint for a missing member. 171 | missing-member-max-choices=1 172 | 173 | 174 | [VARIABLES] 175 | 176 | # List of additional names supposed to be defined in builtins. Remember that 177 | # you should avoid to define new builtins when possible. 178 | additional-builtins= 179 | 180 | # Tells whether unused global variables should be treated as a violation. 181 | allow-global-unused-variables=yes 182 | 183 | # List of strings which can identify a callback function by name. A callback 184 | # name must start or end with one of those strings. 185 | callbacks=cb_,_cb 186 | 187 | # A regular expression matching the name of dummy variables (i.e. expectedly 188 | # not used). 189 | dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ 190 | 191 | # Argument names that match this expression will be ignored. Default to name 192 | # with leading underscore 193 | ignored-argument-names=_.*|^ignored_|^unused_ 194 | 195 | # Tells whether we should check for unused import in __init__ files. 196 | init-import=no 197 | 198 | # List of qualified module names which can have objects that can redefine 199 | # builtins. 200 | redefining-builtins-modules=six.moves,future.builtins 201 | 202 | 203 | [FORMAT] 204 | 205 | # Expected format of line ending, e.g. empty (any line ending), LF or CRLF. 206 | # expected-line-ending-format= 207 | expected-line-ending-format=LF 208 | 209 | # Regexp for a line that is allowed to be longer than the limit. 210 | ignore-long-lines=^\s*(# )??$ 211 | 212 | # Number of spaces of indent required inside a hanging or continued line. 213 | indent-after-paren=4 214 | 215 | # String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 216 | # tab). 217 | indent-string=' ' 218 | 219 | # Maximum number of characters on a single line. 220 | max-line-length=100 221 | 222 | # Maximum number of lines in a module 223 | max-module-lines=1000 224 | 225 | # List of optional constructs for which whitespace checking is disabled. `dict- 226 | # separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. 227 | # `trailing-comma` allows a space between comma and closing bracket: (a, ). 228 | # `empty-line` allows space-only lines. 229 | no-space-check=trailing-comma,dict-separator 230 | 231 | # Allow the body of a class to be on the same line as the declaration if body 232 | # contains single statement. 233 | single-line-class-stmt=no 234 | 235 | # Allow the body of an if to be on the same line as the test if there is no 236 | # else. 237 | single-line-if-stmt=no 238 | 239 | 240 | [SIMILARITIES] 241 | 242 | # Ignore comments when computing similarities. 243 | ignore-comments=yes 244 | 245 | # Ignore docstrings when computing similarities. 246 | ignore-docstrings=yes 247 | 248 | # Ignore imports when computing similarities. 249 | ignore-imports=no 250 | 251 | # Minimum lines number of a similarity. 252 | min-similarity-lines=4 253 | 254 | 255 | [BASIC] 256 | 257 | # Naming hint for argument names 258 | argument-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ 259 | 260 | # Regular expression matching correct argument names 261 | argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ 262 | 263 | # Naming hint for attribute names 264 | attr-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ 265 | 266 | # Regular expression matching correct attribute names 267 | attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ 268 | 269 | # Bad variable names which should always be refused, separated by a comma 270 | bad-names=foo,bar,baz,toto,tutu,tata 271 | 272 | # Naming hint for class attribute names 273 | class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ 274 | 275 | # Regular expression matching correct class attribute names 276 | class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ 277 | 278 | # Naming hint for class names 279 | # class-name-hint=[A-Z_][a-zA-Z0-9]+$ 280 | class-name-hint=[A-Z_][a-zA-Z0-9_]+$ 281 | 282 | # Regular expression matching correct class names 283 | # class-rgx=[A-Z_][a-zA-Z0-9]+$ 284 | class-rgx=[A-Z_][a-zA-Z0-9_]+$ 285 | 286 | # Naming hint for constant names 287 | const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ 288 | 289 | # Regular expression matching correct constant names 290 | const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ 291 | 292 | # Minimum line length for functions/classes that require docstrings, shorter 293 | # ones are exempt. 294 | docstring-min-length=-1 295 | 296 | # Naming hint for function names 297 | function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ 298 | 299 | # Regular expression matching correct function names 300 | function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ 301 | 302 | # Good variable names which should always be accepted, separated by a comma 303 | # good-names=i,j,k,ex,Run,_ 304 | good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ 305 | 306 | # Include a hint for the correct naming format with invalid-name 307 | include-naming-hint=no 308 | 309 | # Naming hint for inline iteration names 310 | inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ 311 | 312 | # Regular expression matching correct inline iteration names 313 | inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ 314 | 315 | # Naming hint for method names 316 | method-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ 317 | 318 | # Regular expression matching correct method names 319 | method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ 320 | 321 | # Naming hint for module names 322 | module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ 323 | 324 | # Regular expression matching correct module names 325 | module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ 326 | 327 | # Colon-delimited sets of names that determine each other's naming style when 328 | # the name regexes allow several styles. 329 | name-group= 330 | 331 | # Regular expression which should only match function or class names that do 332 | # not require a docstring. 333 | no-docstring-rgx=^_ 334 | 335 | # List of decorators that produce properties, such as abc.abstractproperty. Add 336 | # to this list to register other decorators that produce valid properties. 337 | property-classes=abc.abstractproperty 338 | 339 | # Naming hint for variable names 340 | variable-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ 341 | 342 | # Regular expression matching correct variable names 343 | variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ 344 | 345 | 346 | [IMPORTS] 347 | 348 | # Allow wildcard imports from modules that define __all__. 349 | allow-wildcard-with-all=no 350 | 351 | # Analyse import fallback blocks. This can be used to support both Python 2 and 352 | # 3 compatible code, which means that the block might have code that exists 353 | # only in one or another interpreter, leading to false positives when analysed. 354 | analyse-fallback-blocks=no 355 | 356 | # Deprecated modules which should not be used, separated by a comma 357 | deprecated-modules=optparse,tkinter.tix 358 | 359 | # Create a graph of external dependencies in the given file (report RP0402 must 360 | # not be disabled) 361 | ext-import-graph= 362 | 363 | # Create a graph of every (i.e. internal and external) dependencies in the 364 | # given file (report RP0402 must not be disabled) 365 | import-graph= 366 | 367 | # Create a graph of internal dependencies in the given file (report RP0402 must 368 | # not be disabled) 369 | int-import-graph= 370 | 371 | # Force import order to recognize a module as part of the standard 372 | # compatibility libraries. 373 | known-standard-library= 374 | 375 | # Force import order to recognize a module as part of a third party library. 376 | known-third-party=enchant 377 | 378 | 379 | [CLASSES] 380 | 381 | # List of method names used to declare (i.e. assign) instance attributes. 382 | defining-attr-methods=__init__,__new__,setUp 383 | 384 | # List of member names, which should be excluded from the protected access 385 | # warning. 386 | exclude-protected=_asdict,_fields,_replace,_source,_make 387 | 388 | # List of valid names for the first argument in a class method. 389 | valid-classmethod-first-arg=cls 390 | 391 | # List of valid names for the first argument in a metaclass class method. 392 | valid-metaclass-classmethod-first-arg=mcs 393 | 394 | 395 | [DESIGN] 396 | 397 | # Maximum number of arguments for function / method 398 | max-args=5 399 | 400 | # Maximum number of attributes for a class (see R0902). 401 | # max-attributes=7 402 | max-attributes=11 403 | 404 | # Maximum number of boolean expressions in a if statement 405 | max-bool-expr=5 406 | 407 | # Maximum number of branch for function / method body 408 | max-branches=12 409 | 410 | # Maximum number of locals for function / method body 411 | max-locals=15 412 | 413 | # Maximum number of parents for a class (see R0901). 414 | max-parents=7 415 | 416 | # Maximum number of public methods for a class (see R0904). 417 | max-public-methods=20 418 | 419 | # Maximum number of return / yield for function / method body 420 | max-returns=6 421 | 422 | # Maximum number of statements in function / method body 423 | max-statements=50 424 | 425 | # Minimum number of public methods for a class (see R0903). 426 | min-public-methods=1 427 | 428 | 429 | [EXCEPTIONS] 430 | 431 | # Exceptions that will emit a warning when being caught. Defaults to 432 | # "Exception" 433 | overgeneral-exceptions=Exception 434 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | python: 2 | version: 3 3 | requirements_file: requirements.txt 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # This is a common .travis.yml for generating library release zip files for 2 | # CircuitPython library releases using circuitpython-build-tools. 3 | # See https://github.com/adafruit/circuitpython-build-tools for detailed setup 4 | # instructions. 5 | 6 | dist: xenial 7 | language: python 8 | python: 9 | - "3.6" 10 | 11 | cache: 12 | pip: true 13 | 14 | # TODO: if deployment to PyPi is desired, change 'DEPLOY_PYPI' to "true", 15 | # or remove the env block entirely and remove the condition in the 16 | # deploy block. 17 | env: 18 | - DEPLOY_PYPI="false" 19 | 20 | deploy: 21 | - provider: releases 22 | api_key: "$GITHUB_TOKEN" 23 | file_glob: true 24 | file: "$TRAVIS_BUILD_DIR/bundles/*" 25 | skip_cleanup: true 26 | overwrite: true 27 | on: 28 | tags: true 29 | # TODO: Use 'travis encrypt --com -r adafruit/' to generate 30 | # the encrypted password for adafruit-travis. Paste result below. 31 | - provider: pypi 32 | user: adafruit-travis 33 | password: 34 | secure: #-- PASTE ENCRYPTED PASSWORD HERE --# 35 | on: 36 | tags: true 37 | condition: $DEPLOY_PYPI = "true" 38 | 39 | install: 40 | - pip install -r requirements.txt 41 | - pip install circuitpython-build-tools Sphinx sphinx-rtd-theme 42 | - pip install --force-reinstall pylint==1.9.2 43 | 44 | script: 45 | - pylint teaandtechtime_fft.py 46 | - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py) 47 | - circuitpython-build-bundles --filename_prefix teaandtechtime-circuitpython-fft --library_location . 48 | - cd docs && sphinx-build -E -W -b html . _build/html && cd .. 49 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Adafruit Community Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and leaders pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level or type of 9 | experience, education, socio-economic status, nationality, personal appearance, 10 | race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | We are committed to providing a friendly, safe and welcoming environment for 15 | all. 16 | 17 | Examples of behavior that contributes to creating a positive environment 18 | include: 19 | 20 | * Be kind and courteous to others 21 | * Using welcoming and inclusive language 22 | * Being respectful of differing viewpoints and experiences 23 | * Collaborating with other community members 24 | * Gracefully accepting constructive criticism 25 | * Focusing on what is best for the community 26 | * Showing empathy towards other community members 27 | 28 | Examples of unacceptable behavior by participants include: 29 | 30 | * The use of sexualized language or imagery and sexual attention or advances 31 | * The use of inappropriate images, including in a community member's avatar 32 | * The use of inappropriate language, including in a community member's nickname 33 | * Any spamming, flaming, baiting or other attention-stealing behavior 34 | * Excessive or unwelcome helping; answering outside the scope of the question 35 | asked 36 | * Trolling, insulting/derogatory comments, and personal or political attacks 37 | * Public or private harassment 38 | * Publishing others' private information, such as a physical or electronic 39 | address, without explicit permission 40 | * Other conduct which could reasonably be considered inappropriate 41 | 42 | The goal of the standards and moderation guidelines outlined here is to build 43 | and maintain a respectful community. We ask that you don’t just aim to be 44 | "technically unimpeachable", but rather try to be your best self. 45 | 46 | We value many things beyond technical expertise, including collaboration and 47 | supporting others within our community. Providing a positive experience for 48 | other community members can have a much more significant impact than simply 49 | providing the correct answer. 50 | 51 | ## Our Responsibilities 52 | 53 | Project leaders are responsible for clarifying the standards of acceptable 54 | behavior and are expected to take appropriate and fair corrective action in 55 | response to any instances of unacceptable behavior. 56 | 57 | Project leaders have the right and responsibility to remove, edit, or 58 | reject messages, comments, commits, code, issues, and other contributions 59 | that are not aligned to this Code of Conduct, or to ban temporarily or 60 | permanently any community member for other behaviors that they deem 61 | inappropriate, threatening, offensive, or harmful. 62 | 63 | ## Moderation 64 | 65 | Instances of behaviors that violate the Adafruit Community Code of Conduct 66 | may be reported by any member of the community. Community members are 67 | encouraged to report these situations, including situations they witness 68 | involving other community members. 69 | 70 | You may report in the following ways: 71 | 72 | In any situation, you may send an email to . 73 | 74 | On the Adafruit Discord, you may send an open message from any channel 75 | to all Community Helpers by tagging @community moderators. You may also send an 76 | open message from any channel, or a direct message to @kattni#1507, 77 | @tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or 78 | @Andon#8175. 79 | 80 | Email and direct message reports will be kept confidential. 81 | 82 | In situations on Discord where the issue is particularly egregious, possibly 83 | illegal, requires immediate action, or violates the Discord terms of service, 84 | you should also report the message directly to Discord. 85 | 86 | These are the steps for upholding our community’s standards of conduct. 87 | 88 | 1. Any member of the community may report any situation that violates the 89 | Adafruit Community Code of Conduct. All reports will be reviewed and 90 | investigated. 91 | 2. If the behavior is an egregious violation, the community member who 92 | committed the violation may be banned immediately, without warning. 93 | 3. Otherwise, moderators will first respond to such behavior with a warning. 94 | 4. Moderators follow a soft "three strikes" policy - the community member may 95 | be given another chance, if they are receptive to the warning and change their 96 | behavior. 97 | 5. If the community member is unreceptive or unreasonable when warned by a 98 | moderator, or the warning goes unheeded, they may be banned for a first or 99 | second offense. Repeated offenses will result in the community member being 100 | banned. 101 | 102 | ## Scope 103 | 104 | This Code of Conduct and the enforcement policies listed above apply to all 105 | Adafruit Community venues. This includes but is not limited to any community 106 | spaces (both public and private), the entire Adafruit Discord server, and 107 | Adafruit GitHub repositories. Examples of Adafruit Community spaces include 108 | but are not limited to meet-ups, audio chats on the Adafruit Discord, or 109 | interaction at a conference. 110 | 111 | This Code of Conduct applies both within project spaces and in public spaces 112 | when an individual is representing the project or its community. As a community 113 | member, you are representing our community, and are expected to behave 114 | accordingly. 115 | 116 | ## Attribution 117 | 118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 | version 1.4, available at 120 | , 121 | and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). 122 | 123 | For other projects adopting the Adafruit Community Code of 124 | Conduct, please contact the maintainers of those projects for enforcement. 125 | If you wish to use this code of conduct for your own project, consider 126 | explicitly mentioning your moderation policy or making a copy with your 127 | own moderation policy so as to avoid confusion. 128 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 Tom Schucker for Tea and Tech Time 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 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 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | .. image:: https://readthedocs.org/projects/teaandtechtime-circuitpython-fft/badge/?version=latest 5 | :target: https://circuitpython.readthedocs.io/projects/fft/en/latest/ 6 | :alt: Documentation Status 7 | 8 | .. image:: https://img.shields.io/discord/327254708534116352.svg 9 | :target: https://discord.gg/nBQh6qu 10 | :alt: Discord 11 | 12 | .. image:: https://travis-ci.com/tschucker/Teaandtechtime_CircuitPython_FFT.svg?branch=master 13 | :target: https://travis-ci.com/tschucker/Teaandtechtime_CircuitPython_FFT 14 | :alt: Build Status 15 | 16 | CircuitPython FFT Library 17 | 18 | 19 | Dependencies 20 | ============= 21 | This driver depends on: 22 | 23 | * `Adafruit CircuitPython `_ 24 | * `Adafruit CircuitPython Itertools `_ 25 | 26 | Please ensure all dependencies are available on the CircuitPython filesystem. 27 | This is easily achieved by downloading 28 | `the Adafruit library and driver bundle `_. 29 | 30 | Usage Example 31 | ============= 32 | 33 | * `Adafruit Edge Badge Audio Waterfall `_ 34 | 35 | Make sure to follow the directions for connecting the microphone for the circuitpython i2s library support. 36 | 37 | Contributing 38 | ============ 39 | 40 | Contributions are welcome! Please read our `Code of Conduct 41 | `_ 42 | before contributing to help this project stay welcoming. 43 | 44 | Documentation 45 | ============= 46 | 47 | For information on building library documentation, please check out `this guide `_. 48 | -------------------------------------------------------------------------------- /docs/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tschucker/CircuitPython_FFT/c9325bc4633aa9b4effb16575b6987d4b945b803/docs/_static/favicon.ico -------------------------------------------------------------------------------- /docs/api.rst: -------------------------------------------------------------------------------- 1 | 2 | .. If you created a package, create one automodule per module in the package. 3 | 4 | .. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py) 5 | .. use this format as the module name: "adafruit_foo.foo" 6 | 7 | .. automodule:: teaandtechtime_fft 8 | :members: 9 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import os 4 | import sys 5 | sys.path.insert(0, os.path.abspath('..')) 6 | 7 | # -- General configuration ------------------------------------------------ 8 | 9 | # Add any Sphinx extension module names here, as strings. They can be 10 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 11 | # ones. 12 | extensions = [ 13 | 'sphinx.ext.autodoc', 14 | 'sphinx.ext.intersphinx', 15 | 'sphinx.ext.napoleon', 16 | 'sphinx.ext.todo', 17 | ] 18 | 19 | # TODO: Please Read! 20 | # Uncomment the below if you use native CircuitPython modules such as 21 | # digitalio, micropython and busio. List the modules you use. Without it, the 22 | # autodoc module docs will fail to generate with a warning. 23 | # autodoc_mock_imports = ["digitalio", "busio"] 24 | 25 | 26 | intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} 27 | 28 | # Add any paths that contain templates here, relative to this directory. 29 | templates_path = ['_templates'] 30 | 31 | source_suffix = '.rst' 32 | 33 | # The master toctree document. 34 | master_doc = 'index' 35 | 36 | # General information about the project. 37 | project = u'Teaandtechtime FFT Library' 38 | copyright = u'2019 Tom Schucker' 39 | author = u'Tom Schucker' 40 | 41 | # The version info for the project you're documenting, acts as replacement for 42 | # |version| and |release|, also used in various other places throughout the 43 | # built documents. 44 | # 45 | # The short X.Y version. 46 | version = u'1.0' 47 | # The full version, including alpha/beta/rc tags. 48 | release = u'1.0' 49 | 50 | # The language for content autogenerated by Sphinx. Refer to documentation 51 | # for a list of supported languages. 52 | # 53 | # This is also used if you do content translation via gettext catalogs. 54 | # Usually you set "language" from the command line for these cases. 55 | language = None 56 | 57 | # List of patterns, relative to source directory, that match files and 58 | # directories to ignore when looking for source files. 59 | # This patterns also effect to html_static_path and html_extra_path 60 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md'] 61 | 62 | # The reST default role (used for this markup: `text`) to use for all 63 | # documents. 64 | # 65 | default_role = "any" 66 | 67 | # If true, '()' will be appended to :func: etc. cross-reference text. 68 | # 69 | add_function_parentheses = True 70 | 71 | # The name of the Pygments (syntax highlighting) style to use. 72 | pygments_style = 'sphinx' 73 | 74 | # If true, `todo` and `todoList` produce output, else they produce nothing. 75 | todo_include_todos = False 76 | 77 | # If this is True, todo emits a warning for each TODO entries. The default is False. 78 | todo_emit_warnings = True 79 | 80 | napoleon_numpy_docstring = False 81 | 82 | # -- Options for HTML output ---------------------------------------------- 83 | 84 | # The theme to use for HTML and HTML Help pages. See the documentation for 85 | # a list of builtin themes. 86 | # 87 | on_rtd = os.environ.get('READTHEDOCS', None) == 'True' 88 | 89 | if not on_rtd: # only import and set the theme if we're building docs locally 90 | try: 91 | import sphinx_rtd_theme 92 | html_theme = 'sphinx_rtd_theme' 93 | html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] 94 | except: 95 | html_theme = 'default' 96 | html_theme_path = ['.'] 97 | else: 98 | html_theme_path = ['.'] 99 | 100 | # Add any paths that contain custom static files (such as style sheets) here, 101 | # relative to this directory. They are copied after the builtin static files, 102 | # so a file named "default.css" will overwrite the builtin "default.css". 103 | html_static_path = ['_static'] 104 | 105 | # The name of an image file (relative to this directory) to use as a favicon of 106 | # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 107 | # pixels large. 108 | # 109 | html_favicon = '_static/favicon.ico' 110 | 111 | # Output file base name for HTML help builder. 112 | htmlhelp_basename = 'TeaandtechtimeFftLibrarydoc' 113 | 114 | # -- Options for LaTeX output --------------------------------------------- 115 | 116 | latex_elements = { 117 | # The paper size ('letterpaper' or 'a4paper'). 118 | # 119 | # 'papersize': 'letterpaper', 120 | 121 | # The font size ('10pt', '11pt' or '12pt'). 122 | # 123 | # 'pointsize': '10pt', 124 | 125 | # Additional stuff for the LaTeX preamble. 126 | # 127 | # 'preamble': '', 128 | 129 | # Latex figure (float) alignment 130 | # 131 | # 'figure_align': 'htbp', 132 | } 133 | 134 | # Grouping the document tree into LaTeX files. List of tuples 135 | # (source start file, target name, title, 136 | # author, documentclass [howto, manual, or own class]). 137 | latex_documents = [ 138 | (master_doc, 'TeaandtechtimeFFTLibrary.tex', u'TeaandtechtimeFFT Library Documentation', 139 | author, 'manual'), 140 | ] 141 | 142 | # -- Options for manual page output --------------------------------------- 143 | 144 | # One entry per manual page. List of tuples 145 | # (source start file, name, description, authors, manual section). 146 | man_pages = [ 147 | (master_doc, 'TeaandtechtimeFFTlibrary', u'Teaandtechtime FFT Library Documentation', 148 | [author], 1) 149 | ] 150 | 151 | # -- Options for Texinfo output ------------------------------------------- 152 | 153 | # Grouping the document tree into Texinfo files. List of tuples 154 | # (source start file, target name, title, author, 155 | # dir menu entry, description, category) 156 | texinfo_documents = [ 157 | (master_doc, 'TeaandtechtimeFFTLibrary', u'Teaandtechtime FFT Library Documentation', 158 | author, 'TeaandtechtimeFFTLibrary', 'One line description of project.', 159 | 'Miscellaneous'), 160 | ] 161 | -------------------------------------------------------------------------------- /docs/examples.rst: -------------------------------------------------------------------------------- 1 | Simple test 2 | ------------ 3 | 4 | Ensure your device works with this simple test. 5 | 6 | .. literalinclude:: ../examples/fft_simpletest.py 7 | :caption: examples/fft_simpletest.py 8 | :linenos: 9 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | 3 | Table of Contents 4 | ================= 5 | 6 | .. toctree:: 7 | :maxdepth: 4 8 | :hidden: 9 | 10 | self 11 | 12 | .. toctree:: 13 | :caption: Examples 14 | 15 | examples 16 | 17 | .. toctree:: 18 | :caption: API Reference 19 | :maxdepth: 3 20 | 21 | api 22 | 23 | .. toctree:: 24 | :caption: Tutorials 25 | 26 | .. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave 27 | the toctree above for use later. 28 | 29 | .. toctree:: 30 | :caption: Related Products 31 | 32 | .. todo:: Add any product links here. If there are none, then simply delete this todo and leave 33 | the toctree above for use later. 34 | 35 | .. toctree:: 36 | :caption: Other Links 37 | 38 | Download 39 | CircuitPython Reference Documentation 40 | CircuitPython Support Forum 41 | Discord Chat 42 | Adafruit Learning System 43 | Adafruit Blog 44 | Adafruit Store 45 | 46 | Indices and tables 47 | ================== 48 | 49 | * :ref:`genindex` 50 | * :ref:`modindex` 51 | * :ref:`search` 52 | -------------------------------------------------------------------------------- /examples/fft_simpletest.py: -------------------------------------------------------------------------------- 1 | import array 2 | from teaandtechtime_fft import fft, ifft 3 | from math import sin, pi 4 | 5 | #assign the fft size we want to use 6 | fft_size = 256 7 | 8 | #create basic data structure to hold samples 9 | samples = array.array('f', [0] * fft_size) 10 | 11 | #assign a sinusoid to the samples 12 | frequency = 63 # Set this to the Hz of the tone you want to generate. 13 | for i in range(fft_size): 14 | samples[i] = sin(pi * 2 * i / (fft_size/frequency)) 15 | 16 | #create complex samples 17 | test_complex_samples = [] 18 | for n in range(fft_size): 19 | test_complex_samples.append(((float(samples[n]))-1 + 0.0j)) 20 | 21 | #compute fft of complex samples 22 | test_fft = fft(test_complex_samples) 23 | 24 | #compute ifft of the fft values 25 | test_ifft = ifft(test_fft) 26 | 27 | #print computed values for testing and verification 28 | #print complex samples 29 | print("samples") 30 | for i in test_complex_samples: 31 | print(i) 32 | time.sleep(.01) 33 | 34 | #print fft values 35 | print("fft") 36 | for i in test_fft: 37 | print(i) 38 | time.sleep(.01) 39 | 40 | #print ifft values 41 | print("ifft") 42 | for i in test_ifft: 43 | print(i) 44 | time.sleep(.01) 45 | 46 | #compute absolut value of the error per sample 47 | print("error") 48 | for i in range(fft_size): 49 | print(abs(test_ifft[i] - test_complex_samples[i])) 50 | time.sleep(.01) 51 | -------------------------------------------------------------------------------- /examples/verification/README.md: -------------------------------------------------------------------------------- 1 | The files used here are to be run with python3 and demonstrait the verification of the fft written in 2 | circuit python to the numpy version. There is more error but this is to be expected for a small device 3 | and the computational precision needed for the fft and its reverse. 4 | 5 | using the same code to generate samples on each device shows a much greater discrepancy in error if we use 6 | the samples generated out of the circuit python the error is greatly reduced. 7 | -------------------------------------------------------------------------------- /examples/verification/cp_fft.py: -------------------------------------------------------------------------------- 1 | #captured values off serial 2 | cp_fft = [ 3 | (-256+0j), 4 | (2.89933e-05-0.00041759j), 5 | (1.50354e-06+2.75475e-05j), 6 | (-1.1905e-05+0.000241156j), 7 | (3.35402e-06-0.000192769j), 8 | (0.00013245+2.27986e-05j), 9 | (0.000162704+6.5118e-05j), 10 | (-0.000144386-0.000198169j), 11 | (-5.20728e-05-1.75414e-05j), 12 | (0.000127563-7.15122e-05j), 13 | (0.000195871-5.37169e-05j), 14 | (0.000162135+3.62584e-05j), 15 | (0.000197243+5.35311e-05j), 16 | (-4.55856e-05+0.000172068j), 17 | (-0.000195047-0.000250401j), 18 | (0.00027674-0.000250842j), 19 | (0.000454933+0.000434453j), 20 | (-6.57457e-05+0.000287188j), 21 | (-7.64666e-05+7.96703e-06j), 22 | (8.80792e-05-0.00016013j), 23 | (-7.96474e-05-6.39044e-05j), 24 | (0.000185056+3.83994e-05j), 25 | (0.000137617+0.000147868j), 26 | (0.000347314+0.000255352j), 27 | (-0.00046994+0.000120991j), 28 | (7.94883e-05+2.23523e-05j), 29 | (3.97107e-05+5.13027e-05j), 30 | (2.48438e-05+2.51601e-05j), 31 | (2.54828e-05+0.000107316j), 32 | (6.12321e-05-1.50136e-05j), 33 | (-0.000235111+0.00018091j), 34 | (-0.000198247+1.84241e-05j), 35 | (-2.36547e-05-0.000829079j), 36 | (0.000657302+0.00037242j), 37 | (0.000157464+0.000273268j), 38 | (-0.000154652-0.00013019j), 39 | (9.13228e-05+3.53326e-05j), 40 | (9.92829e-05+0.000121766j), 41 | (-1.40751e-05-0.00014414j), 42 | (5.83026e-05+9.68042e-05j), 43 | (7.42631e-05+0.000122849j), 44 | (0.000170054-0.000297358j), 45 | (-3.24175e-05+0.000133299j), 46 | (0.000891625-0.000242918j), 47 | (-2.58585e-05+0.000626147j), 48 | (8.41619e-05+5.25142e-05j), 49 | (0.000500738-0.000115647j), 50 | (0.000653957+0.000716132j), 51 | (-0.000360076+0.0010986j), 52 | (-0.00056507-3.9303e-05j), 53 | (0.000191792+9.96802e-05j), 54 | (-0.000472645+0.000297274j), 55 | (-0.000326593-0.00039608j), 56 | (0.000831736-0.000300087j), 57 | (0.000508789+0.00076357j), 58 | (-3.15678e-05+0.00066919j), 59 | (0.000348637+0.000485008j), 60 | (-0.000211476+0.000391594j), 61 | (0.000288395+0.000478684j), 62 | (0.000130985+0.000989147j), 63 | (-5.6343e-05+0.000710909j), 64 | (0.000493496+0.00182621j), 65 | (8.50189e-05+0.00355384j), 66 | (-0.0100397-128j), 67 | (7.62951e-05-0.00354004j), 68 | (0.000591842-0.00154114j), 69 | (-0.000187611-0.000577588j), 70 | (4.88246e-07-0.00111743j), 71 | (0.000207331-0.000641847j), 72 | (-0.00018373-0.000706649j), 73 | (0.00037607-0.000564858j), 74 | (1.54206e-05-0.000575257j), 75 | (0.000541094-0.000593157j), 76 | (0.000807285+0.000384186j), 77 | (-0.000298581+0.000548643j), 78 | (-0.00059269-0.000361704j), 79 | (0.000188012-0.000112582j), 80 | (-0.000645881+7.38328e-05j), 81 | (-0.000411911-0.00124131j), 82 | (0.000565195-0.000767522j), 83 | (0.000491308-0.00010866j), 84 | (0.000165029-0.000181059j), 85 | (0.000158842-0.000572956j), 86 | (0.000935093+0.000256175j), 87 | (0.000130382-2.02993e-05j), 88 | (0.000129426+0.000378997j), 89 | (-3.4165e-05-7.46481e-05j), 90 | (7.27611e-05-1.31539e-05j), 91 | (-0.0002015+0.000151199j), 92 | (0.000122531-0.000193879j), 93 | (0.000208645-0.00018829j), 94 | (-9.39035e-05+7.41567e-05j), 95 | (0.000216395-0.000220426j), 96 | (0.000552826-0.000391547j), 97 | (4.07472e-05+0.000957255j), 98 | (-0.000158016-0.00010805j), 99 | (-0.000174709+0.000116966j), 100 | (5.1984e-05+0.000112585j), 101 | (-0.000151782-0.00010813j), 102 | (-0.0001479+0.000143347j), 103 | (-9.90757e-05-0.000472565j), 104 | (0.000110285-6.02892e-06j), 105 | (-0.000365176-9.93272e-05j), 106 | (0.000398787-0.0002999j), 107 | (0.000223535-4.50686e-05j), 108 | (0.000124036-7.31717e-05j), 109 | (-0.000122352-7.10912e-05j), 110 | (0.000126921+7.098e-05j), 111 | (-9.12977e-05+1.82696e-05j), 112 | (-8.47288e-05-0.000224342j), 113 | (0.000183959-0.000213638j), 114 | (0.000216698+5.70388e-05j), 115 | (-2.15909e-05+6.64295e-05j), 116 | (4.79026e-05-0.000160185j), 117 | (0.000437017-0.000242763j), 118 | (0.000193521+0.000102624j), 119 | (-1.05944e-05+0.000144053j), 120 | (0.00019786+3.16497e-05j), 121 | (3.24356e-05+4.23114e-05j), 122 | (-6.08485e-05+0.000163761j), 123 | (0.000115819+3.73977e-05j), 124 | (0.000104343-2.81194e-05j), 125 | (-6.32522e-06+0.000207505j), 126 | (-2.70402e-05-4.53131e-05j), 127 | (5.71337e-05-0.000181991j), 128 | (4.11347e-05+0.000410719j), 129 | (-4.65015e-06-7.91173e-05j), 130 | (-0.000122389-0.000108659j), 131 | (0.00012207+0j), 132 | (-0.00010988+0.000142932j), 133 | (-4.65112e-06+7.91159e-05j), 134 | (3.7518e-05-0.000405239j), 135 | (5.71326e-05+0.000181991j), 136 | (-2.85304e-05+4.75993e-05j), 137 | (-6.32484e-06-0.000207505j), 138 | (0.000101096+2.92097e-05j), 139 | (0.000115818-3.73976e-05j), 140 | (-5.7091e-05-0.000163443j), 141 | (3.24358e-05-4.23119e-05j), 142 | (0.000195465-3.00495e-05j), 143 | (-1.05939e-05-0.000144053j), 144 | (0.000193362-9.82705e-05j), 145 | (0.000437016+0.000242765j), 146 | (3.81802e-05+0.000172281j), 147 | (-2.1591e-05-6.643e-05j), 148 | (0.000222751-4.57574e-05j), 149 | (0.000183958+0.000213639j), 150 | (-8.73313e-05+0.00022611j), 151 | (-9.12978e-05-1.82697e-05j), 152 | (0.000129787-6.8232e-05j), 153 | (-0.000122353+7.10905e-05j), 154 | (0.000120832+7.65603e-05j), 155 | (0.000223535+4.5069e-05j), 156 | (0.000403885+0.000302798j), 157 | (-0.000365176+9.9326e-05j), 158 | (0.000111213+7.54511e-06j), 159 | (-9.90765e-05+0.000472565j), 160 | (-0.000147707-0.000140156j), 161 | (-0.000151781+0.000108128j), 162 | (4.13452e-05-9.79322e-05j), 163 | (-0.000174709-0.000116966j), 164 | (-0.0001381+0.000139794j), 165 | (4.07494e-05-0.000957256j), 166 | (0.000549821+0.000392198j), 167 | (0.000216394+0.000220427j), 168 | (-9.05407e-05-6.43407e-05j), 169 | (0.000208644+0.00018829j), 170 | (0.000124561+0.000201017j), 171 | (-0.0002015-0.0001512j), 172 | (6.99863e-05+2.9014e-05j), 173 | (-3.41651e-05+7.4648e-05j), 174 | (0.000127319-0.000379221j), 175 | (0.000130382+2.02998e-05j), 176 | (0.00093758-0.000246455j), 177 | (0.00015884+0.000572956j), 178 | (0.000157663+0.000191134j), 179 | (0.000491308+0.00010866j), 180 | (0.000571348+0.000818507j), 181 | (-0.000411914+0.0012413j), 182 | (-0.000647701-7.08594e-05j), 183 | (0.000188012+0.000112582j), 184 | (-0.000590376+0.000375903j), 185 | (-0.000298578-0.000548646j), 186 | (0.000807926-0.000379047j), 187 | (0.000541094+0.000593157j), 188 | (1.41069e-05+0.000606281j), 189 | (0.000376069+0.000564857j), 190 | (-0.00018627+0.000720765j), 191 | (0.00020733+0.000641847j), 192 | (2.33878e-07+0.00115855j), 193 | (-0.00018761+0.000577586j), 194 | (0.000520382+0.0015564j), 195 | (7.62928e-05+0.00354004j), 196 | (-0.0104555+128j), 197 | (8.50293e-05-0.00355384j), 198 | (0.00049159-0.00184845j), 199 | (-5.63418e-05-0.00071091j), 200 | (0.000131557-0.001031j), 201 | (0.000288396-0.000478683j), 202 | (-0.000215375-0.000397815j), 203 | (0.000348637-0.000485008j), 204 | (-2.69226e-05-0.000705829j), 205 | (0.000508791-0.000763568j), 206 | (0.000830226+0.000291174j), 207 | (-0.000326593+0.000396079j), 208 | (-0.000470353-0.0003131j), 209 | (0.000191792-9.96797e-05j), 210 | (-0.000575918+3.811e-05j), 211 | (-0.000360074-0.0010986j), 212 | (0.000665606-0.000766094j), 213 | (0.000500737+0.000115648j), 214 | (8.15944e-05-5.53916e-05j), 215 | (-2.58571e-05-0.000626147j), 216 | (0.00089548+0.000236451j), 217 | (-3.24172e-05-0.000133299j), 218 | (0.000161122+0.000294389j), 219 | (7.4263e-05-0.000122849j), 220 | (5.96546e-05-0.000106341j), 221 | (-1.40757e-05+0.00014414j), 222 | (9.69515e-05-0.000127375j), 223 | (9.13231e-05-3.53326e-05j), 224 | (-0.000152332+0.000123952j), 225 | (0.000157466-0.000273267j), 226 | (0.000647402-0.000377017j), 227 | (-2.36555e-05+0.000829079j), 228 | (-0.000181737-6.02243e-05j), 229 | (-0.000235111-0.000180909j), 230 | (5.88851e-05+1.17221e-05j), 231 | (2.54828e-05-0.000107316j), 232 | (2.69739e-05-2.86752e-05j), 233 | (3.97111e-05-5.13026e-05j), 234 | (7.90108e-05-2.3791e-05j), 235 | (-0.00046994-0.000120991j), 236 | (0.000352426-0.000263206j), 237 | (0.000137617-0.000147867j), 238 | (0.00018196-4.04971e-05j), 239 | (-7.96473e-05+6.39043e-05j), 240 | (9.03402e-05+0.000153582j), 241 | (-7.64669e-05-7.96761e-06j), 242 | (-7.24565e-05-0.00029366j), 243 | (0.000454933-0.000434453j), 244 | (0.000290208+0.000239292j), 245 | (-0.000195048+0.0002504j), 246 | (-4.62821e-05-0.000175129j), 247 | (0.000197243-5.35306e-05j), 248 | (0.000166117-3.79001e-05j), 249 | (0.000195871+5.37179e-05j), 250 | (0.000128213+7.03313e-05j), 251 | (-5.20728e-05+1.75413e-05j), 252 | (-0.000139569+0.000197152j), 253 | (0.000162704-6.51175e-05j), 254 | (0.000132382-2.34073e-05j), 255 | (3.35394e-06+0.000192769j), 256 | (-1.13185e-05-0.000240947j), 257 | (1.50438e-06-2.7547e-05j), 258 | (2.52941e-06+0.000398576j)] 259 | -------------------------------------------------------------------------------- /examples/verification/cp_fft_verification_in_py3.py: -------------------------------------------------------------------------------- 1 | import array 2 | import numpy as np 3 | from math import sin, pi 4 | 5 | import cp_samples 6 | import cp_fft 7 | import cp_ifft 8 | 9 | #assign the fft size we want to use 10 | fft_size = 256 11 | 12 | #create basic data structure to hold samples 13 | samples = array.array('f', [0] * fft_size) 14 | 15 | #assign a sinusoid to the samples 16 | frequency = 63 # Set this to the Hz of the tone you want to generate. 17 | for i in range(fft_size): 18 | samples[i] = sin(pi * 2 * i / (fft_size/frequency)) 19 | 20 | #create complex samples 21 | test_complex_samples = [] 22 | for n in range(fft_size): 23 | test_complex_samples.append(((float(samples[n]))-1 + 0.0j)) 24 | 25 | #print("samples") 26 | #print(test_complex_samples) 27 | 28 | np_fft = np.fft.fft(test_complex_samples) 29 | #print("numpy fft") 30 | #print(np_fft) 31 | 32 | np_ifft = np.fft.ifft(np_fft) 33 | #print("numpy ifft") 34 | #print(np_ifft) 35 | 36 | error = np_ifft - test_complex_samples 37 | sum_error = np.sum(abs(error)) 38 | print("sum error numpy results") 39 | print(sum_error) 40 | 41 | sum_error_cp = 0 42 | for i in range(fft_size): 43 | sum_error_cp = sum_error_cp + abs(cp_ifft.cp_ifft[i] - cp_samples.cp_samples[i]) 44 | print("sum error circuitpy results") 45 | print(sum_error_cp) 46 | 47 | sum_error_samples = 0 48 | for i in range(fft_size): 49 | sum_error_samples = sum_error_samples + abs(test_complex_samples[i] - cp_samples.cp_samples[i]) 50 | print("sum error numpy vs circuitpy samples") 51 | print(sum_error_samples) 52 | 53 | error_fft = np_fft - cp_fft.cp_fft 54 | sum_error_fft = np.sum(abs(error_fft)) 55 | print("sum error numpy vs circuitpy fft") 56 | print(sum_error_fft) 57 | 58 | error_ifft = np_ifft - cp_ifft.cp_ifft 59 | sum_error_ifft = np.sum(abs(error_ifft)) 60 | print("sum error numpy vs circuitpy ifft") 61 | print(sum_error_ifft) 62 | 63 | #error when using cp_samples as the np.fft input 64 | np_fft_cps = np.fft.fft(cp_samples.cp_samples) 65 | np_ifft_cps = np.fft.ifft(np_fft_cps) 66 | 67 | error_fft_cps = np_fft_cps - cp_fft.cp_fft 68 | sum_error_fft_cps = np.sum(abs(error_fft_cps)) 69 | print("sum error numpy vs circuitpy fft with cp_samples") 70 | print(sum_error_fft_cps) 71 | 72 | error_ifft_cps = np_ifft_cps - cp_ifft.cp_ifft 73 | sum_error_ifft_cps = np.sum(abs(error_ifft_cps)) 74 | print("sum error numpy vs circuitpy ifft with cp_samples") 75 | print(sum_error_ifft_cps) 76 | -------------------------------------------------------------------------------- /examples/verification/cp_ifft.py: -------------------------------------------------------------------------------- 1 | #captured values off serial 2 | cp_ifft = [ 3 | (-0.999999+2.38428e-07j), 4 | (-0.000303984+1.0429e-07j), 5 | (-0.95093-7.7485e-07j), 6 | (-1.99728+8.94173e-08j), 7 | (-1.09802+5.84878e-07j), 8 | (-0.00752306+1.49002e-07j), 9 | (-0.853264-6.25833e-07j), 10 | (-1.98527+1.78839e-07j), 11 | (-1.19509+4.91736e-07j), 12 | (-0.0243018+1.78825e-07j), 13 | (-0.757014-9.23873e-07j), 14 | (-1.96377-2.98033e-07j), 15 | (-1.29029+7.15245e-07j), 16 | (-0.0504758+7.15247e-07j), 17 | (-0.663103-4.47045e-07j), 18 | (-1.93298+1.19212e-07j), 19 | (-1.38269+3.5765e-07j), 20 | (-0.0857968+1.19196e-07j), 21 | (-0.572433-7.74872e-07j), 22 | (-1.89321-2.38397e-07j), 23 | (-1.4714+5.3645e-07j), 24 | (-0.129927+4.76812e-07j), 25 | (-0.485888-4.76839e-07j), 26 | (-1.84483+2.3843e-07j), 27 | (-1.55558+1.19209e-07j), 28 | (-0.182429+2.38404e-07j), 29 | (-0.404295-3.57653e-07j), 30 | (-1.78832+1.19207e-07j), 31 | (-1.6344+4.76849e-07j), 32 | (-0.242805+1.07288e-06j), 33 | (-0.328426-7.15248e-07j), 34 | (-1.72423-2.38411e-07j), 35 | (-1.70711-1.19209e-07j), 36 | (-0.310484-1.69384e-11j), 37 | (-0.259037-5.96049e-07j), 38 | (-1.65316-4.76825e-07j), 39 | (-1.77302+3.57644e-07j), 40 | (-0.38478+9.53669e-07j), 41 | (-0.196784-1.19205e-07j), 42 | (-1.57579+1.17514e-11j), 43 | (-1.83148+1.192e-07j), 44 | (-0.465026+2.38407e-07j), 45 | (-0.14225-5.9602e-07j), 46 | (-1.49287-5.96045e-07j), 47 | (-1.88193+2.3842e-07j), 48 | (-0.550397+1.25171e-06j), 49 | (-0.0959871-5.96032e-07j), 50 | (-1.4052+1.7881e-07j), 51 | (-1.92389+3.57616e-07j), 52 | (-0.640126+5.95983e-08j), 53 | (-0.0584447-2.38419e-07j), 54 | (-1.31365-2.68206e-07j), 55 | (-1.95694-3.57624e-07j), 56 | (-0.733321+6.25857e-07j), 57 | (-0.0299571-5.36443e-07j), 58 | (-1.21906-2.68204e-07j), 59 | (-1.98079-1.7882e-07j), 60 | (-0.829055+3.57631e-07j), 61 | (-0.0108206+5.36428e-07j), 62 | (-1.12235-2.23486e-08j), 63 | (-1.99518+1.78806e-07j), 64 | (-0.926465+6.57538e-07j), 65 | (-0.00120401-1.63916e-07j), 66 | (-1.0245-1.92563e-07j), 67 | (-2-4.6839e-11j), 68 | (-1.02458+3.35293e-07j), 69 | (-0.00120831-3.87431e-07j), 70 | (-0.926384-5.49484e-07j), 71 | (-1.99518-2.98025e-08j), 72 | (-1.12244+8.86622e-07j), 73 | (-0.0108268-2.38421e-07j), 74 | (-0.829005-2.23773e-08j), 75 | (-1.98077+5.96023e-08j), 76 | (-1.21914+5.96043e-07j), 77 | (-0.0299764+5.96e-08j), 78 | (-0.733243-2.08611e-07j), 79 | (-1.95693-1.19206e-07j), 80 | (-1.3137+5.96038e-07j), 81 | (-0.05847-1.19212e-07j), 82 | (-0.640051-3.27835e-07j), 83 | (-1.92386-1.1923e-07j), 84 | (-1.40527+4.76845e-07j), 85 | (-0.0960348-5.96051e-07j), 86 | (-0.550297-4.76841e-07j), 87 | (-1.88188-1.02436e-11j), 88 | (-1.49296+8.34479e-07j), 89 | (-0.142306-1.19212e-07j), 90 | (-0.464958-4.7684e-07j), 91 | (-1.83144+1.19216e-07j), 92 | (-1.57583+2.3844e-07j), 93 | (-0.196804+5.96065e-07j), 94 | (-0.384717-1.19212e-07j), 95 | (-1.77293+1.19203e-07j), 96 | (-1.65325+4.76838e-07j), 97 | (-0.259111-1.19201e-07j), 98 | (-0.310404-7.15264e-07j), 99 | (-1.70706-1.19213e-07j), 100 | (-1.72428+2.38437e-07j), 101 | (-0.328474+2.38423e-07j), 102 | (-0.242772-3.57633e-07j), 103 | (-1.63433-3.57641e-07j), 104 | (-1.78838+4.76843e-07j), 105 | (-0.404347+4.76838e-07j), 106 | (-0.182391-1.19212e-07j), 107 | (-1.55554-5.96041e-07j), 108 | (-1.84489+8.34483e-07j), 109 | (-0.485957+4.7682e-07j), 110 | (-0.129887-4.76843e-07j), 111 | (-1.4713-3.57626e-07j), 112 | (-1.89326+1.19201e-07j), 113 | (-0.572519+5.95749e-08j), 114 | (-0.0857637-4.76848e-07j), 115 | (-1.38263-2.38401e-07j), 116 | (-1.933+3.5764e-07j), 117 | (-0.663142+5.36441e-07j), 118 | (-0.050467+3.57605e-07j), 119 | (-1.29021-8.64274e-07j), 120 | (-1.9638+9.53677e-07j), 121 | (-0.757123+2.68223e-07j), 122 | (-0.0242798-7.74873e-07j), 123 | (-1.195-2.53311e-07j), 124 | (-1.98528+1.19198e-07j), 125 | (-0.853327+7.52532e-07j), 126 | (-0.00751829-5.06651e-07j), 127 | (-1.09792-8.97792e-07j), 128 | (-1.99729-5.96069e-07j), 129 | (-0.951004+3.76255e-07j), 130 | (-0.000303268+2.98145e-08j), 131 | (-0.99995-2.38409e-07j), 132 | (-1.99969-1.04326e-07j), 133 | (-1.04915+7.7487e-07j), 134 | (-0.00271702-8.93966e-08j), 135 | (-0.901859-5.84864e-07j), 136 | (-1.99246-1.49022e-07j), 137 | (-1.14683+6.25864e-07j), 138 | (-0.01474-1.78789e-07j), 139 | (-0.804835-4.91741e-07j), 140 | (-1.97568-1.78802e-07j), 141 | (-1.24303+9.23871e-07j), 142 | (-0.0362363+2.98014e-07j), 143 | (-0.709688-7.15267e-07j), 144 | (-1.9495-7.15264e-07j), 145 | (-1.33695+4.47025e-07j), 146 | (-0.0670512-1.19206e-07j), 147 | (-0.617223-3.57605e-07j), 148 | (-1.91417-1.19223e-07j), 149 | (-1.42762+7.74848e-07j), 150 | (-0.106806+2.3844e-07j), 151 | (-0.528556-5.36434e-07j), 152 | (-1.87003-4.76862e-07j), 153 | (-1.51418+4.76835e-07j), 154 | (-0.155191-2.38407e-07j), 155 | (-0.444375-1.19209e-07j), 156 | (-1.81755-2.38433e-07j), 157 | (-1.59573+3.57603e-07j), 158 | (-0.211675-1.19212e-07j), 159 | (-0.365546-4.76826e-07j), 160 | (-1.75712-1.07289e-06j), 161 | (-1.67164+7.15264e-07j), 162 | (-0.275826+2.38426e-07j), 163 | (-0.292829+1.19209e-07j), 164 | (-1.68948-1.69384e-11j), 165 | (-1.74099+5.96044e-07j), 166 | (-0.346917+4.76849e-07j), 167 | (-0.226924-3.57612e-07j), 168 | (-1.61511-9.53679e-07j), 169 | (-1.80332+1.19214e-07j), 170 | (-0.424349+1.17514e-11j), 171 | (-0.168432-1.19219e-07j), 172 | (-1.53485-2.3843e-07j), 173 | (-1.8578+5.96073e-07j), 174 | (-0.507227+5.96047e-07j), 175 | (-0.118017-2.38417e-07j), 176 | (-1.4495-1.25168e-06j), 177 | (-1.90403+5.9606e-07j), 178 | (-0.594846-1.78817e-07j), 179 | (-0.0760899-3.5764e-07j), 180 | (-1.35983-5.96109e-08j), 181 | (-1.94156+2.38418e-07j), 182 | (-0.686363+2.68236e-07j), 183 | (-0.0430508+3.57632e-07j), 184 | (-1.26669-6.2584e-07j), 185 | (-1.97006+5.36441e-07j), 186 | (-0.781135+2.68238e-07j), 187 | (-0.01917+1.78808e-07j), 188 | (-1.17074-3.57624e-07j), 189 | (-1.9892-5.36455e-07j), 190 | (-0.877783+2.23548e-08j), 191 | (-0.00479817-1.78822e-07j), 192 | (-1.07339-6.57489e-07j), 193 | (-1.9988+1.6391e-07j), 194 | (-0.975604+1.92539e-07j), 195 | (2.38419e-07+2.13731e-11j), 196 | (-0.975335-3.35259e-07j), 197 | (-1.99879+3.87429e-07j), 198 | (-1.07366+5.49476e-07j), 199 | (-0.00482464+2.98021e-08j), 200 | (-0.877515-8.86616e-07j), 201 | (-1.98916+2.38416e-07j), 202 | (-1.17113+2.23262e-08j), 203 | (-0.0192456-5.9607e-08j), 204 | (-0.780753-5.96049e-07j), 205 | (-1.96999-5.96092e-08j), 206 | (-1.26683+2.08621e-07j), 207 | (-0.043093+1.19213e-07j), 208 | (-0.686224-5.96055e-07j), 209 | (-1.94151+1.19207e-07j), 210 | (-1.35996+3.27816e-07j), 211 | (-0.0761456+1.19188e-07j), 212 | (-0.594599-4.76829e-07j), 213 | (-1.90392+5.96042e-07j), 214 | (-1.44974+4.76833e-07j), 215 | (-0.118145-1.02436e-11j), 216 | (-0.506992-8.34451e-07j), 217 | (-1.85767+1.19207e-07j), 218 | (-1.53518+4.76834e-07j), 219 | (-0.168648-1.19202e-07j), 220 | (-0.424029-2.38397e-07j), 221 | (-1.80309-5.96028e-07j), 222 | (-1.61537+1.19207e-07j), 223 | (-0.227093-1.19216e-07j), 224 | (-0.346714-4.76836e-07j), 225 | (-1.74085+1.19217e-07j), 226 | (-1.68963+7.15247e-07j), 227 | (-0.292976+1.19205e-07j), 228 | (-0.275683-2.384e-07j), 229 | (-1.67149-2.38414e-07j), 230 | (-1.75726+3.57622e-07j), 231 | (-0.36566+3.57615e-07j), 232 | (-0.21162-4.76832e-07j), 233 | (-1.59566-4.76836e-07j), 234 | (-1.8176+1.19206e-07j), 235 | (-0.444547+5.96051e-07j), 236 | (-0.155079-8.34447e-07j), 237 | (-1.51389-4.76854e-07j), 238 | (-1.87019+4.76832e-07j), 239 | (-0.528792+3.57629e-07j), 240 | (-0.106687-1.19217e-07j), 241 | (-1.42738-5.96344e-08j), 242 | (-1.91428+4.76826e-07j), 243 | (-0.617472+2.38436e-07j), 244 | (-0.0669537-3.57616e-07j), 245 | (-1.33675-5.36443e-07j), 246 | (-1.94956-3.57651e-07j), 247 | (-0.709829+8.64261e-07j), 248 | (-0.0361969-9.53671e-07j), 249 | (-1.24288-2.68219e-07j), 250 | (-1.97571+7.74848e-07j), 251 | (-0.805098+2.53328e-07j), 252 | (-0.0146945-1.1922e-07j), 253 | (-1.14656-7.52485e-07j), 254 | (-1.99249+5.06628e-07j), 255 | (-0.902126+8.97797e-07j), 256 | (-0.00270367+5.96024e-07j), 257 | (-1.04894-3.76254e-07j), 258 | (-1.99969-2.97901e-08j)] 259 | -------------------------------------------------------------------------------- /examples/verification/cp_samples.py: -------------------------------------------------------------------------------- 1 | #captured values off serial 2 | cp_samples = [ 3 | (-1+0j), 4 | (-0.000301361+0j), 5 | (-0.950932+0j), 6 | (-1.99729+0j), 7 | (-1.09802+0j), 8 | (-0.00752091+0j), 9 | (-0.853265+0j), 10 | (-1.98528+0j), 11 | (-1.19509+0j), 12 | (-0.0242994+0j), 13 | (-0.757014+0j), 14 | (-1.96377+0j), 15 | (-1.29029+0j), 16 | (-0.0504732+0j), 17 | (-0.663103+0j), 18 | (-1.93299+0j), 19 | (-1.38269+0j), 20 | (-0.0857942+0j), 21 | (-0.572433+0j), 22 | (-1.89322+0j), 23 | (-1.47141+0j), 24 | (-0.129924+0j), 25 | (-0.485888+0j), 26 | (-1.84484+0j), 27 | (-1.55558+0j), 28 | (-0.182427+0j), 29 | (-0.404294+0j), 30 | (-1.78833+0j), 31 | (-1.6344+0j), 32 | (-0.242803+0j), 33 | (-0.328426+0j), 34 | (-1.72423+0j), 35 | (-1.70712+0j), 36 | (-0.310482+0j), 37 | (-0.259036+0j), 38 | (-1.65317+0j), 39 | (-1.77303+0j), 40 | (-0.384779+0j), 41 | (-0.196783+0j), 42 | (-1.57579+0j), 43 | (-1.83148+0j), 44 | (-0.465025+0j), 45 | (-0.142248+0j), 46 | (-1.49287+0j), 47 | (-1.88193+0j), 48 | (-0.550396+0j), 49 | (-0.0959861+0j), 50 | (-1.4052+0j), 51 | (-1.92389+0j), 52 | (-0.640125+0j), 53 | (-0.0584426+0j), 54 | (-1.31365+0j), 55 | (-1.95694+0j), 56 | (-0.733321+0j), 57 | (-0.0299559+0j), 58 | (-1.21906+0j), 59 | (-1.98079+0j), 60 | (-0.829055+0j), 61 | (-0.0108182+0j), 62 | (-1.12236+0j), 63 | (-1.99519+0j), 64 | (-0.926465+0j), 65 | (-0.00120234+0j), 66 | (-1.0245+0j), 67 | (-2+0j), 68 | (-1.02458+0j), 69 | (-0.00120759+0j), 70 | (-0.926386+0j), 71 | (-1.99518+0j), 72 | (-1.12244+0j), 73 | (-0.0108256+0j), 74 | (-0.829006+0j), 75 | (-1.98078+0j), 76 | (-1.21914+0j), 77 | (-0.0299752+0j), 78 | (-0.733244+0j), 79 | (-1.95693+0j), 80 | (-1.3137+0j), 81 | (-0.0584693+0j), 82 | (-0.640051+0j), 83 | (-1.92386+0j), 84 | (-1.40527+0j), 85 | (-0.0960333+0j), 86 | (-0.550298+0j), 87 | (-1.88188+0j), 88 | (-1.49297+0j), 89 | (-0.142305+0j), 90 | (-0.464957+0j), 91 | (-1.83145+0j), 92 | (-1.57583+0j), 93 | (-0.196803+0j), 94 | (-0.384716+0j), 95 | (-1.77294+0j), 96 | (-1.65325+0j), 97 | (-0.25911+0j), 98 | (-0.310402+0j), 99 | (-1.70706+0j), 100 | (-1.72429+0j), 101 | (-0.328473+0j), 102 | (-0.242771+0j), 103 | (-1.63433+0j), 104 | (-1.78839+0j), 105 | (-0.404346+0j), 106 | (-0.18239+0j), 107 | (-1.55554+0j), 108 | (-1.8449+0j), 109 | (-0.485957+0j), 110 | (-0.129885+0j), 111 | (-1.4713+0j), 112 | (-1.89327+0j), 113 | (-0.572519+0j), 114 | (-0.0857618+0j), 115 | (-1.38263+0j), 116 | (-1.93301+0j), 117 | (-0.663142+0j), 118 | (-0.0504649+0j), 119 | (-1.29022+0j), 120 | (-1.96381+0j), 121 | (-0.757125+0j), 122 | (-0.024277+0j), 123 | (-1.19501+0j), 124 | (-1.98529+0j), 125 | (-0.853329+0j), 126 | (-0.00751472+0j), 127 | (-1.09792+0j), 128 | (-1.9973+0j), 129 | (-0.951005+0j), 130 | (-0.000299692+0j), 131 | (-0.999951+0j), 132 | (-1.9997+0j), 133 | (-1.04915+0j), 134 | (-0.00271511+0j), 135 | (-0.90186+0j), 136 | (-1.99247+0j), 137 | (-1.14683+0j), 138 | (-0.0147374+0j), 139 | (-0.804836+0j), 140 | (-1.97569+0j), 141 | (-1.24303+0j), 142 | (-0.0362344+0j), 143 | (-0.709689+0j), 144 | (-1.9495+0j), 145 | (-1.33695+0j), 146 | (-0.0670481+0j), 147 | (-0.617223+0j), 148 | (-1.91417+0j), 149 | (-1.42762+0j), 150 | (-0.106805+0j), 151 | (-0.528557+0j), 152 | (-1.87004+0j), 153 | (-1.51418+0j), 154 | (-0.155188+0j), 155 | (-0.444375+0j), 156 | (-1.81755+0j), 157 | (-1.59573+0j), 158 | (-0.211672+0j), 159 | (-0.365546+0j), 160 | (-1.75712+0j), 161 | (-1.67164+0j), 162 | (-0.275825+0j), 163 | (-0.292828+0j), 164 | (-1.68948+0j), 165 | (-1.741+0j), 166 | (-0.346916+0j), 167 | (-0.226923+0j), 168 | (-1.61511+0j), 169 | (-1.80333+0j), 170 | (-0.424348+0j), 171 | (-0.168431+0j), 172 | (-1.53486+0j), 173 | (-1.85781+0j), 174 | (-0.507226+0j), 175 | (-0.118017+0j), 176 | (-1.4495+0j), 177 | (-1.90403+0j), 178 | (-0.594845+0j), 179 | (-0.0760889+0j), 180 | (-1.35983+0j), 181 | (-1.94156+0j), 182 | (-0.686363+0j), 183 | (-0.0430496+0j), 184 | (-1.26669+0j), 185 | (-1.97006+0j), 186 | (-0.781136+0j), 187 | (-0.0191698+0j), 188 | (-1.17075+0j), 189 | (-1.98921+0j), 190 | (-0.877783+0j), 191 | (-0.00479746+0j), 192 | (-1.07339+0j), 193 | (-1.9988+0j), 194 | (-0.975605+0j), 195 | (0j), 196 | (-0.975336+0j), 197 | (-1.99879+0j), 198 | (-1.07366+0j), 199 | (-0.00482392+0j), 200 | (-0.877515+0j), 201 | (-1.98917+0j), 202 | (-1.17113+0j), 203 | (-0.0192461+0j), 204 | (-0.780754+0j), 205 | (-1.97+0j), 206 | (-1.26683+0j), 207 | (-0.0430925+0j), 208 | (-0.686223+0j), 209 | (-1.94151+0j), 210 | (-1.35997+0j), 211 | (-0.0761452+0j), 212 | (-0.594599+0j), 213 | (-1.90392+0j), 214 | (-1.44975+0j), 215 | (-0.118144+0j), 216 | (-0.506992+0j), 217 | (-1.85767+0j), 218 | (-1.53519+0j), 219 | (-0.168648+0j), 220 | (-0.424028+0j), 221 | (-1.80309+0j), 222 | (-1.61537+0j), 223 | (-0.227094+0j), 224 | (-0.346712+0j), 225 | (-1.74086+0j), 226 | (-1.68963+0j), 227 | (-0.292976+0j), 228 | (-0.275681+0j), 229 | (-1.67149+0j), 230 | (-1.75726+0j), 231 | (-0.36566+0j), 232 | (-0.211619+0j), 233 | (-1.59566+0j), 234 | (-1.8176+0j), 235 | (-0.444548+0j), 236 | (-0.155077+0j), 237 | (-1.5139+0j), 238 | (-1.8702+0j), 239 | (-0.528794+0j), 240 | (-0.106684+0j), 241 | (-1.42738+0j), 242 | (-1.91428+0j), 243 | (-0.617472+0j), 244 | (-0.066951+0j), 245 | (-1.33675+0j), 246 | (-1.94957+0j), 247 | (-0.709831+0j), 248 | (-0.036195+0j), 249 | (-1.24289+0j), 250 | (-1.97572+0j), 251 | (-0.8051+0j), 252 | (-0.0146914+0j), 253 | (-1.14656+0j), 254 | (-1.9925+0j), 255 | (-0.902128+0j), 256 | (-0.00269985+0j), 257 | (-1.04895+0j), 258 | (-1.9997+0j)] 259 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Adafruit-Blinka 2 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | """A setuptools based setup module. 2 | 3 | See: 4 | https://packaging.python.org/en/latest/distributing.html 5 | https://github.com/pypa/sampleproject 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | # To use a consistent encoding 10 | from codecs import open 11 | from os import path 12 | 13 | here = path.abspath(path.dirname(__file__)) 14 | 15 | # Get the long description from the README file 16 | with open(path.join(here, 'README.rst'), encoding='utf-8') as f: 17 | long_description = f.read() 18 | 19 | setup( 20 | name='adafruit-circuitpython-fft', 21 | 22 | use_scm_version=True, 23 | setup_requires=['setuptools_scm'], 24 | 25 | description='CircuitPython FFT Library', 26 | long_description=long_description, 27 | long_description_content_type='text/x-rst', 28 | 29 | # The project's main homepage. 30 | url='https://github.com/adafruit/Adafruit_CircuitPython_FFT', 31 | 32 | # Author details 33 | author='Adafruit Industries', 34 | author_email='circuitpython@adafruit.com', 35 | 36 | install_requires=[ 37 | 'Adafruit-Blinka' 38 | ], 39 | 40 | # Choose your license 41 | license='MIT', 42 | 43 | # See https://pypi.python.org/pypi?%3Aaction=list_classifiers 44 | classifiers=[ 45 | 'Development Status :: 3 - Alpha', 46 | 'Intended Audience :: Developers', 47 | 'Topic :: Software Development :: Libraries', 48 | 'Topic :: System :: Hardware', 49 | 'License :: OSI Approved :: MIT License', 50 | 'Programming Language :: Python :: 3', 51 | 'Programming Language :: Python :: 3.4', 52 | 'Programming Language :: Python :: 3.5', 53 | ], 54 | 55 | # What does your project relate to? 56 | keywords='adafruit blinka circuitpython micropython fft ifft', 57 | 58 | # You can just specify the packages manually here if your project is 59 | # simple. Or you can use find_packages(). 60 | # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, 61 | # CHANGE `py_modules=['...']` TO `packages=['...']` 62 | py_modules=['teaandtechtime_fft'], 63 | ) 64 | -------------------------------------------------------------------------------- /teaandtechtime_fft.py: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | # 3 | # Copyright (c) 2019 Tom Schucker for Tea and Tech Time 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 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 21 | # THE SOFTWARE. 22 | """ 23 | `teaandtechtime_fft` 24 | ================================================================================ 25 | 26 | CircuitPython FFT Library 27 | 28 | 29 | * Author(s): Tom Schucker 30 | 31 | Implementation Notes 32 | -------------------- 33 | 34 | **Hardware:** 35 | 36 | **Software and Dependencies:** 37 | 38 | * Adafruit CircuitPython firmware for the supported boards: 39 | https://github.com/adafruit/circuitpython/releases 40 | 41 | """ 42 | 43 | # imports 44 | from math import pi, sin, cos, sqrt, pow, log 45 | from adafruit_itertools import islice, count 46 | import array 47 | 48 | __version__ = "0.0.0-auto.0" 49 | __repo__ = "https://github.com/tschucker/Teaandtechtime_CircuitPython_FFT.git" 50 | 51 | #Computes the complex fft of the input array needs to be power of 2 length to work. 52 | def fft(x): 53 | N = len(x) 54 | if N <= 1: return x 55 | even = fft(list(islice(x,0,N,2))) 56 | odd = fft(list(islice(x,1,N,2))) 57 | T = [cos(2*pi*k/N)*odd[k].real+sin(2*pi*k/N)*odd[k].imag + (cos(2*pi*k/N)*odd[k].imag-sin(2*pi*k/N)*odd[k].real)*1j for k in range(N//2)] 58 | return [even[k].real + T[k].real + (even[k].imag + T[k].imag)*1j for k in range(N//2)] + \ 59 | [even[k].real - T[k].real + (even[k].imag - T[k].imag)*1j for k in range(N//2)] 60 | 61 | #Computes the complex inverse fft of the input array needs to be power of 2 length to work 62 | #not the most efficiant but uses the same fft code. 63 | def ifft(x): 64 | fft_len = float(len(x)) 65 | x_swap = [] 66 | for s in x: 67 | x_swap.append(s.imag + s.real*1j) 68 | temp = fft(x_swap) 69 | temp_swap = [] 70 | for s in temp: 71 | temp_swap.append((s.imag/fft_len) + (s.real/fft_len)*1j) 72 | return temp_swap 73 | 74 | #Computes the double sided spectrogram of the input array needs to be a power of 2 to work 75 | def spectrogram(x): 76 | freq = fft(x) 77 | temp_list = [] 78 | for f in freq: 79 | abs_val = abs(f) 80 | if abs_val != 0.0: 81 | temp_list.append(int(log(abs_val))) 82 | else: 83 | temp_list.append(0) 84 | return temp_list 85 | 86 | --------------------------------------------------------------------------------