Engineers Who Code!
Tags: programming, python, linux, engineering
Published: 2022-11-24 18:55:34

As an electrical engineer hoping for the occasional engineering article, I sometimes feel a little lonely here.  :-)  Maybe this short note kick starts talking/sharing among other code writing engineers.  Or at least see how many of us there might be here.  My work is predominantly DSP, Digital Signal Processing, applied to RF signals.  I work on things like signal creation from IEEE WiFi specs, RF angle of arrival, cyclostationary signal processing, and similar.  Tying this into a topic possibly of more interest to the group is that my work week is not just mostly mathematical, but in particular math with complex numbers.  Matlab/Octave is the most well known with strong support for complex mathematics, but I prefer python because of the strong user community.  I'll go off on a tangent (yup, bad math pun) about complex numbers while sharing some background.

Computer languages started out heavily oriented to scientists and engineers.  The result was language support for complex numbers, e.g., the venerable Fortran.  As computer use evolved, support for complex numbers waned.  They weren't even in C until, I think, C99.  I suppose it is a semi-niche need.  But when you happen to live in that niche, it is uncomfortable without the support.  Languages like Matlab and python are so popular because in addition to built-in complex numbers, there are many libraries using them from filter design and signal manipulation to general complex functions like FFTs, or Fast Fourier Transforms.

I work in an RF lab with radios, lab gear and DSP code that all revolve around I/Q signals, which stands for in-phase/quadrature.  I enjoy python because i/q signals are so easily expressed and used.  Quadrature comes up a lot in electrical engineering and simply means that you have two signals and one is a "quad," or 90/360 degrees, out of phase with the other.  Two things 90 degrees apart, hmm, sounds a lot like Cartesian coordinates or maybe even...complex numbers!  The two signals are in fact very real, in the sense that they're made up of electrons or samples, but we'll call one "real" (in the mathematical sense) and the other "complex."  Euler teaches us that cos(x) + j sin(x) = exp(jx).  EEs call them I/Q signals, and exp(jx) bundles up so much so succinctly.

A simple example is a radio station.  The DJ's voice is at very low audio frequencies and must be mixed, or shifted, up to the radio station's assigned carrier frequency like 103.1 MHz.  If the DJ's voice is sampled at time intervals in a vector (array) named t_s meaning time in units of seconds, and stored in a vector voice_iq, and the radio station is assigned a carrier fc_Hz = 103.1e6, it is simple in python to create a carrier and mix the voice:

`carrier_iq = exp(2j * pi * fc_Hz * t_s)
mixed_iq = voice_iq * carrier_iq`

The vectors t_s, voice_iq, and carrier_iq contain many thousands of samples and are not scalar.  Imagine the ugliness of doing that in Java or other languages that don't natively support complex numbers.  I suffered it on a project once...doable but painful.  Python makes life as an EE so comfortable!  (And that doesn't even touch on control of lab gear with SCPI in python, a topic on laboratory automation.)

That's some background how a programming language is put to use in my work environment.  For the slice of the professional universe where I live, python is great.  I am very interested to hear of scientific and engineering coding applications of others and why you chose the languages & tools you use.