Fp = 49500;    % Passband frequency in Hz
Fst = 50000; % Stopband frequency in Hz
Ap = 1;      % Passband ripple in dB
Ast = 95;    % Stopband attenuation in dB

% Design the filter
df = designfilt('lowpassfir','PassbandFrequency',Fp,...
                'StopbandFrequency',Fst,'PassbandRipple',Ap,...
                'StopbandAttenuation',Ast,'SampleRate',fs);
hfvt = fvtool(df);

% Filter the data and compensate for delay
D = ceil(mean(grpdelay(df))); % filter delay, added ceil to make integer
ylp = filter(df,[y; zeros(D,1)]);
ylp = ylp(D+1:end);
