by Steve Poulsen
Introduction
Signal processing has been around for many decades. Initially performed with hardware, it later migrated to software using DSPs (Digital Signal Processors). Even MCUs could perform basic signal processing tasks. In the early 2000s, we were processing audio on an ARM9 while processing video on a DSP, using Texas Instruments digital still camera chips (DSC) and later the DaVinci™ series.
Creating programs for these chips required significant time to analyze signals, choose algorithms that might provide desired results, test, observe the results, and then make changes to fix issues. Sometimes these algorithms didn't work and needed to be scrapped for something better. It was tedious, but when the solution was complete, it was well understood.
The rapid growth in artificial intelligence has moved some of the DSP processing to AI models that essentially perform what a DSP program did in the past. The benefit has been that the testing of algorithms is now left to high-speed processors to test, validate, adjust, and repeat. The engineer now faces a new set of tools in deciding the structure of the model and how to train it.
In both cases, large data sets were needed. For the DSP program, the data was needed to test and validate. Failures were manually observed and would often lead to algorithm tweaks. For AI, the data is used for training, and the processors make the tweaks to find the optimum solution. In both cases, large data sets made for a better algorithm.
This article will explore a traditional DSP algorithm and how similar functionality is achieved in an AI model. One important goal is to show that knowledge of a good DSP structure for an algorithm is crucial in creating a good AI model. The AI model can only train on the structure provided. A bad structure will yield a bad model.
Digital Signal Processing
One example of a digital signal processing problem that is not straightforward is measuring heart rate using the heart rate (HR) signal from a sensor. The HR signal typically looks like the following.
This signal looks nice and clean, and a first attempt at measuring the HR would be to look for the peaks and measure the time between them. For an algorithm, however, we must define what constitutes a peak. In the image, there are two peaks – one larger and one smaller. Understanding how an HR signal looks, we conclude that the small peaks are not of interest; rather, the time between the tall peaks is what we look for.
We then may choose to implement a slow-running maximum detector to track the peaks. This peak tracker might look something like this:
if sample > max_sample then max_sample = sample else max_sample = max_sample * 0.99
Note: 0.99 is chosen to show that this value is very close to 1, and the decay is very slow.
However, in practice, we may find our HR signal is noisy and has many spikes. In this case, we might implement a more sophisticated approach:
if sample > max_sample then decay_coefficient = 0.9 else delay_coefficient = 0.99
max_sample = max_sample * delay_coefficient + sample * (1 - delay_coefficient).
In this implementation, the coefficients create a fast rise to follow a maximum and a slow decay to hold the maximum. The actual coefficient values are calculated based on the range of valid heart rates, how fast the HR pulse can rise, and other factors.
We next encounter a new challenge when we examine real HR signals.
In the real world, we often have a DC bias or low-frequency signal that the HR rides on and some high frequency noises. These components are generally not useful for our analysis, so we typically implement a high-pass filter, and a low-pass filter, to reduce these noises. This results in a signal processing chain with the following components:
- High-pass filter
- Low-pass filter
- Maximum detector
- Minimum detector
- Peak detection with thresholds
The signal is filtered, then minimum/maximum detectors are applied, while passing the filtered signal and the min/max values to the next phase. We typically set thresholds at 20% and 80% of the range between the min/max values and identify a peak when the signal crosses the 80% threshold and a valley when it crosses the 20% threshold. Once we detect a peak, we wait for a valley before looking for the next peak. We then record the time of each peak and calculate the heart rate.
These thresholds need optimization, as HR signals vary significantly between individuals and activities. This leads to implementing additional rules, filters, and calculations to obtain reliable heart rate measurements. The final algorithm might include:
- High-pass filter
- Low-pass filter
- Maximum detector
- Minimum detector
- Enhanced peak detection with min/max thresholds
- Temporal analysis
The peak detection becomes increasingly sophisticated through experimentation and testing. However, the purpose of this article is not to solve these problems, but to demonstrate the approach and the challenges which need overcome.
Artificial Intelligence (ML)
An AI implementation benefits from understanding the signal processing methodology to create a better solution. However, AI introduces some elements of automated optimization. To create an AI model, we typically implement the following approach:
We know we need initial filtering (HPF and LPF), but additional filtering may be beneficial. Therefore, we implement a convolutional layer in our model, potentially with 4 units to allow the AI to discover the most useful filtering operations that machine learning (ML) may optimize beyond our traditional understanding. The convolutional layer processes more than just frequency components; it may learn to extract relevant features such as rising edges and their magnitudes.
Layer 1: convolutional layer with 4 filters
We then implement a dense layer to allow the ML system to learn functions analogous to min/max/peak detection or to detect other features we may not be aware of. These dense layers process the samples through various transformations to produce combined values. We might start with 256 nodes (neurons) to provide the model sufficient parameters for optimization, though we may reduce this number through testing to achieve optimal results with fewer nodes.
Layer 2: dense layer of 256 nodes
The next stage adds a second dense layer that reduces the processing to a single output: the estimated heart rate.
Layer 3: dense layer of 1 node
For input, the model requires sufficient samples to analyze at least two heart rate cycles at the lowest expected heart rate. A larger input window helps improve accuracy, and our implementation might process 50,000 samples, updating in smaller increments of 1,000 samples using a sliding window of 49,000 previous samples and 1,000 new samples.
This model undergoes training and testing phases, with error analysis guiding improvements. With more training data and iterations, we might expect better accuracy. The model architecture may require refinement, such as additional layers or adjustments to the number of filters or dense layer nodes based on performance metrics. An example Tensor Flow model is as follows.
model = tf.keras.Sequential([
tf.keras.layers.Input(shape=[50000, 1]),
tf.keras.layers.Conv1D(4, kernel_size=256, activation='relu'),
tf.keras.layers.MaxPooling1D(pool_size=4),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(256, activation='relu'),
tf.keras.layers.Dense(1, 'activation='linear')
])
This is a simplified model for illustration purposes. In practice, heart-rate signals would likely need more layers, including specialized layers, as well as other changes to be most efficient.
Conclusion
The traditional DSP and AI approaches each offer distinct advantages and challenges. While AI enables us to achieve optimal algorithms without detailed internal understanding, it requires us to focus on architecture design and optimization. Even with AI models, we must understand the signal processing requirements for our objectives. We may need to analyze why a model isn't achieving desired performance and adjust its architecture. After obtaining additional training data and retraining, we can develop improved models.
In the DSP approach, we manually optimize parameters through experimentation when signal characteristics are not well understood. This requires deeper technical knowledge, and achieving an optimal algorithm can take considerable time.
The hybrid approach often proves most effective. For example, when we know certain filtering operations are necessary, we can implement proven filters for these tasks. We might also implement min/max detection and then feed the filtered signal, minimum value, maximum value, and other key parameters into our model, training it to handle aspects that are less well understood. In this scenario, we must avoid making incorrect assumptions that might prevent the AI model from discovering better solutions.
With advanced computational resources for training, our focus has shifted to understanding and optimizing architecture rather than implementing detailed processing steps. However, even with AI models, success requires understanding the signal processing fundamentals needed to achieve our objectives.
Comments
0 comments
Please sign in to leave a comment.