# Signal leveling using scipy

Apologies if I'm using incorrect terms, and if this question's already been answered here. I have a data set which consists of a high DC signal modulated by AC signal (taken from custom-built biomedical instrumentation). Now the problem is that my signal has some low-frequency features that I'm having a hard time getting rid of using scipy. Please note that I'm a researcher but have limited practical experience in signal processing. I first do a low-pass on the signal to remove high-frequency components, and then I am trying to add a second filter to remove this low-frequency feature.

I tried doing a (butterworth order 1, cutoff 0.1Hz) high-pass filter but this removes the DC offset, which is important for me to keep (Figure 1). It also behaves in a rather odd manner.

I then tried doing a (butterworth order 1, band 0.1Hz to 0.5Hz) bandstop filter (removing low frequencies just above zero and just below my range of interest) but this results in a strange peak in the filtered output which I am unable to explain (Figure 2 - bonus points for someone who can shed light on this).

What I want to do is level the data, and remove these artifacts, so that each peak will be in line with the next. I've searched around but there doesn't seem to be an obvious and readily available solution to this.

To give you an idea of what I would really like to do, here is a similar treatment of the signal done in OriginPro: (Look at the blue signal - it has not had its DC offset shifted at all. How is OriginPro implementing this highpass filter? How can I replicate this behaviour in scipy?)

Why do I want to use scipy if my job's being done in Origin? Simple: (1) I want to understand the processing in greater detail so I can optimize it to not lose important parts of the signal (2) To automate the entire processing from acquisition to analysis.

Would greatly appreciate any help at all. Thanks in advance.

• A bandstop filter removes frequencies within a band. I think you meant a bandpass filter. However it does look like you're using a bandpass filter, so that's good. – MackTuesday May 20 '14 at 17:02
• That peak you see is likely due to a non-zero response at frequency zero and lag in the filter. Notice that DC is passed in figure 2. An order-1 bandpass filter can't give you zero response at both frequencies zero and Nyquist. So: use a higher order. If this isn't real-time processing, you can use a giant order if you like. – MackTuesday May 20 '14 at 17:14
• You might also consider doing your processing in the frequency domain, although that has its gotchas too. – MackTuesday May 20 '14 at 17:15
• High-pass filters always remove DC, since DC is the lowest possible frequency. If OriginPro is not removing DC, then it's not actually a high-pass filter. Does their documentation explain anything? If you want to keep DC, remove low frequencies, and keep high frequencies, you need a bandstop filter. Plotting your spectrum would help to figure out where the cutoffs should be. By "rather odd manner" do you mean the step response of the filter starting at -2 and approaching 0? Can you explain why you need DC but not low frequencies? Are you using lfilter or filtfilt? – endolith May 20 '14 at 20:45
• I am quite wary of doing processing in the frequency domain! I am using lfilter. The reason I don't want intermediete low frequencies is because they are most likely the result of artifacts that are created by my measurement equipment (it's a biomedical experiment, consisting of attachments on a human being, so with the person's movements, these artifacts are developed, which I am trying to remove). – derbedhruv Jun 1 '14 at 9:59