matlabfilterlowpass-filter

Matlab low pass filter output initial/end value


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);

enter image description here 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? enter image description here


Solution

  • When confronted with this problem, what I often end up doing is creating a start-up signal which precedes the filtered signal.

    For a low pass filter that is a relatively easy task, but depends on your original signal. My initial attempt would be to reflect part of the signal with respect to the origin:

    [b,a] = butter(5,.7);
    N = 50; % change this to suit your needs
        yNew = filtfilt(b,a,[y(N:-1:1);y];
    yNew = yNew(N+1:end);
    

    This ensures that the start-up is minimal, and you can "hit the ground running".