clear

L=1;
N = 100;
dx = L/N;
x = 0:dx:1-dx;
y = cos(7*2*pi*x/L);
[k,amp] = find_spec(y);
figure(1)
plot(x,y,'LineWidth',2)
figure(2)
plot(k,amp,'o-')
axis([0,N/2,-17,1])

pause



y = exp(cos(2*pi*x));
[k,amp] = find_spec(y);
figure(1)
plot(x,y,'LineWidth',2)
figure(2)
plot(k,amp,'o-')
axis([0,N/2,-17,1])

pause

y = 1./(2-cos(2*pi*x));
[k,amp] = find_spec(y);
figure(1)
plot(x,y,'LineWidth',2)
figure(2)
plot(k,amp,'o-')
axis([0,N/2,-17,1])

pause

x = 0:dx:1-dx;
eps = 1;
y = 1./(eps^2+sin(pi*(x-1/2)).^2);
[k,amp] = find_spec(y);
figure(1)
clf
plot(x,y,'LineWidth',2)
figure(2)
clf
plot(k,amp,'o-')
axis([0,N/2,-17,1]);

% k_crit = 20

eps = 1/2;
x = 0:dx:1-dx;
y = 1./(eps^2+sin(pi*(x-1/2)).^2);
[k,amp] = find_spec(y);
figure(3)
clf
plot(x,y,'LineWidth',2)
figure(4)
clf
plot(k,amp,'o-')
axis([0,N/2,-17,1])
% k_crit = 40

eps = 1/4;
N = 2*N;
dx = L/N;
x = 0:dx:1-dx;
y = 1./(eps^2+sin(pi*(x-1/2)).^2);
[k,amp] = find_spec(y);
figure(5)
clf
plot(x,y,'LineWidth',2)
figure(6)
clf
plot(k,amp,'o-')
axis([0,N/2,-17,1])
% k_crit = 80

eps = 1/8;
N = 2*N;
dx = L/N;
x = 0:dx:1-dx;
y = 1./(eps^2+sin(pi*(x-1/2)).^2);
[k,amp] = find_spec(y);
figure(5)
clf
plot(x,y,'LineWidth',2)
figure(6)
clf
plot(k,amp,'o-')
% k_crit = 160



% centered pulse
x1 = .3;
x2 = .7;
eps = .05;
N = 100000;
dx = 1/N;
x = 0:dx:1-dx;
y = tanh((x-x1)/eps) - tanh((x-x2)/eps);
% for m=-M:M
%     y = y + tanh((x-x1-m)/eps) - tanh((x-x2-m)/eps);
% end
% y = y-1;
figure(1)
clf
plot(x,y,'LineWidth',2)
axis([0,1,0,2.1])
% print -dps centered_pulse.ps
[k,amp] = find_spec(y);
z = 5*10^(-5)./k.^2;
figure(2)
clf
plot(k,amp,'-')
hold on
plot(k,log10(z),'--')
xlabel('k','FontSize',16)
axis([0,max(k),-10,1])
% print -dps centered_pulse_spec2.ps
axis([0,100,-10,1])
% print -dps centered_pulse_spec1.ps
figure(3)
plot(log10(k),amp)
hold on
plot(log10(k),-4-2*log10(k),'--')
xlabel('log10(k)','FontSize',16)
hold off
% print -dps centered_pulse_spec3.ps

% off-centered pulse
x1 = .3;
x2 = .8;
eps = .05;
N = 100000;
dx = 1/N;
x = 0:dx:1-dx;
y = tanh((x-x1)/eps) - tanh((x-x2)/eps);
% for m=-M:M
%     y = y + tanh((x-x1-m)/eps) - tanh((x-x2-m)/eps);
% end
% y = y-1;
figure(1)
clf
plot(x,y,'LineWidth',2)
axis([0,1,0,2.1])
% print -dps centered_pulse.ps
[k,amp] = find_spec(y);
z = 5*10^(-5)./k.^2;
figure(2)
clf
plot(k,amp,'-')
hold on
plot(k,log10(z),'--')
xlabel('k','FontSize',16)
axis([0,max(k),-10,1])
% print -dps centered_pulse_spec2.ps
axis([0,100,-10,1])
% print -dps centered_pulse_spec1.ps
figure(3)
plot(log10(k),amp)
hold on
plot(log10(k),-3.8-log10(k),'--')
xlabel('log10(k)','FontSize',16)
hold off
% print -dps centered_pulse_spec3.ps
