Time series ideal filter

function xf=ilpf(x,fp)
% An ideal lowpass filter with perfect nulls in the frequency response
% and with filtering procedure; for short and long data length
% fp – Filter cutoff frequency (0>fp>0.5)

x(:);Signal with noise

% Obtain the mean of the data:
M = mean(x);
x1 = x – M;

% Create a timeseries object
% Specify a time vector that ranges from 1 to length(x) intervals.
x2 = timeseries(x1,1:length(x1));

% Enter the frequency interval for filtering the data:
interval=[0 fp ];

% Invoke an ideal pass filter:
xf = idealfilter(x2,interval,’pass’);
x3 = xf.data;
x3=x3(:);
xf=x3+M;

return
x=3+randn(700,1);
xf=ilpf(x,0.02);
% Compare the original data and the shaped data on a line plot:
close all
figure(1)
plot(x,’-.’), grid on, hold on
plot(xf,’r-‘)