Extracting Signals from Noise and Other Distractions
Extracting an actual signal from real world noise is one of the most important skills of embedded software engineers. Noise, bias fluctuations based on temperature, and a plethora other distractions can stand between you and the data you need for your project. This month, Bob shows us how to extract the true signal without introducing other errors, through digital filtering.
When I first got out of college, I worked on the Apollo Lunar Excursion Module’s (LEM) backup guidance system (later referred to as the Lunar Module or LM). My initial job was testing and analyzing the gyros used in our design. Gyro drift and noise were huge issues to be solved in maintaining the accuracy of these systems. I did my analysis on a Friden calculating machine (Figure 1). (You can watch a video of the Friden’s inner workings, and playing the Friden March on YouTube [1]).
It was at that time that I was introduced to Kalman filters. Used extensively in navigation, guidance and vehicle control, the Kalman filter uses an algorithm that takes past inputs and a statistical knowledge of the noise footprint to predict the state of the system.
I was so ignorant of the actual workings and applicability of this filter that, in the mid-70s, I planned to create the first hand-held musical instrument tuner using Kalman filtering. I explained my plan (without disclosing the “how”) to a technical editor from Byte magazine, while he was jamming with some friends at our house. He told me that creating such a tuner had been tried unsuccessfully many times before. The problem was filtering out the fundamental frequency. In a “smarter than thou” mode, I said that I planned to use a Kalman filter to extract the frequency—a completely bogus application of the filter. Thankfully he didn’t roll his eyes.
This month, we will look at a few filtering algorithms that are applicable to the embedded systems we design, beginning with some general guidelines. It’s an immense and important topic, but of course, I will address it in thin slices.
GENERAL GUIDELINES
Know Your Inputs: A few years back, my grandson and I tried to create a radar gun to measure the speed of his baseball pitches. We had purchased one off-the-shelf, but it had several practical problems with its use—one of which was that his sinker kept hitting it! So necessity was the mother of invention, and we tried to build our own. Eventually we got stymied with devising a filter algorithm on the signal. Our sensor did not output velocity, but distance. And how do you get velocity from distance? By dividing the distance differences over a time interval. That was the easy part. The problem was the noise on the line.
Different filters are needed when you are measuring a relatively stable input, such as the outdoor temperature, that doesn’t change rapidly, compared to a signal whose data is rapidly changing. A 90mph fastball travels 60.5 feet in 430ms (okay – he only throws 88mph). Thus, the distance from the gun to the ball is decreasing rapidly. So, your first step in designing your filter is to characterize the input you are going to filter: what is the data supposed to look like without any noise?
Know Your Noise: In designing good input filters, knowing your inputs is imperative, but it’s also important to know your noise. I remember once applying a filter to an electrode coming from the heart, and seeing what looked like just a bunch of noise transformed to the standard QRS waves. (Q is the first negative-going signal; R is the first positive-going signal; and S is the second negative-going signal). This filter algorithm was provided to us, and included a low-pass, a band-pass, a high-pass, and a notch filter. To design a good input filter, we need to know the characteristics of the noise on our signal. Is it all high frequency noise? Is it 60Hz hum? Or is it as complicated as an EKG signal? Knowing your noise will be an important step in designing your filter.
Sampling Rate: Once you have become familiar with your inputs and the associated noise on the input, you need to choose a sampling rate for your digital filter. The sampling rate is the number of times every second that you read an analog or digital input. We have to carefully choose our sample rate. Too slow, and we may experience aliasing—extracting data that is not accurately reflecting the actual data.
We have all seen aliasing on TV where the sample rate of the camera (frames per second) causes wagon wheels or helicopter blades to look like they are standing still or even going backwards. Figure 2 graphically shows how a too-slow sample rate can cause us to see one frequency, when the data is really another frequency. Notice how our under-sampled samples would yield a filtered signal oscillating at a frequency eight times slower than the actual signal.
Work done at the turn of the 20th century by E. T. Whitaker, and further developed by Henry Nyquist and Claude Shannon, demonstrated that the sampling rate necessary to avoid aliasing must be at least twice the bandwidth of the input signal.
However, that is just one factor that affects sample rate. Imagine you are designing a breath detector to determine when to dispense oxygen to a patient. If you can dispense the oxygen only when it is needed, you can reduce the total amount of oxygen delivered, and still deliver the amount that the patient needs. If we used an analog pressure sensor and knew that the maximum breath rate we would see would be 1Hz, then according to the Whitaker-Nyquist-Shannon sampling theorem, we would need to sample it at least a 2Hz rate to guarantee we didn’t miss a breath.
But wait! It isn’t as simple as applying the Whitaker-Nyquist-Shannon theorem to our data. There is a point in the breath pressure curve that we want to trigger the oxygen. Let’s say that we want to output the oxygen within 50ms after the “breath in” starts. To achieve that, we need to break the 1-second breath cycle into 20 samples of 50ms each—and then apply the Nyquist-Shannon theorem to the resulting 20Hz. A reasonable rule of thumb we have used is 4-10 times the sample rate, or in this case, an 80 – 200Hz sample rate.
Too high a sample rate may exhaust the available real time to perform other tasks.
Cutoff Frequency: The cutoff frequency is the point either above or below which the filter begins or ceases to take effect. This is controllable by the type of filter you choose and the parameters that you apply. Ideally you want it as near to the noise as possible, but other tradeoffs may make that impossible.
Acceptable Lag: Based on the sample size and your cutoff frequency, your filter will induce a lag in your system. We always must make tradeoffs with filters—lower noise comes at the expense of, among other things, more lag. Lag can make a mess of feedback control systems, so make sure you take that into account. This where modelling your control system is so important. Each filter has its own characteristics for the amount of lag you will induce by applying the filter.
Know the Filter Options: Here is a brief summary of some of the options we have for digital filters.
- FIR/IIR Filters – Finite Impulse Response/Infinite Impulse Response filters are really a category of filters. FIR filters are used to limit the effect of impulse inputs to your input stream. A moving average filter is a simple FIR filter. While a FIR filter retains the impact of an impulse input for only a finite period of time, an IIR will retain the impact of an impulse for a long time (not infinitely, but a long time).
Generally, a FIR filter is more computationally and memory intensive than a IIR filter. If your processor does not have floating-point arithmetic, and you are implementing your algorithm in fixed-point arithmetic, then using a FIR filter will reduce the quantization effect. Quantization errors occur by introducing round-off errors in your calculations, underflow and overflow of the dynamic range of your signal, and error accumulation. Quantization happens when using either floating-point or fixed-point math, but can be more pronounced with fixed-point math, because it has less dynamic range and precision than floating-point math. What is fixed-point arithmetic? I am glad you asked; it’s the subject of my next column.
- Low-pass filters – A good low-pass filter will allow your lower-frequency signals in, while keeping higher frequencies out. An algorithm for a low-pass filter can be built from this fundamental line of C code:
output = output + filter_constant * (input – output);
Perform this algorithm every time you sample the input. To determine the filter_constant, take the sample period (let’s say 0.1ms) and divide it by the period of the desired cutoff frequency. If the cutoff frequency is 500Hz, the period is 2ms.
I created a Python program with the above algorithm, and you can see the results of a low-pass filter on a 1Hz signal with a lot of random noise on top of it. Figure 3 is the signal and the noise. Figure 4 and Figure 5 are the outputs of our low-pass filter, using different filter constants. Notice the lag introduced when we changed the cut-off frequency from 100Hz to 20Hz. The Python program is available for download on the Circuit Cellar Article Materials and Resources webpage. Play with sample period and cutoff frequency to observe their effects.
- High-pass filters – A good high-pass filter will allow your higher-frequency signals in, while keeping lower frequencies out. There are many different algorithms to choose from. Each works better than the other, depending on your desired input and your noise profile.
A Butterworth filter will provide a flat frequency response above the passband (the frequencies above the cutoff frequency). A Chebyshev filter will have a steeper cutoff than the Butterworth, but will induce some ripple in the passband. The wide array of options—all that have C and Python code available on the web—are the reasons you need to know what you want the output coming out of the filter to look like. How much ripple is acceptable? How much lag you can tolerate?
A simple high-pass filter algorithm would be:
output = filter_constant * (output + input – last_input);
where filter_constant is the time constant/(time constant + sample period)
- Band-pass filters – A good band-pass filter will allow a specific range of frequencies through, while attenuating frequencies outside that range. You can create a band-pass filter by combining a low-pass filter and a high-pass filter.
- Notch filters – A good notch filter will reduce inputs at a specific frequency. We often use them to eliminate hum from A/C power coming in (50Hz or 60Hz).
- Outlier Filter – If your data is subject to some samples widely differing from the norm, an outlier filter can simply remove the highs and the lows from the sample. You can add an outlier filter before any of the above filters.
- Sliding Window Average – For slow-moving signals with minimal noise, one can create a moving window of 10 samples and average them. This will induce a lag in the system, but that may be acceptable.
WHICH FILTER TO USE?
There are good tools out there that will help you to design the digital filter based on your data. If you are coding- adverse and are not cash limited, MatLab [2] might be your better choice. I prefer Python with its open source library, “matplotlib” [3] and “scipy” [4]. With MatLab it’s like that old ad for The Outer Limits TV show: “We control the horizontal. We control the vertical.” With Python, you are in full control. With both, you can input a data set of your actual data (noise and all) and determine what filter and what parameters (cutoff frequency, sample rate, and others) you will use, and then find the filter that works best for your data. But with both, the options can be staggering.
Thin Slices of Filter Facts
It seems like with every article I write, I delve into topics about which whole books can be written. Oh, did you say there already are books written about digital filter design? Yes! There are more than 20 books on this topic just on Amazon. But we tackled it in thin slices. It’s a noisy world out there. Knowing how to design good, effective, and efficient digital filters is a valuable tool to have in your tool box.
In my next column, I am going to introduce you to fixed-point arithmetic. When I started in this business 50 years ago, the first microcontroller had just become available commercially. No microcontroller had a floating-point processor, and we had to do all arithmetic in fixed point. We landed on the moon with fixed-point arithmetic. Doing more with less often means doing serious math on a tiny PIC processor. Knowing how to do this can save you bundles in recurring costs on your next project.

Check out the Python Low Pass Filter lowPass.py (in the code file link). Make sure you install the “matplotlib” library prior to running.
REFERENCES
[1]https://www.youtube.com/watch?v=-MLQ0yI1BrQ This video demonstrates how the Friden divides, and shows how you can play the “Friden March” as portrayed in the Jack Lemon film, The Apartment.
[2] https://www.mathworks.com/products/matlab.html Use Matlab to evaluate your actual data to the algorithms you will be using to create the digital filter you need.
[3] https://matplotlib.org/ A comprehensive library for creating static, animated, and interactive visualizations in Python.
[4] https://scipy.org/ This library for Python is extensive and allows you to do what you do with Matlab in designing your digital filters.
PUBLISHED IN CIRCUIT CELLAR MAGAZINE • AUGUST 2025 #421 – Get a PDF of the issue
Sponsor this ArticleBob Japenga has been designing embedded systems since 1973. From 1988 - 2020, Bob led a small engineering firm specializing in creating a variety of real-time embedded systems. Bob has been awarded 11 patents in many areas of embedded systems and motion control. Now retired, he enjoys building electronic projects with his grandchildren. You can reach him at
Bob@ListeningToGod.org






