% here's a version for figures, e.g. leaving out all the * and + marks
% (to put in by hand on the final idraw)
% makes the file a lot smaller rather than 4 copies same plot superimposed
%
sr=1000; % sampling rate
%sr=1000 looks crappy when differentiated, much more points not much better
%so later replot strangely shaped sinusoid on uniform lattice in loglog space
f=[1/64*f1cycle_sqr(1/8*sr) 1/16*f1cycle_sqr(1/4*sr) 1/4*f1cycle_sqr(1/2*sr) f1cycle_sqr(sr) 4*f1cycle_sqr(2*sr) 16*f1cycle_sqr(4*sr)];
q=(1/8*sr:8*sr-1)/sr; % q=(125:7999)/1000
%%%grid doesn't seem to work in octave2.1; need octave2.1 for axis("equal")
%%%grid
gset nokey
xlabel('q')
ylabel('f(q)')
qintegers=[1/8 1/4 1/2 1 2 4 8];
fintegers=[1/64 1/16 1/4 1 4 16 64];
%plot(q,f,qintegers,fintegers,'+',qintegers,fintegers,"*")

qtrue=(0:8*sr-1)/sr; % ok for linear plot, but problem for loglog plot
ftrue=qtrue.^2;

subplot(131);
%plot(q,f,qintegers,fintegers,'+',qintegers,fintegers,"*",qtrue,ftrue,".")
%%%plot(q,f,qtrue,ftrue)
axis("equal")
plot(q(126:3876),f(126:3876)); % plot only the middle 4 cycles of all 6 cycles
                               % this plots .25 to 4 instead of .125 to 8
Q=log(q)/log(2);
F=log(f)/log(2);
Qintegers=log(qintegers)/log(2);
Fintegers=log(fintegers)/log(2);
Qtrue=log(q)/log(2); % log plot problem because it goes to zero
ftrue=q.^2;
Ftrue=log(ftrue)/log(2);
subplot(132);
xlabel('Q')
ylabel('F(Q)')
title('Comparametric Periodicity (''Comperiodicity'')')
%plot(Q,F,Qintegers,Fintegers,'+',Qintegers,Fintegers,"*",Qtrue,Ftrue,".")
%%%plot(Q,F,Qtrue,Ftrue)
plot(Q(126:3876),F(126:3876),Qtrue,Ftrue)
subplot(133);
xlabel('Q')
%ylabel('dF/dQ/(2pi)')
ylabel('dF/dQ')
title('Comparametric Periodicity (''Comperiodicity'')')
Qt=Q(1:length(Q)-1); % Qt is Q truncated
dF=sr*diff(F);

% redraw previous plot on a uniformly sampled lattice
%funiform=1+sin(2*pi*2..^((0:999)./1000)); % 1 cycle
funiform=1+f1cycle_sqr(2*pi*2..^((0:999)./1000)); % 1 cycle
%aq=linspace(0,3,1000); % gives bumpy derivatives, e.g. should be half open
aq=3*(0:999)/1000;
%aq=3*(0:999)/999;
funiform=funiform+aq;
Funiform=log(funiform)/log(2);
%%%Funiforms=[Funiform-6 Funiform-4 Funiform-2 Funiform Funiform+2 Funiform+4];
Funiforms=[Funiform-4 Funiform-2 Funiform Funiform+2];
Funiforms_scaled=Funiforms/2/pi;

%%plot((diff(Funiforms));
plot(linspace(-3,3,length(Funiforms)-1),1000*diff(Funiforms),[-3,3],[2,2]);

subplot(111);

