Skip to main content

The Python Fixed Point module

Project description

pyPhix, the Python Fixed Point module

pyPhix is a python package for fixed point number representation. It is intended to support the implementation of digital signal processing systems. As such only fix-point addition, subtraction and multiplication operations are implemented.

You can find more information about the module objects and functionalities at readthedocs project page.

Features

  • virtually unlimited number length (depending on your RAM size)
  • based on NumPy
  • customizable rounding method (SymInf, SymZero, NonSymPos, NonSymNeg, ConvEven, ConvOdd, Floor, Ceil)
  • customizable wrapping method (Sat, Wrap)
  • support various representation formats (bin, hex, int, float)
  • perform single or array based operations with customizable output format (+, -, *)

License

pyPhix

pyPhix is an open source python module released under the terms of Mozilla Public License Version 2.0.

NumPy

NumPy is the fundamental package needed for scientific computing with Python and it is released under these terms.

Install

The pyPhix package is available on pypi.org. You can install it by running:

$ pip install pyphix.

Alternatively you can clone the pyPhix repository and from the folder containing the setup.py file run:

$ python setup install

This package requires Python 3.6 to work.

You can also directly download the tar.gz archive from pypi.org. The archive can be easily verified by adding the gpg public key 1E948096166391C0 to your keyring.

Usage Examples

Fix Format

This object is used to indicate the number of bits the user wants to use for value reprensetation.

Create fix-point format objets:

>>> from pyphix import fix
>>> fmt_a=fix.FixFmt(True, 2, 10)
>>> fmt_b=fix.FixFmt(False, 0, 7)

Print the maximum representable ranges and test if a value is included in the range:

>>> fmt_a.fixrange
(-4.0, 3.9990234375)

>>> fmt_b.fixrange
(0.0, 0.9921875)

>>> -10 in fmt_a
False

>>> 0 in fmt_b
True

Different representations are available:

>>> fmt_a.tuplefmt
(True, 2, 10)

>>> fmt_b.listfmt
[False, 0, 7]

>>> print(fmt_b)
(False, 0, 7)

Fix Number

This object contain fix-point number represenation.

Round methods comparison, assuming format (True, 4, 5):

Round method Pos odd fraction Pos even fraction Neg odd fraction Neg even fraction
Real value 7.296875 2.325 -1.078125 -1.08125
Mult by 2^5 233.5 74.4 -34.5 -34.6
SymInf 7.3125 2.3125 -1.09375 -1.09375
SymZero 7.28125 2.3125 -1.0625 -1.09375
NonSymPos 7.3125 2.3125 -1.0625 -1.09375
NonSymNeg 7.28125 2.3125 -1.09375 -1.09375
ConvEven 7.3125 2.3125 -1.0625 -1.09375
ConvOdd 7.28125 2.3125 -1.09375 -1.09375
Floor 7.28125 2.3125 -1.09375 -1.09375
Ceil 7.3125 2.34375 -1.0625 -1.0625

A small usage example:

>>> from pyphix import fix
>>> from pyphix.fix import ERoundMethod, EOverMethod
>>> fmt = fix.FixFmt(True, 4, 5)
>>> fix_vec = fix.FixNum(
        [7.296875,  2.325   , -1.078125, -1.08125], fmt,
        rnd=ERoundMethod.CONV_ODD, over=EOverMethod.WRAP)
>>> fix_val = fix.FixNum(
        1.16, fmt,
        rnd=ERoundMethod.CONV_ODD, over=EOverMethod.WRAP)

Perform a full resolution addition:

>>> fix_vec + fix_val
[8.4375  3.46875 0.0625  0.0625 ]

  fmt: (True, 5, 5)
  rnd: ERoundMethod.CONV_ODD
  over: EOverMethod.WRAP

Perform a multiplication and cast result to a small format:

>>> fix_val.mult(
        fix_vec, out_fmt=fix.FixFmt(False, 3, 2),
        rnd=ERoundMethod.SYM_INF, over=EOverMethod.SAT)
[7.75 2.75 0.   0.  ]

  fmt: (False, 3, 2)
  rnd: ERoundMethod.SYM_INF
  over: EOverMethod.SAT

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyPhix-0.1.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyPhix-0.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file pyPhix-0.1.tar.gz.

File metadata

  • Download URL: pyPhix-0.1.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.4

File hashes

Hashes for pyPhix-0.1.tar.gz
Algorithm Hash digest
SHA256 8cb87ee23c280fb8a506904b9d7f8d80cd97cf89eea6fe4efe90857e3eb841cf
MD5 61e7078d05adc8c2836d4c0fb58111b6
BLAKE2b-256 e93208bebf0e22dc65f5a7c72f4769ded3760a01eaeadd5b1a309592307ae65e

See more details on using hashes here.

File details

Details for the file pyPhix-0.1-py3-none-any.whl.

File metadata

  • Download URL: pyPhix-0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.4

File hashes

Hashes for pyPhix-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f421cae379f0603178c4ffb01b069dbe1c9c2a6891498b728d9a7842b0bc5680
MD5 b4b5da9203296efbe404c8576e61225b
BLAKE2b-256 79cb5b89e63acddfeb8b33b75d70dcfe4c9f568ae4f11de6f8630093cbcd7655

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page