dt = 4e-8;
xzero = 0;
t = [0:5001]*dt + xzero;

pitch = 315e-6;
s = [-31.5:31.5]*pitch;
fc = 2.6e6;

fid=fopen('ats_4ab1.bin','rb','b');
raw=zeros(64,64,5002);

load bpf2;
m = (length(bpf)-1)/2;
for k = 1:64,
k
    for l = 1:64,
        q = 6.1035e-7*fread(fid,5002,'short');
        if (k == l)
            q = -0.65*[q(3:5002)-mean(q(2000:5002)) ; zeros(2,1)]; 
        else
            q = q - mean(q(2000:5002));
        end
        q = conv(q,bpf);
        raw(k,l,:) = q(1+m:5002+m);
    end
end

fclose(fid);
return

% Dip filter
cassumed = 1450;
rho1 = 40*pi/180;
rho2 = -40*pi/180;
[f1,f2]=freqspace(41,'meshgrid');
Hd = zeros(41,41);
Hd(f1 > 0 & f2 < f1*pitch*sin(rho1)/(cassumed*dt) & f2 > f1*pitch*sin(rho2)/(cassumed*dt)) = 1;
Hd(f1 == 0 & f2 == 0) = 1;
Hd(f1 < 0 & f2 > f1*pitch*sin(rho1)/(cassumed*dt) & f2 < f1*pitch*sin(rho2)/(cassumed*dt)) = 1;
dipfilt = fwind1(Hd,hamming(41));

for k = 1:64,
    k
    raw(k,:,:) = filter2(dipfilt,squeeze(raw(k,:,:)));
end

