%function Hd = LPF_IIR
%LPF_IIR Returns a discrete-time filter object.

%
% MATLAB Code
% Generated by MATLAB(R) 7.13 and the Signal Processing Toolbox 6.16.
%
% Generated on: 12-Sep-2015 09:07:13
%

% Butterworth Highpass filter designed using FDESIGN.HIGHPASS.

% All frequency values are in Hz.
Fs = 360;  % Sampling Frequency

Fstop = 0.5;         % Stopband Frequency
Fpass = 1;           % Passband Frequency
Astop = 40;          % Stopband Attenuation (dB)
Apass = 1;           % Passband Ripple (dB)
match = 'stopband';  % Band to match exactly

% Construct an FDESIGN object and call its BUTTER method.
h  = fdesign.highpass(Fstop, Fpass, Astop, Apass, Fs);
Hd = design(h, 'butter', 'MatchExactly', match);

% [EOF]

%grpdelay(Hd,2048,Fs)   % plot group delay
N2 = mean(grpdelay(Hd))*0 % filter delay in samples


%N2= round (N/2)*0+1;
sigin= s118bw12(1,:);
%sigout= -filter(Hd,sigin);
sigout= filtfilt(Hd.sosMatrix,Hd.ScaleValues,sigin);
sigout_shifted= sigout(N2+1:end);
figure
subplot(3,1,1), plot(sigin(1:10000-N2))
subplot(3,1,2), plot(sigout_shifted)
subplot(3,1,3), plot(sigin(1:10000-N2)-sigout_shifted)