% uph4 (microphonics4)
% Test with the trapezoidal filter

clear
hold off

load drandn.txt
x = drandn;
I=size(x);

%[a,b,c,d]=butter(1,10e-9*1e3*pi,'high')   %high pass, 10KHz

%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);
%  xf(i,:)=dlsim(a,b,c,d,x(i,:))';    %filter microphonics
%end

y=zeros(I);

m=450;
k=32;
for n=1000:I(1,1)
  y(n)=y(n-1)+x(n)-x(n-m)-x(n-m-k)+x(n-2*m-k);
end

num=zeros(1,933);
num(1)=1;
num(451)=-1;
num(483)=-1;
num(933)=1;

den=zeros(1,933);
den(1)=1;
den(2)=-1;

%disp('1')
%w=0.4:.02:1;

%[mag,ph]=dbode(num,den,w);

%plot(mag)


yl=-50+dlsim(num,den,x);

for i=1:I(1,1)-460
 r(i)=yl(i+460)-yl(i);
end

%figure(1);plot(x')
figure(2);plot(1:I(1,1),y','g',1:I(1,1),yl','b')
figure(1);plot(r')


