Skip to main content

Package to generate PWL incrementally using little 'events' like rectangular pulses and exponential rising or falling edges.

Project description

pwl_writer

by Victor Sabiá P. Carpes

Tested on:

  • python 3.6.6
    • numpy 1.19.5
    • matplotlib 3.3.4
  • python 3.11.1
    • numpy 1.25.0
    • matplotlib 3.7.1

Type stubs for older numpy versions for mypy checking can be found here.

Summary

This package defines a class PWL to generate objects that represent time dependent signals $x(t)$ that need to be coded in a PWL file. Those objects are built using little components such as rectangular pulses and sawtooth pulses that can be chained together.

Motivation

The motivations for this package are the nuisances of writing PWL files by hand. To properly explain this, let's discuss how PWL files work.

PWL stands for piecewise linear. A PWL file is a way to represent a time dependent signal (referenced by $x(t)$ from now on) for simulation softwares such as LTspice and Cadence Virtuoso. In it, points of the form $(t, x)$ are stored. During simulation, those points are interpolated with first degree polynomials. This poses 2 problems:

  1. Due to the linear interpolation, the resulting signal is continuous. This tends to be desirable, but if the intention is moddeling, for example, rectangular pulses, each transition will need 2 points with very close time coordinates to approximate a discontinuous transition. This can get extremely tedious to code out by hand.
  2. Each point has an absolute time coordinate with respect to the origin. If the desired signal is for example a series of rectangular pulses with certain durations and for some reason the duration of the first pulse is changed, all the following points will need to have their time coordinates changed as well.

This package solves both problems by providing an abstraction layer. They are solved by the 2 following features:

  1. A minimal timestep is defined at the creation of the PWL object that is used to automatically generate all the needed transitions for any discontinous transition.
  2. The signal is built using small building blocks (such as rectangular pulse and exponential transition) called events that are defined in terms of durations. That is to say, time is treated in a differential fashion. The time coordinates from a given event are all with respect to the final instant of the previous event. For example, let's assume we want to model a rectangular pulse with amplitude 1 and duration 1 second followed by a downtime at zero for 10 seconds and then another rectangular pulse with the same duration and amplitude. If we change the duration of the first pulse to 2 seconds, the downtime and second pulse will be both delayed by the 1 second but retain their durations.

Another advantage of using this package is not a feature per se but more a consequence of using a programing language. That advantage is simply that all those events can be added inside for loops, if clauses and functions, allowing for greater flexibility. For example, let's assume we want to control a system that can be in the following states:

  • Idle
  • Mode 1
  • Mode 2

For each state, various control signals need to be at specific values. We could create a PWL object for each control signal and define 3 functions that apply all the needed values for the control signals for each state. If we nedded the system to be at mode 1 for 3 seconds, idle for 1 second and at mode 2 for 5 seconds, we could write something like the following:

mode1_state(3)
idle_state(1)
mode2_state(5)

How to Install

To install, simply run one of the following commands:

pip install pwl_writer
pip3 install pwl_writer

Documentation

Full documentation for the package can be found here. It was written with Pycco.

Project details


Download files

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

Source Distribution

pwl_writer-1.1.1.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

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

pwl_writer-1.1.1-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file pwl_writer-1.1.1.tar.gz.

File metadata

  • Download URL: pwl_writer-1.1.1.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.27.1

File hashes

Hashes for pwl_writer-1.1.1.tar.gz
Algorithm Hash digest
SHA256 b69a0743a8f39771bdbfcd83a5057e462df02b85be5ee5519af1e4e450dea8da
MD5 4f86ddd210c76cd47a82e67e6e028a97
BLAKE2b-256 f80ac51cdf5c2400f71e95e24d3bdd361aa949da55416caf3ddc427201c6247c

See more details on using hashes here.

File details

Details for the file pwl_writer-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: pwl_writer-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.27.1

File hashes

Hashes for pwl_writer-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1f84733447f24dc9cbac2e0f152759fbc031c74c9ae5f3afd2f32d0b32f07d13
MD5 20e7dd1a43222460519affef5d8f40fc
BLAKE2b-256 a890c4cd5f56499063e6bab1135f98cd77957e3659f0b5f371ea0cf1f7d63270

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