% Filter design 

% % According to their passband and stop band:
% % 
% % Low pass (smoothing)
% % High Pass
% % Stopband
% % Passband

[b,a]= butter(6,2000*2/fsi,'low');
y= filter(b,a,data);
figure(4), plot(y)

% Play with Filter order

% Let's visualize it:
clf
plot(fscale,1/200*X(1:length(data)/2))
hold on
plot(fscale,H(1:length(data)/2),'r')
hold off

% Play with filter Type


% % 
% % Mainly 3 types of filters
% % 
% % Bessel: preserves wave shape: linear phase (constant group delay). This property only holds for analog filter, not digital filter
% % Butterworth: flat and monotonic, at the sacrifice of roll off steepness
% % Chebyshev -- type 1: equiripple in passband and monotonic in stopband
% % Chebyshev -- type 2: monotonic in passband and equiripple in stopband, roll off slower than type 1
% % 
% % according to their input sampling
% % continuous (no sampling) Matlab simulation (OpAmp implementation)
% % digital (sampled signal)


% Impulse response
h= impz(b,a);
stem(h)