par(mfrow=c(3,2))

############################# C ####################################

# Simulation of the letter 'C' for moderate (c1) and large (c2) noise

t<-seq(pi/2+0.2,3*pi/2-0.2, length=60)
cx<-cos(t)
cy<-sin(t)

scx<-rnorm(60,0,0.01)
scy<-rnorm(60,0,0.01)

ecx<-rnorm(60,0,0.1)
ecy<-rnorm(60,0,0.1)

cx1<-cx+scx
cy1<-cy+scy
cx2<-cx+ecx
cy2<-cy+ecy

# Plot data without LPC
# par(mfrow=c(1,2))
# plot(cx1, cy1)
# plot(cx2, cy2)

c1<-cbind(cx1,cy1); c2<-cbind(cx2,cy2)

# LPC's for 'C'

# par(mfrow=c(1,2))
lpc.c1<-lpc(c1, h= c(0.1,0.1), t0=0.1, iter=50, way="two",pen=T, penpot=2, mult=1, depth=1, plotlpc=3)
lpc.c2<-lpc(c2, h= c(0.15,0.15), t0=0.15, iter=50, way="two",  pen=T, penpot=2, mult=1, depth=1, plotlpc=3)

# The red points along the fitted curves correspond to the local centers of mass 
# as described in [1].

############################## E ##########################################


# Simulation of the letter 'E' for moderate (e1) and large (e2) noise

ex<-append(rep(0,40), append(seq(0,1,length=20), append(seq(0,1,length=20),seq(0,1,length=20))))
ey<-append(seq(0,2,length=40), append(rep(0,20), append(rep(1,20), rep(2,20))))

sex<-rnorm(100,0,0.01)
sey<-rnorm(100,0,0.01)

eex<-rnorm(100,0,0.1)
eey<-rnorm(100,0,0.1)

ex1<-ex+sex
ey1<-ey+sey
ex2<-ex+eex
ey2<-ey+eey

# Plot data without LPC
# par(mfrow=c(1,2))
# plot(ex1, ey1)
# plot(ex2, ey2)

e1<-cbind(ex1,ey1); e2<-cbind(ex2,ey2)

# LPC's for 'E'


# par(mfrow=c(1,2))
lpc.e1<-lpc(e1, h= c(0.1,0.1), t0=0.1, iter=50, way= "two", pen=T, penpot=2, mult=1, depth=2, plotlpc=3)
lpc.e2<-lpc(e2, h= c(0.15,0.15), t0=0.1, iter=50, way= "two", pen=T, penpot=2, mult=1, depth=2, thresh=0.3)

# Remark: The bandwidth for the noisy 'E' is set to 0.15, which is slighty higher than in [2],
# but gives smoother curves. Not every time the choice depth =2 is successful - depending on the starting point one might
# need  depth =3. For the letter 'K' this is similar. 

# Red branches: depth=1; green branches: depth=2


################################ K #########################################

# Simulation of the letter 'K' for moderate (k1) and large (k2) noise

kx<-append(rep(0,40), append(seq(0,1,length=30), seq(0.3,1.0,length=20)))
ky<-append(seq(0,2,length=40), append(kx[41:70]+0.6 , -1.1*kx[71:90]+1.1 ))

ekx<-rnorm(90,0,0.07)
eky<-rnorm(90,0,0.07)

skx<-rnorm(90,0,0.01)
sky<-rnorm(90,0,0.01)

kx1<-kx+skx
ky1<-ky+sky
kx2<-kx+ekx
ky2<-ky+eky

# Plot data without LPC
# par(mfrow=c(1,2))
# plot(kx1, ky1)
# plot(kx2, ky2)

# LPC's for 'K'

k1<-cbind(kx1,ky1); k2<-cbind(kx2,ky2)

# par(mfrow=c(1,2))
lpc.k1<-lpc(k1, h= c(0.08,0.08), t0=0.08, x0=c(1,1.5), iter=50, way="two", pen=T, penpot=2, mult=1, depth=3, plotlpc=3)
lpc.k2<-lpc(k2, h= c(0.15,0.15), t0=0.15, iter=50, way="two",  pen=T, penpot=2, mult=1, depth=2, thresh=0.1, plotlpc=3)

# Red branches: depth=1; green branches: depth=2; blue branches: depth=3
 
# Note that no multiple initializations are used thoughout all examples - 
# the different branches are exclusively launched by starting points of second order
# stemming from high second local principal components 
# (Einbeck, Tutz & Evers, 2005b, in Proc of the GfKl Dortmund 2004).