%load cbf;
N = length(dztz);
dt = 0.002;
time = [0:N-1]*dt;
figure(1)
plot(time,dztz);
xlabel('time (s)');

freq = [-N/2:N/2-1]/(N*dt);
figure(2)
plot(freq,abs(fftshift(fft(dztz-mean(dztz)))))
xlabel('freq (hz)');

fbw = 10; % Filter bandwidth = 10 Hz
f1 = abs(freq) < fbw;  % rect filt
f2 = (0.5 + 0.5*cos(pi*freq/fbw/2)).*(abs(freq) < 2*fbw); % hanning filt

dztzf1 = ifft(ifftshift(fftshift(fft(dztz)).*f1'));
dztzf2 = ifft(ifftshift(fftshift(fft(dztz)).*f2'));
timewid = 1/fbw/dt;
dztzf3 = conv2(dztz,ones([timewid 1])/timewid,'valid');
f3time = [ones([timewid/2 1])/timewid; zeros([N-timewid 1]);ones([timewid/2 1])/timewid;]

figure(3)
subplot(311)
plot(time,dztzf1);
title('filtered signals')
subplot(312)
plot(time,dztzf2);
subplot(313)
plot(time(timewid/2:N-timewid/2),dztzf3);
xlabel('time (s)');

impresp1 = ifft(ifftshift(f1));
impresp2 = ifft(ifftshift(f2));

figure(4)
subplot(311)
plot(time,impresp1);
title('impulse responses')
subplot(312)
plot(time,impresp2);
subplot(313)
plot(time,f3time);
xlabel('time (s)');

f3 = real(fftshift(fft(f3time)));
figure(5)
subplot(311)
plot(freq,f1);
title('freq responses')
subplot(312)
plot(freq,f2);
subplot(313)
plot(freq,f3);
xlabel('freq (Hz)');
