Python-based Digital Signal Processing Materials for use in DSP classes
This repository contains a collection of Python functions designed to simulate fundamental Digital Signal Processing (DSP) operations. It is intended for students and educators to visualize and manipulate discrete-time signals, replicating standard MATLAB DSP toolboxes in a Pythonic environment.
To run the scripts and functions in this repository, you will need:
- NumPy: For array manipulation and mathematical operations.
- Matplotlib: For plotting and visualizing signals.
To install the required libraries, run:
pip install numpy matplotlibImport the functions from the main module sigfunctions.py into your script:
import numpy as np
import matplotlib.pyplot as plt
from sigfunctions import stepseq, sigshift, sigaddGenerates a unit sample sequence (impulse)
- Returns: n (time vector), x (signal array)
Generates a unit step sequence
- Returns: n (time vector), x (signal array)
Shifts a signal
- Returns: y (shifted signal), n (new time vector)
Folds (time-reverses) a signal about
- Returns: n (folded time vector), y (folded signal)
Decomposes a real signal
- Returns: xe (even part), xo (odd part), m (symmetric time vector)
Adds two signals
- Automatically aligns time vectors and handles zero-padding.
- Returns: y (summed signal), n (common time vector)
Multiplies two signals
- Returns: y (product signal), n (common time vector)
Computes the convolution
- Returns: y (convolved signal), ny (resulting time vector)
Computes the correlation
- Returns: y (convolved signal), ny (resulting time vector)
Computes the Discrete-Time Fourier Transform.
- Parameters: k (frequency index range), delta (frequency step size in radians).
- Returns: w (frequency vector), X (computed DTFT values)
Numerical approximation of the Continuous-Time Fourier Transform.
- Returns: t (time vector), x (sampled signal), W (freq vector), Xa (approximate CTFT)
Computes the Discrete Fourier Transform.
-
Returns: Xk (DFT coeff. array over
$0 \leq k \leq N-1$ )
Computes the inverse Discrete Fourier Transform.
-
Returns: xn (N-point sequence over
$0 \leq n \leq N-1$ )
import numpy as np
import matplotlib.pyplot as plt
from sigfunctions import stepseq, sigadd
# 1. Generate two step sequences
n1, x1 = stepseq(0, 10, 0)
n2, x2 = stepseq(5, 15, 0)
# 2. Add them together (handles different time ranges automatically)
y, n = sigadd(x1, n1, x2, n2)
# 3. Plot
plt.stem(n, y)
plt.title("Signal Addition Example")
plt.xlabel("n")
plt.ylabel("Amplitude")
plt.show()