%cos_ups_exam


fre = 32;

f = @(x,fre)(cos(2*pi*fre*x)+5*sin(pi*fre*x) -2*sin(4*pi*fre*x)-cos(pi/2*fre*x));%*exp(-2*pi*((x-1/2)*2)^2);
j=input('loglength N; ?')
N=2^j;
%Ll=input('depth; ?');
k=0:N-1;

cs=zeros(1,N);
for kk=0:N-1
cs(kk+1)=f(kk/N,fre);
end
figure;fplot(@(x)f(x,fre),[0 1])
Ll=input('depth of dyadic subdivision; ?')
D=zeros(2,10);
N2=N*2^Ll;
cs2=zeros(1,N2);

for k2=0:N2-1;
cs2(k2+1)=f(k2/N2,fre);
end
Par1=[2:2:20];
for kk=1:10
    Par=Par1(kk);

[spli]=intersplliPt(cs,Par,Ll,2);

%Dif2=max(abs(cs2-spli));
Dif2=sqrt(mean(abs(cs2-spli).^2));
D(1,kk)=Par;
D(2,kk)=(log10(Dif2));
%D(2,kk)=round(log10(Dif2));

end
T=zeros(2,10); 

Ll=input('depth of ternary subdivision; ?')
N3=N*3^Ll;
cs3=zeros(1,N3);

for k3=0:N3-1;
cs3(k3+1)=f(k3/N3,fre);
end

Par1=[3 :2:21];
for kk=1:10
    Par=Par1(kk);

[spli3]=intersplliPt(cs,Par,Ll,3);
%Dif3=max(abs(cs3-spli3));
Dif3=sqrt(mean(abs(cs3-spli3).^2));
T(1,kk)=Par;
T(2,kk)=(log10(Dif3));

end
[D]
[T]
figure;
subplot(1,2,1)
bar(D(1,:),D(2,:))
set(gca,'FontSize',20)
subplot(1,2,2)
bar(T(1,:),T(2,:))
set(gca,'FontSize',20)

