% uph1 (microphonics1)
% can we remove uphonics digitally?
%

clear
hold off

load shapes2
I=size(shapes2);
S=1600;           %max number of samples for trapezoidal filter
x=zeros(I(1,1),S/2);
x=[x ones(I(1,1),S/2)];
T=10e-9*(1:I(1,1)*S)*1e3;    %uphonics at 1KHz
uph=0.1*sin(T*2*pi);    

for i=1:I(1,1)
  x(i,(S/2+1):(S/2+50))=shapes2(i,:);
  x(i,:)=x(i,:)+uph((i-1)*S+1:i*S);
end

y=zeros(I(1,1),2000);
m=50;
k=100;
for i=1:I(1,1)
 for n=600:1600
  y(i,n)=y(i,n-1)+x(i,n)-x(i,n-m)-x(i,n-m-k)+x(i,n-2*m-k);
 end
end

figure(1);plot(x')
figure(2);plot(y(:,600:1700)')
figure(3);plot(T',uph')

for i=1:I(1,1)
 mx(i)=max(y(i,:));
end
