This post reviews how I approached the 2022 IC Design Contest final. The problem was to process an ECG waveform and identify the positions of its Q, R, and S components.

Problem overview

The proposed processing flow had three stages:

  1. A 16-tap moving average:

    MV(n)=x(n)+x(n−1)+⋯+x(n−15)16MV(n)=\frac{x(n)+x(n-1)+\cdots+x(n-15)}{16}
  2. DC-bias removal:

    DelDC(n)=x(n)−MV(n)DelDC(n)=x(n)-MV(n)
  3. A 15-tap windowing filter, with symmetric triangular weights:

    WF(n)=DelDC(n−7)+2DelDC(n−6)+⋯+8DelDC(n)+⋯+DelDC(n+7)64WF(n)=\frac{DelDC(n-7)+2DelDC(n-6)+\cdots+8DelDC(n)+\cdots+DelDC(n+7)}{64}
Algorithm flow for ECG QRS detection

Hardware architecture

Hardware architecture for ECG QRS detection

Interface

SignalDescription
din10-bit input data
busyThe host can send data when this is 0
Q, R, S12-bit position values, output together
validIndicates that the Q, R, and S positions are valid

Implementing the moving average

A direct 16-tap moving average sums 16 samples, which suggests a fairly large adder network. I wanted to avoid that.

Instead, I used a running cumulative sum:

S1(n)=S1(n−1)+x(n) S_1(n)=S_1(n-1)+x(n)

Then the sum over a 16-sample window is:

MV(n)=S1(n)−S1(n−16)16 MV(n)=\frac{S_1(n)-S_1(n-16)}{16}

Compared with directly summing all 16 samples, this changes the implementation in three important ways:

  1. We can substantially reduce the amount of addition logic, although the cumulative-sum arithmetic needs a wider data range.
  2. We still need to retain the historical information needed by the filter. The register requirement does not simply disappear.
  3. We may significantly shorten the critical path.

That last point was especially important to our AT result.

Implementing the windowing filter

I used a similar idea for the windowing filter. In signal-processing classes, we learn that convolving two rectangular windows produces a triangular window. That is exactly the shape of the coefficients in this filter.

In other words, the triangular filter can be expressed as two cascaded moving sums.

Using the notation from my original design:

S2(n)=DelDC(n)+⋯+DelDC(n−7) S_2(n)=DelDC(n)+\cdots+DelDC(n-7)
WF(n)=S2(n)+⋯+S2(n+7) WF(n)=S_2(n)+\cdots+S_2(n+7)

The final filter also needs the appropriate scaling by 64. The precise sample alignment depends on the streaming implementation.

I could then apply the same running-sum technique to both stages, instead of building a large network that evaluates every weighted term separately.

Finding Q, R, and S

For the R peak, we can keep updating the maximum value and its position as samples arrive.

The Q and S positions can likewise be found with relatively simple comparisons and stored candidate positions. Each of these decisions needs only a few arithmetic or comparison elements and registers in our design.

Where the optimization mattered

After the competition, I noticed that many other designs had clock periods around 3 ns. Our architecture had only a few logic operations between registers, including the necessary comparisons, and we reached roughly 2 ns.

That difference in clock period alone could create a major difference in the final AT score.

On the area side, the data history needed by the filters limited how much register storage we could remove without changing the algorithm. I did not want to exploit the test patterns by implementing something that no longer performed the intended computation.

What I learned from the competition

This post focuses on the ideas I had when reading the problem. They sound straightforward in retrospect, but boundary conditions still needed careful verification.

I spent roughly 60% of the competition time in MATLAB, checking that the transformed algorithms behaved correctly before implementing them. After that, RTL development and APR went relatively smoothly.

Near the end, I optimized the RTL and experimented with floorplans at different core utilizations. I eventually prioritized timing rather than spending more time increasing utilization.

For example, reducing the clock period from 2.2 ns to 2.0 ns improves the timing factor by about 9%. Raising core utilization from 70% to 80% could also improve an area-related metric, but it would take considerably more implementation time to resolve timing and DRC issues.

My main takeaway was simple: a mathematical reformulation of the algorithm gave us more leverage than late-stage physical-design tuning.

Actually my teammate unable to participate due to COVID-19 quarantine restrictions, I was initially unsure whether I could complete the competition on my own, but the experience ultimately gave me a tremendous sense of accomplishment!