%function Hd = BPF_FIR
%BPF_FIR 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:30:54
%

% FIR Window Bandpass filter designed using the FIR1 function.

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

Fstop1 = 0.5;            % First Stopband Frequency
Fpass1 = 1;              % First Passband Frequency
Fpass2 = 30;             % Second Passband Frequency
Fstop2 = 40;             % Second Stopband Frequency
Dstop1 = 0.0001;          % First Stopband Attenuation
Dpass  = 0.17099735734;  % Passband Ripple
Dstop2 = 0.0001;          % Second Stopband Attenuation
flag   = 'scale';        % Sampling Flag

% Calculate the order from the parameters using KAISERORD.
[N,Wn,BETA,TYPE] = kaiserord([Fstop1 Fpass1 Fpass2 Fstop2]/(Fs/2), [0 ...
                             1 0], [Dstop1 Dpass Dstop2]);

% Calculate the coefficients using the FIR1 function.
b  = fir1(N, Wn, TYPE, kaiser(N+1, BETA), flag);
Hd = dfilt.dffir(b);

% [EOF]


N2 = round(mean(grpdelay(Hd))) % filter delay in samples
sigin= s118em12(1,:);
sigout= filter(Hd,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)