Weird ringing at signal start and end for default Matlab lowpass filter **FIND UPDATES BELOW THE ORIGINAL QUESTION TEXT:
I am trying to lowpass filter electrophysiological data and I see ringing near sharp transients at signal start and end.
Ringing at start:

Ringing at sharp transients:

I am simply using Matlab's default lowpass filter:
fpass=1000;
f_sampling=20000;
fil_X=lowpass(X,fpass,f_sampling);

Two questions:

Why do I see the weird ringing effect at signal start and end?
What strategies can I use for reducing the ringing (both at start/end and at sharp transients) other than reducing the steepness of the filter in the frequency domain? Can some fancy windowing be of help? I tried forcing Matlab to use IIR filter with filtfilt and the ringing stays the same.

Thanks,
Anand
UPDATES:
Padding the signal at start and then removing the padded portion from the filtered trace gets rid of the ringing at start. Thanks!!
For the other problem, I tried an IIR filter without filtfilt. Ignore the unnecessary double filtering. I do it because lowpass automatically applies filtfilt.
[~,ft_obj]=lowpass(X,fpass,f_sampling,'impulseresponse','iir');
fil_X=filter(ft_obj,X); 

Here is what I get:

As you can see, it gets rid of the pre-transient ringing, while introducing post-transient ringing. The post-transient ringing should not be a big issue. But, there is also a signal delay/distortion that becomes clear at the same time point across different conditions (red line). That can shift the absolute and relative timing of events in the signal.
Is there a way to compensate for that?
You are using a linear phase filter. These are non causal and hence you get pre-ringing at your transients. Use a minimum phase or IIR filter. Do NOT use filtfilt, since that makes an IIR filter linear phase again and you end up with the same problem
The artifact at the beginning is the step response of the filter. The filter needs access to &quot;past&quot; samples and since it doesn't know what these are, it assumes they are 0. In your case, you have a DC jump and it looks like they are more like -0.05. There multiple work-arounds. In your case it's probable the easiest to pre-pend the signal with a few hundred constant samples that are the average of the first few hundred sample of your signal, filter the whole thing and cut the pre-pended section off again.