Need to filter very small signal I am measuring ECG signals on subjects and I am having issues filtering a very small signal from the inherent noise of the collecting device. I am using an 18 bit ADC to digitize the signal
Here is an example of the noisy signal I get:

I would like it to look like this:

I have tried different filters and the best signal yet has been from the 8-point mean averaging of the signal:

However, I am trying to find the p-wave, which is a small upward deflection just before the large QRS complex of the pulse. This p-wave is buried in the noise and I can't seem to get it out. I have tried creating a median beat of 300 heartbeats, and by doing this I can show that the p-wave does exist, but I need to show that it exists for every heartbeat.
Median beat:

Is there a more elaborate way to tease out the p-wave using the median beat, or could you point me to other strategies for improving the signal to noise ratio?
The first thing you should do is examine your signal collection hardware and do everything humanly possible to improve the signal-to-noise ratio of the analog signal applied to your A/D converter. I realize this is easier said than done, but do your very best to reduce the noise in your analog signal.
Next, you might consider the following process:

Based on the following figure, examine your noisy signal samples and identify the $T_n$ time instants of your QRS complex spikes.
Create multiple signal segments, $S_n$, where each segment comprises $N$ samples just prior to and including the QRS complex spike sample.
Average the $S_n$ signal segments.
Examine the &quot;averaged&quot; $N$-sample segment to see if your can detect an averaged p-wave.