I have a signal with an unwanted oscillating carrier, shown in the blue curve. I made a low pass filter (5th order butterworth) and applied with filtfilt
function, and low the filtered output is the red curve.
[b,a] = butter(5,.7);
y = filtfilt(b,a,y);
The red curve from x value 500 to the end is exactly what I wanted, however the initial oscillation is still there. It seems like the filter function tries to match the initial/end value of the filter input and output, thus the oscillation preserves. Is there a way to unmatch the initial value so I can get a smooth output without any oscillation?
Update: I think my question wasn't clear. I want something like the black curve (hand drawing): completely remove the oscillation, and do NOT match the initial value. How can I do this?
The short answer is that what you're asking isn't possible.
All filters take some time to "warm up" - this is known as the 'rise time' of the filter. This occurs because an n
-order filter performs a weighted average of the last n
samples, and when the signal first starts, that backlog of samples isn't available.
The filter you've got there actually has a pretty good rise time - it only takes around 10 samples to start tracking the input properly.
The oscillations that occur are known as 'overshoot' - when designing a filter, there's a tradeoff between rise time and overshoot, you can't have a fast rise time and no overshoot. The wikipedia article on damping might be a good resource for you.