In previous blogs we discussed emerging opportunities like health monitoring in smart wearable technologies, home automation and LED lighting, with new technologies and emerging applications that are only limited by our imaginations! Common to all of these technologies and applications, is the design of the hardware and signal processing algorithms which make these sensors come alive and communicate, which as embedded designers, can be as interesting as the technologies themselves!

Today, I would like to share some signal processing ideas and identify some pitfalls that seem easy to fall into if we are not careful. We also want to make available to you a free signal processing tool that you can download from the Occammd website. The tool will demonstrate the concepts in this blog, as well as many techniques that we will touch on in future blogs and articles. If you have any questions or comments that we can share together as you go through this, or new blogs that you would like to see, please let us know.

Occasionally, as embedded designers, we don’t always have the luxury of designing a system from the ground up. In some cases, the processor and sensors have been selected, software is written and a prototype has been built before we get to it. All we need to do is “get it all working”! The good news is that the design constraints around these kinds of situations can often represent some of the more challenging problems to solve, and as a result, are very interesting to work on.

I had a situation like this a few years ago that involved a control loop for a pumping system that was being implemented on an 8-bit microprocessor. As shown in Figure 1, the control loop adjusted the voltage/speed of the pump motor to hold a constant pressure set point. The assumption was that the motor control loop was messed up, but in reality, sensor and A/D limitations, along with signal processing methods that were biasing the pressure feed-back data to the motor control loop were the key issues. Essentially, since garbage was being feed to the motor control loop, garbage was coming out and the system would not function properly. Market urgency to get a working prototype out required every attempt at “fixing” the system without changing the hardware.

It is often the case, that once the overall system has been evaluated; there are signal processing techniques that can be implemented to assist with improving the overall system performance. In this situation, the pressure transducer was responding to the pump with a sinusoidal bias that was equal in frequency to the rotational frequency of the pump. Let’s walk briefly through the issues and solutions, not so much to identify specifics about the system parameters, but in a manner that the basic principles being discussed can be applied to systems, and/or similar signal processing scenarios, that you may be working on.


Common Pitfall

In the described system scenario, algorithms had already been implemented in software to “filter out” the unwanted sinusoid that was biasing the control loop. However the system also had signal-to-noise ratio (SNR) issues, so moving averages were implemented along with an increase in the sampling rate which changed the characteristics of filtering algorithms that had been previously implemented by another group. This is a common pitfall. Changes are made to the sampling rate of the data, without considering the effect on digital filtering algorithms that are also being implemented. This can be done not only by changing the sampling rate of the A/D hardware, but also by averaging samples before sending them to a filtering algorithm, which changes the effective sampling rate, and therefore response of the filter using that data. Later, we will leverage this characteristic of digital filters in our solution, but if not handled correctly, it can cause problems within an embedded system.

Also recall that moving averages are simply FIR filters with all the coefficients set to 1/N, where N is the number of taps being used in the filter. There is a white paper on the Occammd website that addresses techniques for increasing the SNR in more detail if you have an interest. Increasing the sampling rate will only result in an improved SNR if you also limit the bandwidth properly. For a simple moving average filter, any percent increase in sampling rate must also be accompanied by the same percent increase in the number of filter taps to improve the SNR of the processed data. The signal processing tool that can be downloaded from the Occammd website has a number of examples to illustrate these points.


The challenge for the system described in Figure 1, was eliminating bias from the pressure readings with as few computations as possible, since we were locked into an 8-bit microprocessor. At the same time, there needed to be a reasonable response time to changes in pressure. At low pressures, the motor would run slowly and the response time could be the required minimum and then ramp up the bandwidth as needed. However at higher pressures, it was desired to have an increase in response time if at all possible. Simply translated, lower sampling rates at lower pressures and motor speeds were okay, but there needed to be a way to ramp up to higher sampling rates at higher pressures / motor speeds, and limits set on how slow the lower end of the sampling rate could go.

One possible technique was using a least-mean-squared adaptive filtering algorithm to notch out the unwanted motor frequency from the pressure data, but this required a number of computations that were not well suited for the 8-bit microprocessor. Examples of this method are available in the Occammd signal processing tool, along with more suitable applications. Another technique involved using the motor’s hall sensor / tachometer to measure the frequency of the motor rotation, and then average samples between tachometer pulses to eliminate the sinusoidal component of the pressure data. If the motor frequency was stable, this approach would work in theory, but provided poor performance when the motor frequency was changing. The reason for this can be observed by examining a typical moving average frequency response, illustrated in Figure 2. Depending on the number of taps (16 in this case), the attenuation envelope at higher frequencies will be defined, but with notches at integer multiples of the sampling rate. These notches are very narrow in bandwidth, so any summation of samples that does not align with an integer multiple of the sampling rate will more likely fall along the tops of the lobes, which in this case is between 25db to 30db for 16 additions.


Ultimately, the solution involved a combination of measuring the tachometer period to sample the motor frequency, while at the same time leveraging the previously identified pitfall that filter characteristics will change with changing sampling rates. Fortunately, the changes are predictable and repeatable, and can be very useful if handled correctly, which we will discuss later.

Figure 3 illustrates a typical pressure signal relative to the tachometer signal. The actual pressure modulates this waveform up and down, depending on the actual system pressure. The instantaneous tachometer frequency is calculated using the microprocessor timer, and this data is used to generate an A/D sampling rate.

Small adjustments can be seen in the A/D sampling rate at the rising edge of the tachometer, as the microprocessor sampling algorithm keeps the A/D sampling rate locked in at an integer multiple of the tachometer frequency. At tachometer readings below a defined threshold, the A/D sampling rate is held at a fixed minimum sampling rate.


picture-4Figure 4 illustrates a screen shot from the Occammd signal processing tool which was used to design a notch filter that is broad enough in bandwidth to deal with the typical motor frequency spread, using a two stage cascaded bi-quad IIR filter. The center frequency of the notch filter is an integer multiple of the sampling rate, and decimation in time sampling is used to increase the sampling rate further, while averaging enough samples to improve the SNR. If you download the signal processing tool and want to experiment with these concepts, please contact Occammd through the website, and we will be happy to assist you with the operation of the tool and any specific questions that you have. The tool is not intended as a replacement for Matlab, Mathworks, or other types of signal processing analysis tools, but its free and can assist with illustrating many commonly encountered signal processing scenarios. It is excel based with the code implemented in visual basic for simulating data and generating filter coefficients, which we can make available as well.

One of the tricks in using bi-quad IIR filters is manipulating the calculated filter coefficients to be as close to powers of two as possible, while still maintaining the characteristics of the filter design. This enables the implementation to be done with simple addition, subtraction and a shift instead of coefficient multiplies, making it better suited for small 8-bit microprocessors.

The algorithm for the notch filter in Figure 4 is:

  1. y1(n)=[{(x(n-1)+x(n-2))≪2} + x(n-1)-y1(n-1)] >>3
  2. y2(n) = [{(y1(n-1)+y1(n-2))≪2} – y1(n-1) + y2(n-1)]>>3

picture-5Where x(n) is the input sample and y2(n) is the filtered output sample. The notched out frequencies will be within a reasonable bandwidth around ¼ the current sampling rate. The actual sampling rate used was 32x the tachometer frequency, with decimation in 8, so the IIR filter sample rate was 4x the tachometer frequency. The notch filter which removed the unwanted range of frequencies requires only 6 additions/subtractions and no multiplies. Figure 5 illustrates the performance of the notch filter with a simulated signal. The top plot is a section of the simulated data with tachometer frequencies modulated around 60Hz. The middle plot is the frequency domain of the pre-filtered and post-filtered data. The bottom plot shows repeated step responses of the filtered data with the unwanted sinusoidal data removed. The sampling rate of the IIR filtered data is 240Hz in this simulation.


A common pitfall when working with legacy designs, or fixing bugs in new designs, is inconsistency between the sampling methods and digital filtering algorithms being used. Often, the sampling rate, either under-sampling or over-sampling, can be used strategically as part of the signal processing algorithms being implemented. In smaller 8-bit microprocessors where computational capability and space is limited, IIR filters can be effectively used to fix signal processing issues. In this case, a sliding window IIR notch filter was implemented by paring A/D sampling algorithms with two cascaded bi-quad IIR filters, and taking advantage of keeping the oversampling rate consistent with the filter design being used. Occammd has a free signal processing tool that can be downloaded from the Occammd website ( The tool can be used to design filters, experiment with algorithms, and see examples of the techniques used in this blog. If you have any suggestions for future blogs, or would like assistance with the signal processing tool download, please contact Occammd through the contact page on their website.

Bob Fugerer