Skip to main content

DSPFTW

Starting points and helper functions for learning digital signal processing.

Setup

If you haven't already, install Python 3.5 or greater, and the dspftw package.

python3 -m pip install dspftw --user

Intro

Decomposition

Superposition: The foundation of DSP

Sinusoids

Prefer to use the complex exponential form instead of real, as it's a more natural fit for fourier analysis and synthesis.

The following functions represent a complex sinusoid. They are equivalent, and take the same parameters:

  • A = Amplitude (y axis is amplitude).
  • f = Frequency (cycles per second) in Hertz. It is multiplied by 2π to get radians per second.
  • t = Time in seconds. These functions work in the time domain (x axis is time).
  • ϕ = Phase offset at t=0, in radians.
z(t) = A*exp(j*(2π*f*t+ϕ))

z(t) = A*cos(2π*f*t+ϕ)+j*A*sin(2π*f*t+ϕ)

We can define this in Python with the following.

import numpy as np

# Here we use the name "complex_sinusoid" instead of just "z".
def complex_sinusoid(A, f, t, phi): return A * np.exp(1j*(2*np.pi*f*t+phi))

In fact, this is defined in the dspftw package, so let's import that.

import dspftw

We can create our own sinusoid by defining everything except t.

def my_sinusoid(t): return dspftw.complex_sinusoid(A=5, f=5, t=t, phi=0)

We can get the signal at a bunch of times thanks to numpy arrays. We use numpy.linspace to generate the evenly spaced times.

import numpy as np
times = np.linspace(0, 1, num=25)  # 25 evenly spaced values between 0 and 1
my_signal = my_sinusoid(times)  # returns an array of complex values representing the signal

Now plot it out with dspftw.plot_complex(), which uses matplotlib.

import matplotlib.pyplot as plt
dspftw.plot_complex(my_signal)
plt.show()

Complex Exponential Signals

Roots of Unity

Roots of Unity Animation

Wolfram Mathworld

Delta Function

Conjugate

Complex Conjugate

Convolution

Convolution

Correlation

numpy.correlate

Kronecker Product

numpy.kron

Sample Signals

SigIDWiki sample signals

Loading Signals

Complex 8 bit

import numpy as np
signal = np.fromfile('filename', dtype='b')  # load the whole file
signal = np.fromfile('filename', dtype='b', count=1024)  # only load the first 1024 bytes of the file
signal = np.fromfile('filename', dtype='b', offset=1024)  # skip the first 1024 bytes of the file
signal = np.fromfile('filename', dtype='b', offset=1024, count=1024)  # skip 1024, then load 1024

This just loads the values as an array of real numbers, but we want it as complex. We have to interpret every other value as the imaginary component.

signal = signal[0::2] + signal[1::2]*1j

Complex 32 bit float, little-endian (x86)

signal = np.fromfile('filename', dtype='<f')

count and offset work as above, but note that offset is in bytes, so you must multiple by 4 since there are 4 bytes in 32 bits.

Complex 32 bit float, big-endian

signal = np.fromfile('filename', dtype='>f')

count and offset work as above, but note that offset is in bytes, so you must multiple by 4 since there are 4 bytes in 32 bits.

Download files

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

Source Distribution

dspftw-2024.168.206.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

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

dspftw-2024.168.206-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file dspftw-2024.168.206.tar.gz.

File metadata

  • Download URL: dspftw-2024.168.206.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.4

File hashes

Hashes for dspftw-2024.168.206.tar.gz
Algorithm Hash digest
SHA256 81944389110b754cd38875216eab19ff7de1a095f811493633b022be150e2529
MD5 0a32b46f779d77f2a86a96c0f86686d3
BLAKE2b-256 10a11ff940cccbfc41a19ce03f4b1bdc65a4fa3e292dd9b0359d7e3b1561b4ac

See more details on using hashes here.

File details

Details for the file dspftw-2024.168.206-py3-none-any.whl.

File metadata

  • Download URL: dspftw-2024.168.206-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.4

File hashes

Hashes for dspftw-2024.168.206-py3-none-any.whl
Algorithm Hash digest
SHA256 7a946960198038f50075118f4c05a326dba285fb37814c6f5c18d64af284edfc
MD5 de40f84f0ac84f6e0c45e15bfe51cd55
BLAKE2b-256 4999225c80dfe89bcde55d68048ebe1eb84fb36492216d632f5cb15f55c0c74a

See more details on using hashes here.

Release history Release notifications | RSS feed

2024.272.181

2 files

2024.272.178

2 files

2024.206.219

2 files

2024.170.85

2 files

This release

2024.168.206 This release

2 files

2024.168.184

2 files

2021.301.640

2 files

2021.273.156

2 files

2021.271.684

2 files

2021.224.899

2 files

2021.224.869

2 files

2021.132.1012

1 file

2021.111.1016

1 file

2021.111.1010

1 file

2021.111.873

1 file

2021.90.1052

1 file

2021.90.938

1 file

2021.90.922

1 file

2021.90.900

1 file

2021.84.800

1 file

2021.84.798

1 file

2021.83.1005

1 file

2021.83.974

1 file

2021.83.889

1 file

2021.83.878

1 file

2021.83.865

1 file

2021.69.1124

1 file

2020.251.0

1 file

2020.250.1

1 file

2020.250.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page