(* CASL, Cell-Cycle Analysis in Scale of Log by Fujikawa-Yamamoto, (1998) *)

(* Create list mode data by FCS to ASCII. Put the data into Mathematica folder. Parm = {0,0,1,0,0} means that FL2H is the 3rd.*)

filename = InputString["File Name ??"];
Totaldata=ReadList[filename,Table[Number,{5}]];
Parm={0,0,1,0,0};
FL2Hlist=Totaldata.Parm;
HT1024=Table[0,{t,1,1024}];
Do[If[FL2Hlist[[i]]>0,HT1024[[FL2Hlist[[i]]]] +=1,HT1024[[FL2Hlist[[i]]]] +=0],{i,10000}];
HT512=Table[0,{t,1,512}];
Do[HT512[[i]]=HT1024[[(2 i - 1)]]+HT1024[[(2 i)]],{i,512}];
data=HT512;

MaxHeight = Max[Take[data,{100,500}]];
AxOrigine = AxesOrigin -> {0,0};
AxLabel = AxesLabel -> {""};
PRange = PlotRange ->{0,MaxHeight*1.2};
PJoined = PlotJoined->True;
PStyle = PlotStyle ->{AbsoluteThickness[0.02], GrayLevel[0]};
GLines = GridLines->{Automatic,None};
PLabel = PlotLabel->"";
dataPlot = ListPlot[data, AxOrigine, PRange, PJoined, PStyle, GLines, PLabel];

For[i=100, Max[Take[data,{i, i}]] < MaxHeight, i += 1, i=i ];
Print["Maximum peak position = ", i];
mMax = Input["Maximum peak position ="];
Print["Maximum peak position = ", mMax]

LowerMax = Max[Take[data,{mMax - 40,mMax - 30}]];
For[i=(mMax - 30), data[[i]] < LowerMax, i -= 1, i=i ];
i=i;
Print["Lower Maximum peak position = ", i]
mLowerMax = Input["Lower Maximum peak position = "];
Print["Lower Maximum peak position = ", mLowerMax]
LoDist = mMax - mLowerMax;

UpperMax = Max[Take[data,{mMax + 20,mMax + 40}]];
For[i = (mMax + 20), Max[Take[data,{i, i}]] < UpperMax, i += 1, i=i ];
Print["Upper Maximum peak position = ", i]
mUpperMax = Input["UpperMaximum peak position = "];
Print["Upper Maximum peak position = ", mUpperMax]
UpDist = mUpperMax - mMax;

AxOrigine=AxesOrigin ->{0,0};
PRange=PlotRange->{0,MaxHeight*1.2};
PJoined=PlotJoined->True;
PStyle=PlotStyle ->{AbsoluteThickness[0.02], GrayLevel[0]};
GLines=GridLines->{{(mLowerMax - 3*LoDist),(mLowerMax - 2*LoDist),(mLowerMax - LoDist),
mLowerMax,mMax,mUpperMax,(mUpperMax + UpDist),(mUpperMax + 2*UpDist),(mUpperMax + 3*UpDist)},None};
PLabel=PlotLabel->"";
dataPlot = ListPlot[data, AxOrigine, PRange, PJoined, PStyle, GLines, PLabel]

Print["Expected Peak = ", (mLowerMax - 4*LoDist)];
Print["Expected Peak = ", (mLowerMax - 3*LoDist)];
Print["Expected Peak = ", (mLowerMax - 2*LoDist)];
Print["Expected Peak = ", (mLowerMax - LoDist)];
Print["Expected Peak = ", mLowerMax];
Print["Expected Peak = ", mMax];
Print["Expected Peak = ", mUpperMax];
Print["Expected Peak = ", (mUpperMax + UpDist)];
Print["Expected Peak = ", (mUpperMax + 2*UpDist)];
Print["Expected Peak = ", (mUpperMax + 3*UpDist)];
Print["Expected Peak = ", (mUpperMax + 4*UpDist)];
Print["Expected Peak = ", (mUpperMax + 5*UpDist)];
Print[];

m2c = Input["2c peak position = "];
Print["2c peak position = ", m2c];
m4c = Input["4c peak position = "];
Print["4c peak position = ", m4c];
m8c = Input["8c peak position = "];
Print["8c peak position = ", m8c];
m16c = Input["16c peak position = "];
Print["16c peak position = ", m16c];
m32c = Input["32c peak position = "];
Print["32c peak position = ", m32c];
m64c = Input["64c peak position = "];
Print["64c peak position = ", m64c];
m128c = Input["128c peak position = "];
Print["128c peak position = ", m128c];

m0c = m2c - (m4c - m2c)*2;
m2c=m2c-m0c;
m4c=m4c-m0c;
m8c=m8c-m0c;
m16c=m16c-m0c;
m32c=m32c-m0c;
m64c=m64c-m0c;
m128c=m128c-m0c;
Sdata = Take[data,{(m0c+1),512}];

AxOrigine=AxesOrigin->{0,0};
PRange=PlotRange->{0,MaxHeight*1.2};
PJoined=PlotJoined->True;
PStyle=PlotStyle->{AbsoluteThickness[0.02],GrayLevel[0]};
GLines=GridLines->{{m2c,m4c,m8c,m16c, m32c,m64c,m128c}, None};
PLabel=PlotLabel->"";
dataPlot=ListPlot[Sdata, AxOrigine, PRange, PJoined, PStyle, GLines, PLabel]

For[i=50, Max[Take[Sdata,{i, i}]]<MaxHeight,i+=1,i=i];
Print["Maximum peak position in shifted histogram = ", i];
W= Input["% height for CV calc = "];
Print["Selected height (%) = ",W];
mMax=i;
i=mMax;
For[i=i,Sdata[[i]]>MaxHeight*(W/100),i+=1,i=i];
i=i-1;
j=mMax;
For[j=j,Sdata[[j]]>MaxHeight*(W/100),j-=1,j=j];
j=j+1;
WF=1/2*(Log[10]-Log[W/100])^0.5;
CVmaxR = WF*(i - mMax)/mMax;
CVmaxL = WF*(mMax - j)/mMax;
Print["Peak CV from right= ",CVmaxR]
Print["Peak CV from left= ",CVmaxL]
CVmax = Input["peak CV = "];
MaxPloidy =Input["Input C of Max-Peak-Ploidy, example:32"];
J=0; i=MaxPloidy; For[i=i, i>2, i/=2, J=J+1]; J=J;
DevFactor = 2^J;
CV=CVmax*DevFactor;
Print["CV(%) = ",CV*100];

m2cd=(m4c-m2c)/10;
{m21,m22,m23,m24,m25,m26,m27,m28,m29}=Table[Round[t=m2c+(m2cd*i)], {i,1,9,1}];
m4cd=(m8c-m4c)/10;
{m41,m42,m43,m44,m45,m46,m47,m48,m49}=Table[Round[t=m4c+(m4cd*i)], {i,1,9,1}];
m8cd=(m16c-m8c)/10;
{m81,m82,m83,m84,m85,m86,m87,m88,m89}=Table[Round[t=m8c+(m8cd*i)], {i,1,9,1}];
m16cd=(m32c-m16c)/10;
{m161,m162,m163,m164,m165,m166,m167,m168,m169}=Table[Round[t=m16c+(m16cd*i)], {i,1,9,1}];
m32cd=(m64c-m32c)/10;
{m321,m322,m323,m324,m325,m326,m327,m328,m329}=Table[Round[t=m32c+(m32cd*i)], {i,1,9,1}];
m64cd=(m128c-m64c)/10;
{m641,m642,m643,m644,m645,m646,m647,m648,m649}=Table[Round[t=m64c+(m64cd*i)], {i,1,9,1}];
MT={m2c,m21,m22,m23,m24,m25,m26,m27,m28,m29,
m4c,m41,m42,m43,m44,m45,m46,m47,m48,m49,
m8c,m81,m82,m83,m84,m85,m86,m87,m88,m89,
m16c,m161,m162,m163,m164,m165,m166,m167,m168,m169,
m32c,m321,m322,m323,m324,m325,m326,m327,m328,m329,
m64c,m641,m642,m643,m644,m645,m646,m647,m648,m649,
m128c};

CV2c=(2 CV)/2;
{CV21,CV22,CV23,CV24,CV25,CV26,CV27,CV28,CV29}=Table[t=CV2c*(1/(1+0.1*i)), {i,1,9,1}];
CV4c=(2 CV)/3;
{CV41,CV42,CV43,CV44,CV45,CV46,CV47,CV48,CV49}=Table[t=CV4c*(1/(1+0.1*i)), {i,1,9,1}];
CV8c=(2 CV)/4;
{CV81,CV82,CV83,CV84,CV85,CV86,CV87,CV88,CV89}=Table[t=CV8c*(1/(1+0.1*i)), {i,1,9,1}];
CV16c=(2 CV)/5;
{CV161,CV162,CV163,CV164,CV165,CV166,CV167,CV168,CV169}=Table[t=CV16c*(1/(1+0.1*i)), {i,1,9,1}];
CV32c=(2 CV)/6;
{CV321,CV322,CV323,CV324,CV325,CV326,CV327,CV328,CV329}=Table[t=CV32c*(1/(1+0.1*i)), {i,1,9,1}];
CV64c=(2 CV)/7;
{CV641,CV642,CV643,CV644,CV645,CV646,CV647,CV648,CV649}=Table[t=CV64c*(1/(1+0.1*i)), {i,1,9,1}];
CV128c=(2 CV)/8;
CVT={CV2c,CV21,CV22,CV23,CV24,CV25,CV26,CV27,CV28,CV29,
CV4c,CV41,CV42,CV43,CV44,CV45,CV46,CV47,CV48,CV49,
CV8c,CV81,CV82,CV83,CV84,CV85,CV86,CV87,CV88,CV89,
CV16c,CV161,CV162,CV163,CV164,CV165,CV166,CV167,CV168,CV169,
CV32c,CV321,CV322,CV323,CV324,CV325,CV326,CV327,CV328,CV329,
CV64c,CV641,CV642,CV643,CV644,CV645,CV646,CV647,CV648,CV649,
CV128c};
Print["Gausian CV finished"];

p=(2 Pi)^0.5; B = CVT MT; B = p B;
{N2c,N21,N22,N23,N24,N25,N26,N27,N28,N29,
N4c,N41,N42,N43,N44,N45,N46,N47,N48,N49,
N8c,N81,N82,N83,N84,N85,N86,N87,N88,N89,
N16c,N161,N162,N163,N164,N165,N166,N167,N168,N169,
N32c,N321,N322,N323,N324,N325,N326,N327,N328,N329,
N64c,N641,N642,N643,N644,N645,N646,N647,N648,N649,
N128c} = 1/B;
Print["Gausian factor finished"];

f = 512 - m0c;
T= Table[0,{x,1,f}];
Do[T[[x]]=N2c Exp[-((x-(m2c))^2)/(2 (m2c CV2c)^2)],{x,m2c-20,m2c+20}];T2c=T;T=0*T;
Do[T[[x]]=N21 Exp[-((x-(m21))^2)/(2 (m21 CV21)^2)],{x,m21-20,m21+20}];T21=T;T=0*T;
Do[T[[x]]=N22 Exp[-((x-(m22))^2)/(2 (m22 CV22)^2)],{x,m22-20,m22+20}];T22=T;T=0*T;
Do[T[[x]]=N23 Exp[-((x-(m23))^2)/(2 (m23 CV23)^2)],{x,m23-20,m23+20}];T23=T;T=0*T;
Do[T[[x]]=N24 Exp[-((x-(m24))^2)/(2 (m24 CV24)^2)],{x,m24-20,m24+20}];T24=T;T=0*T;
Do[T[[x]]=N25 Exp[-((x-(m25))^2)/(2 (m25 CV25)^2)],{x,m25-20,m25+20}];T25=T;T=0*T;
Do[T[[x]]=N26 Exp[-((x-(m26))^2)/(2 (m26 CV26)^2)],{x,m26-20,m26+20}];T26=T;T=0*T;
Do[T[[x]]=N27 Exp[-((x-(m27))^2)/(2 (m27 CV27)^2)],{x,m27-20,m27+20}];T27=T;T=0*T;
Do[T[[x]]=N28 Exp[-((x-(m28))^2)/(2 (m28 CV28)^2)],{x,m28-20,m28+20}];T28=T;T=0*T;
Do[T[[x]]=N29 Exp[-((x-(m29))^2)/(2 (m29 CV29)^2)],{x,m29-20,m29+20}];T29=T;T=0*T;
Do[T[[x]]=N4c Exp[-((x-(m4c))^2)/(2 (m4c CV4c)^2)],{x,m4c-20,m4c+20}];T4c=T;T=0*T;
Do[T[[x]]=N41 Exp[-((x-(m41))^2)/(2 (m41 CV41)^2)],{x,m41-20,m41+20}];T41=T;T=0*T;
Do[T[[x]]=N42 Exp[-((x-(m42))^2)/(2 (m42 CV42)^2)],{x,m42-20,m42+20}];T42=T;T=0*T;
Do[T[[x]]=N43 Exp[-((x-(m43))^2)/(2 (m43 CV43)^2)],{x,m43-20,m43+20}];T43=T;T=0*T;
Do[T[[x]]=N44 Exp[-((x-(m44))^2)/(2 (m44 CV44)^2)],{x,m44-20,m44+20}];T44=T;T=0*T;
Do[T[[x]]=N45 Exp[-((x-(m45))^2)/(2 (m45 CV45)^2)],{x,m45-20,m45+20}];T45=T;T=0*T;
Do[T[[x]]=N46 Exp[-((x-(m46))^2)/(2 (m46 CV46)^2)],{x,m46-20,m46+20}];T46=T;T=0*T;
Do[T[[x]]=N47 Exp[-((x-(m47))^2)/(2 (m47 CV47)^2)],{x,m47-20,m47+20}];T47=T;T=0*T;
Do[T[[x]]=N48 Exp[-((x-(m48))^2)/(2 (m48 CV48)^2)],{x,m48-20,m48+20}];T48=T;T=0*T;
Do[T[[x]]=N49 Exp[-((x-(m49))^2)/(2 (m49 CV49)^2)],{x,m49-20,m49+20}];T49=T;T=0*T;
Do[T[[x]]=N8c Exp[-((x-(m8c))^2)/(2 (m8c CV8c)^2)],{x,m8c-20,m8c+20}];T8c=T;T=0*T;
Do[T[[x]]=N81 Exp[-((x-(m81))^2)/(2 (m81 CV81)^2)],{x,m81-20,m81+20}];T81=T;T=0*T;
Do[T[[x]]=N82 Exp[-((x-(m82))^2)/(2 (m82 CV82)^2)],{x,m82-20,m82+20}];T82=T;T=0*T;
Do[T[[x]]=N83 Exp[-((x-(m83))^2)/(2 (m83 CV83)^2)],{x,m83-20,m83+20}];T83=T;T=0*T;
Do[T[[x]]=N84 Exp[-((x-(m84))^2)/(2 (m84 CV84)^2)],{x,m84-20,m84+20}];T84=T;T=0*T;
Do[T[[x]]=N85 Exp[-((x-(m85))^2)/(2 (m85 CV85)^2)],{x,m85-20,m85+20}];T85=T;T=0*T;
Do[T[[x]]=N86 Exp[-((x-(m86))^2)/(2 (m86 CV86)^2)],{x,m86-20,m86+20}];T86=T;T=0*T;
Do[T[[x]]=N87 Exp[-((x-(m87))^2)/(2 (m87 CV87)^2)],{x,m87-20,m87+20}];T87=T;T=0*T;
Do[T[[x]]=N88 Exp[-((x-(m88))^2)/(2 (m88 CV88)^2)],{x,m88-20,m88+20}];T88=T;T=0*T;
Do[T[[x]]=N89 Exp[-((x-(m89))^2)/(2 (m89 CV89)^2)],{x,m89-20,m89+20}];T89=T;T=0*T;
Do[T[[x]]=N16c Exp[-((x-(m16c))^2)/(2 (m16c CV16c)^2)],{x,m16c-20,m16c+20}];T16c=T;T=0*T;
Do[T[[x]]=N161 Exp[-((x-(m161))^2)/(2 (m161 CV161)^2)],{x,m161-20,m161+20}];T161=T;T=0*T;
Do[T[[x]]=N162 Exp[-((x-(m162))^2)/(2 (m162 CV162)^2)],{x,m162-20,m162+20}];T162=T;T=0*T;
Do[T[[x]]=N163 Exp[-((x-(m163))^2)/(2 (m163 CV163)^2)],{x,m163-20,m163+20}];T163=T;T=0*T;
Do[T[[x]]=N164 Exp[-((x-(m164))^2)/(2 (m164 CV164)^2)],{x,m164-20,m164+20}];T164=T;T=0*T;
Do[T[[x]]=N165 Exp[-((x-(m165))^2)/(2 (m165 CV165)^2)],{x,m165-20,m165+20}];T165=T;T=0*T;
Do[T[[x]]=N166 Exp[-((x-(m166))^2)/(2 (m166 CV166)^2)],{x,m166-20,m166+20}];T166=T;T=0*T;
Do[T[[x]]=N167 Exp[-((x-(m167))^2)/(2 (m167 CV167)^2)],{x,m167-20,m167+20}];T167=T;T=0*T;
Do[T[[x]]=N168 Exp[-((x-(m168))^2)/(2 (m168 CV168)^2)],{x,m168-20,m168+20}];T168=T;T=0*T;
Do[T[[x]]=N169 Exp[-((x-(m169))^2)/(2 (m169 CV169)^2)],{x,m169-20,m169+20}];T169=T;T=0*T;
Do[T[[x]]=N32c Exp[-((x-(m32c))^2)/(2 (m32c CV32c)^2)],{x,m32c-20,m32c+20}];T32c=T;T=0*T;
Do[T[[x]]=N321 Exp[-((x-(m321))^2)/(2 (m321 CV321)^2)],{x,m321-20,m321+20}];T321=T;T=0*T;
Do[T[[x]]=N322 Exp[-((x-(m322))^2)/(2 (m322 CV322)^2)],{x,m322-20,m322+20}];T322=T;T=0*T;
Do[T[[x]]=N323 Exp[-((x-(m323))^2)/(2 (m323 CV323)^2)],{x,m323-20,m323+20}];T323=T;T=0*T;
Do[T[[x]]=N324 Exp[-((x-(m324))^2)/(2 (m324 CV324)^2)],{x,m324-20,m324+20}];T324=T;T=0*T;
Do[T[[x]]=N325 Exp[-((x-(m325))^2)/(2 (m325 CV325)^2)],{x,m325-20,m325+20}];T325=T;T=0*T;
Do[T[[x]]=N326 Exp[-((x-(m326))^2)/(2 (m326 CV326)^2)],{x,m326-20,m326+20}];T326=T;T=0*T;
Do[T[[x]]=N327 Exp[-((x-(m327))^2)/(2 (m327 CV327)^2)],{x,m327-20,m327+20}];T327=T;T=0*T;
Do[T[[x]]=N328 Exp[-((x-(m328))^2)/(2 (m328 CV328)^2)],{x,m328-20,m328+20}];T328=T;T=0*T;
Do[T[[x]]=N329 Exp[-((x-(m329))^2)/(2 (m329 CV329)^2)],{x,m329-20,m329+20}];T329=T;T=0*T;
Do[T[[x]]=N64c Exp[-((x-(m64c))^2)/(2 (m64c CV64c)^2)],{x,m64c-20,m64c+20}];T64c=T;T=0*T;
Do[T[[x]]=N641 Exp[-((x-(m641))^2)/(2 (m641 CV641)^2)],{x,m641-20,m641+20}];T641=T;T=0*T;
Do[T[[x]]=N642 Exp[-((x-(m642))^2)/(2 (m642 CV642)^2)],{x,m642-20,m642+20}];T642=T;T=0*T;
Do[T[[x]]=N643 Exp[-((x-(m643))^2)/(2 (m643 CV643)^2)],{x,m643-20,m643+20}];T643=T;T=0*T;
Do[T[[x]]=N644 Exp[-((x-(m644))^2)/(2 (m644 CV644)^2)],{x,m644-20,m644+20}];T644=T;T=0*T;
Do[T[[x]]=N645 Exp[-((x-(m645))^2)/(2 (m645 CV645)^2)],{x,m645-20,m645+20}];T645=T;T=0*T;
Do[T[[x]]=N646 Exp[-((x-(m646))^2)/(2 (m646 CV646)^2)],{x,m646-20,m646+20}];T646=T;T=0*T;
Do[T[[x]]=N647 Exp[-((x-(m647))^2)/(2 (m647 CV647)^2)],{x,m647-20,m647+20}];T647=T;T=0*T;
Do[T[[x]]=N648 Exp[-((x-(m648))^2)/(2 (m648 CV648)^2)],{x,m648-20,m648+20}];T648=T;T=0*T;
Do[T[[x]]=N649 Exp[-((x-(m649))^2)/(2 (m649 CV649)^2)],{x,m649-20,m649+20}];T649=T;T=0*T;
Do[T[[x]]=N128c Exp[-((x-(m128c))^2)/(2 (m128c CV128c)^2)],{x,m128c-20,m128c+20}];T128c=T;T=0*T;

TS2 = T21+T22+T23+T24+T25+T26+T27+T28+T29;
TS4 = T41+T42+T43+T44+T45+T46+T47+T48+T49;
TS8 = T81+T82+T83+T84+T85+T86+T87+T88+T89;
TS16 = T161+T162+T163+T164+T165+T166+T167+T168+T169;
TS32 = T321+T322+T323+T324+T325+T326+T327+T328+T329;
TS64 = T641+T642+T643+T644+T645+T646+T647+T648+T649;

Z=Apply[Plus,Take[Sdata,{1,f}]];

Vm2c =Max[Take[Sdata, {m2c-3,m2c+3}]];
Vm25= Min[Take[Sdata,{m25-8, m25+8}]];
Vm4c =Max[Take[Sdata, {m4c-3,m4c+3}]];
Vm45= Min[Take[Sdata,{m45-8, m45+8}]];
Vm8c =Max[Take[Sdata, {m8c-3,m8c+3}]];
Vm85= Min[Take[Sdata,{m85-8, m85+8}]];
Vm16c=Max[Take[Sdata, {m16c-3,m16c+3}]];
Vm165=Min[Take[Sdata,{m165-8, m165+8}]];
Vm32c=Max[Take[Sdata, {m32c-3,m32c+3}]];
Vm325=Min[Take[Sdata,{m325-8, m325+8}]];
Vm64c=Max[Take[Sdata, {m64c-3,m64c+3}]];
Vm645=Min[Take[Sdata,{m645-8, m645+8}]];
Vm128c=Max[Take[Sdata, {m128c-3,m128c+3}]];
Print["Vm2c =",Vm2c]
Print["Vm4c =",Vm4c]
Print["Vm8c =",Vm8c]
Print["Vm16c =",Vm16c]
Print["Vm32c =",Vm32c]
Print["Vm64c =",Vm64c]
Print["Vm128c =",Vm128c]

ZTS2 = Z*TS2;
For[FS2=0, FS2 ZTS2[[m25]]<Vm25, FS2 += 0.1];
For[FS2=FS2-0.1, FS2 ZTS2[[m25]]<Vm25, FS2 += 0.01];
For[FS2=FS2-0.01, FS2 ZTS2[[m25]]<Vm25, FS2 += 0.001];
For[FS2=FS2-0.001, FS2 ZTS2[[m25]]<Vm25, FS2 += 0.0001];
FS2=FS2-0.0001;
If[FS2<0,FS2=0,FS2=FS2];

ZTS4 = Z*TS4;
For[FS4=0, FS4 ZTS4[[m45]]<Vm45, FS4 += 0.1];
For[FS4=FS4-0.1, FS4 ZTS4[[m45]]<Vm45, FS4 += 0.01];
For[FS4=FS4-0.01, FS4 ZTS4[[m45]]<Vm45, FS4 += 0.001];
For[FS4=FS4-0.001, FS4 ZTS4[[m45]]<Vm45, FS4 += 0.0001];
FS4=FS4-0.0001;
If[FS4<0,FS4=0,FS4=FS4];

ZTS8 = Z*TS8;
For[FS8=0, FS8 ZTS8[[m85]]<Vm85, FS8 += 0.1];
For[FS8=FS8-0.1, FS8 ZTS8[[m85]]<Vm85, FS8 += 0.01];
For[FS8=FS8-0.01, FS8 ZTS8[[m85]]<Vm85, FS8 += 0.001];
For[FS8=FS8-0.001, FS8 ZTS8[[m85]]<Vm85, FS8 += 0.0001];
FS8=FS8-0.0001;
If[FS8<0,FS8=0,FS8=FS8];

ZTS16 = Z*TS16;
For[FS16=0, FS16 ZTS16[[m165]]<Vm165, FS16 += 0.1];
For[FS16=FS16-0.1, FS16 ZTS16[[m165]]<Vm165, FS16 += 0.01];
For[FS16=FS16-0.01, FS16 ZTS16[[m165]]<Vm165, FS16 += 0.001];
For[FS16=FS16-0.001, FS16 ZTS16[[m165]]<Vm165, FS16 += 0.0001];
FS16=FS16-0.0001;
If[FS16<0,FS16=0,FS16=FS16];

ZTS32 = Z*TS32;
For[FS32=0, FS32 ZTS32[[m325]]<Vm325, FS32 += 0.1];
For[FS32=FS32-0.1, FS32 ZTS32[[m325]]<Vm325, FS32 += 0.01];
For[FS32=FS32-0.01, FS32 ZTS32[[m325]]<Vm325, FS32 += 0.001];
For[FS32=FS32-0.001, FS32 ZTS32[[m325]]<Vm325, FS32 += 0.0001];
FS32=FS32-0.0001;
If[FS32<0,FS32=0,FS32=FS32];

ZTS64 = Z*TS64;
For[FS64=0, FS64 ZTS64[[m645]]<Vm645, FS64 += 0.1];
For[FS64=FS64-0.1, FS64 ZTS64[[m645]]<Vm645, FS64 += 0.01];
For[FS64=FS64-0.01, FS64 ZTS64[[m645]]<Vm645, FS64 += 0.001];
For[FS64=FS64-0.001, FS64 ZTS64[[m645]]<Vm645, FS64 += 0.0001];
FS64=FS64;
If[FS64<0,FS64=0,FS64=FS64];

FZTS2=FS2*ZTS2;
FZTS4=FS4*ZTS4;
FZTS8=FS8*ZTS8;
FZTS16=FS16*ZTS16;
FZTS32=FS32*ZTS32;
FZTS64=FS64*ZTS64;

ZT2c=Z T2c;
For[F2c=0,Max[Take[(F2c ZT2c)+FZTS2,{m2c-1,m2c+1}]]<Vm2c, F2c += 0.1];
For[F2c=F2c-0.1,Max[Take[(F2c ZT2c)+FZTS2,{m2c-1,m2c+1}]]<Vm2c, F2c += 0.01];
For[F2c=F2c-0.01,Max[Take[(F2c ZT2c)+FZTS2,{m2c-1,m2c+1}]]<Vm2c, F2c += 0.001];
For[F2c=F2c-0.001,Max[Take[(F2c ZT2c)+FZTS2,{m2c-1,m2c+1}]]<Vm2c, F2c += 0.0001];
F2c=F2c;
If[F2c<0,F2c=0,F2c=F2c];

ZT4c=Z T4c;
For[F4c=0,Max[Take[(F4c ZT4c)+FZTS2+FZTS4,{m4c-1,m4c+1}]]<Vm4c, F4c += 0.1];
For[F4c=F4c-0.1,Max[Take[(F4c ZT4c)+FZTS2+FZTS4,{m4c-1,m4c+1}]]<Vm4c, F4c += 0.01];
For[F4c=F4c-0.01,Max[Take[(F4c ZT4c)+FZTS2+FZTS4,{m4c-1,m4c+1}]]<Vm4c, F4c += 0.001];
For[F4c=F4c-0.001,Max[Take[(F4c ZT4c)+FZTS2+FZTS4,{m4c-1,m4c+1}]]<Vm4c, F4c += 0.0001];
F4c=F4c;
If[F4c<0,F4c=0,F4c=F4c];

ZT8c=Z T8c;
For[F8c=0,Max[Take[(F8c ZT8c)+FZTS4+FZTS8,{m8c-1,m8c+1}]]<Vm8c, F8c += 0.1];
For[F8c=F8c-0.1,Max[Take[(F8c ZT8c)+FZTS4+FZTS8,{m8c-1,m8c+1}]]<Vm8c, F8c += 0.01];
For[F8c=F8c-0.01,Max[Take[(F8c ZT8c)+FZTS4+FZTS8,{m8c-1,m8c+1}]]<Vm8c, F8c += 0.001];
For[F8c=F8c-0.001,Max[Take[(F8c ZT8c)+FZTS4+FZTS8,{m8c-1,m8c+1}]]<Vm8c, F8c += 0.0001];
F8c=F8c;
If[F8c<0,F8c=0,F8c=F8c];

ZT16c=Z T16c;
For[F16c=0,Max[Take[(F16c ZT16c)+FZTS8+FZTS16,{m16c-1,m16c+1}]]<Vm16c, F16c += 0.1];
For[F16c=F16c-0.1,Max[Take[(F16c ZT16c)+FZTS8+FZTS16,{m16c-1,m16c+1}]]<Vm16c, F16c += 0.01];
For[F16c=F16c-0.01,Max[Take[(F16c ZT16c)+FZTS8+FZTS16,{m16c-1,m16c+1}]]<Vm16c, F16c += 0.001];
For[F16c=F16c-0.001,Max[Take[(F16c ZT16c)+FZTS8+FZTS16,{m16c-1,m16c+1}]]<Vm16c, F16c += 0.0001];
F16c=F16c;
If[F16c<0,F16c=0,F16c=F16c];

ZT32c=Z T32c;
For[F32c=0,Max[Take[(F32c ZT32c)+FZTS16+FZTS32,{m32c-1,m32c+1}]]<Vm32c, F32c += 0.1];
For[F32c=F32c-0.1,Max[Take[(F32c ZT32c)+FZTS16+FZTS32,{m32c-1,m32c+1}]]<Vm32c, F32c += 0.01];
For[F32c=F32c-0.01,Max[Take[(F32c ZT32c)+FZTS16+FZTS32,{m32c-1,m32c+1}]]<Vm32c, F32c += 0.001];
For[F32c=F32c-0.001,Max[Take[(F32c ZT32c)+FZTS16+FZTS32,{m32c-1,m32c+1}]]<Vm32c, F32c += 0.0001];
F32c=F32c;
If[F32c<0,F32c=0,F32c=F32c];

ZT64c=Z T64c;
For[F64c=0,Max[Take[(F64c ZT64c)+FZTS32+FZTS64,{m64c-1,m64c+1}]]<Vm64c, F64c += 0.1];
For[F64c=F64c-0.1,Max[Take[(F64c ZT64c)+FZTS32+FZTS64,{m64c-1,m64c+1}]]<Vm64c, F64c += 0.01];
For[F64c=F64c-0.01,Max[Take[(F64c ZT64c)+FZTS32+FZTS64,{m64c-1,m64c+1}]]<Vm64c, F64c += 0.001];
For[F64c=F64c-0.001,Max[Take[(F64c ZT64c)+FZTS32+FZTS64,{m64c-1,m64c+1}]]<Vm64c, F64c += 0.0001];
F64c=F64c;
If[F64c<0,F64c=0,F64c=F64c];

ZT128c=Z T128c;
For[F128c=0,Max[Take[(F128c ZT128c)+ FZTS64,{m128c-1,m128c+1}]]<Vm128c, F128c += 0.1];
For[F128c=F128c-0.1,Max[Take[(F128c ZT128c)+ FZTS64,{m128c-1,m128c+1}]]<Vm128c, F128c += 0.01];
For[F128c=F128c-0.01,Max[Take[(F128c ZT128c)+ FZTS64,{m128c-1,m128c+1}]]<Vm128c, F128c += 0.001];
For[F128c=F128c-0.001,Max[Take[(F128c ZT128c)+ FZTS64,{m128c-1,m128c+1}]]<Vm128c, F128c += 0.0001];
F128c=F128c;
If[F128c<0,F128c=0,F128c=F128c];

FZT = F2c ZT2c + FS2 ZTS2 + F4c ZT4c + FS4 ZTS4 + F8c ZT8c + FS8 ZTS8 +
F16c ZT16c+ FS16 ZTS16 + F32c ZT32c + FS32 ZTS32 + F64c ZT64c+ FS64 ZTS64 + F128c ZT128c;

PRange = PlotRange ->{0,MaxHeight*1.2};
PJoined = PlotJoined->True;
Fram = Frame->True;
PStyle = PlotStyle->{AbsoluteThickness[0.02], RGBColor[0,0,1]};
GLines = GridLines->{None,None};
PLabel = PlotLabel->"";
FLabel = FrameLabel->{"Channel Number","Cell Number"};
XTics = Ticks->{{{m2c,2},{m4c,4},{m8c,8},{m16c,16},{m32c,32},{m64c,64},{m128c,128}},Automatic};
IPlot = ListPlot[FZT, PRange, PJoined,XTics, PStyle, PLabel,GLines];
Show[IPlot,dataPlot]

Diff = Sdata-FZT;

TC={T21,T22,T23,T24,T25,T26,T27,T28,T29,
T41,T42,T43,T44,T45,T46,T47,T48,T49,
T81,T82,T83,T84,T85,T86,T87,T88,T89,
T161,T162,T163,T164,T165,T166,T167,T168,T169,
T321,T322,T323,T324,T325,T326,T327,T328,T329,
T641,T642,T643,T644,T645,T646,T647,T648,T649};

MC={m21,m22,m23,m24,m25,m26,m27,m28,m29,
m41,m42,m43,m44,m45,m46,m47,m48,m49,
m81,m82,m83,m84,m85,m86,m87,m88,m89,
m161,m162,m163,m164,m165,m166,m167,m168,m169,
m321,m322,m323,m324,m325,m326,m327,m328,m329,
m641,m642,m643,m644,m645,m646,m647,m648,m649};

ZTC = Z TC;
K=0;
FC = Table[K,{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.01, FC[[i]]=FC[[i]]-0.01],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.01, FC[[i]]=FC[[i]]-0.01],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.01, FC[[i]]=FC[[i]]-0.01],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.01, FC[[i]]=FC[[i]]-0.01],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.01, FC[[i]]=FC[[i]]-0.01],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.01, FC[[i]]=FC[[i]]-0.01],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.01, FC[[i]]=FC[[i]]-0.01],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.01, FC[[i]]=FC[[i]]-0.01],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.01, FC[[i]]=FC[[i]]-0.01],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.01, FC[[i]]=FC[[i]]-0.01],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.001, FC[[i]]=FC[[i]]-0.001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.001, FC[[i]]=FC[[i]]-0.001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.001, FC[[i]]=FC[[i]]-0.001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.001, FC[[i]]=FC[[i]]-0.001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.001, FC[[i]]=FC[[i]]-0.001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.001, FC[[i]]=FC[[i]]-0.001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.001, FC[[i]]=FC[[i]]-0.001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.001, FC[[i]]=FC[[i]]-0.001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.001, FC[[i]]=FC[[i]]-0.001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.001, FC[[i]]=FC[[i]]-0.001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.0001, FC[[i]]=FC[[i]]-0.0001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.0001, FC[[i]]=FC[[i]]-0.0001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.0001, FC[[i]]=FC[[i]]-0.0001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.0001, FC[[i]]=FC[[i]]-0.0001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.0001, FC[[i]]=FC[[i]]-0.0001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.0001, FC[[i]]=FC[[i]]-0.0001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.0001, FC[[i]]=FC[[i]]-0.0001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.0001, FC[[i]]=FC[[i]]-0.0001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.0001, FC[[i]]=FC[[i]]-0.0001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FZC[[MC[[i]]]]<Diff[[MC[[i]]]],FC[[i]] +=0.0001, FC[[i]]=FC[[i]]-0.0001],{i,54}];
FZC= Sum[(FC[[i]] ZTC[[i]]),{i,54}];
Do[If[FC[[i]]<0,FC[[i]]=0,FC[[i]]=FC[[i]]],{i,54}];

{FC1,FC2,FC3,FC4,FC5,FC6,FC7,FC8,FC9,
FC10,FC11,FC12,FC13,FC14,FC15,FC16,FC17,FC18,
FC19,FC20,FC21,FC22,FC23,FC24,FC25,FC26,FC27,
FC28,FC29,FC30,FC31,FC32,FC33,FC34,FC35,FC36,
FC37,FC38,FC39,FC40,FC41,FC42,FC43,FC44,FC45,
FC46,FC47,FC48,FC49,FC50,FC51,FC52,FC53,FC54}=FC;

FC2T=FC1+FC2+FC3+FC4+FC5+FC6+FC7+FC8+FC9;
FC4T=FC10+FC11+FC12+FC13+FC14+FC15+FC16+FC17+FC18;
FC8T=FC19+FC20+FC21+FC22+FC23+FC24+FC25+FC26+FC27;
FC16T=FC28+FC29+FC30+FC31+FC32+FC33+FC34+FC35+FC36;
FC32T=FC37+FC38+FC39+FC40+FC41+FC42+FC43+FC44+FC45;
FC64T=FC46+FC47+FC48+FC49+FC50+FC51+FC52+FC53+FC54;

FZ = FZT +FZC;

PRange = PlotRange ->{0,MaxHeight*1.2};
PJoined = PlotJoined->True;
Fram = Frame->True;
PStyle = PlotStyle->{AbsoluteThickness[0.02], RGBColor[1,0,0]};
GLines = GridLines->{None,None};
PLabel = PlotLabel->"";
FLabel = FrameLabel->{"Channel Number","Cell Number"};
XTics = Ticks->{{{m2c,2},{m4c,4},{m8c,8},{m16c,16},{m32c,32},{m64c,64},{m128c,128}},Automatic};
APlot = ListPlot[FZ, PRange, PJoined, PStyle, XTics, PLabel,GLines];
Show[APlot, dataPlot]
Show[IPlot, APlot, dataPlot]

FT = F2c+F4c+F8c+F16c+F32c+F64c+F128c+
9 (FS2+FS4+FS8+FS16+FS32+FS64)+
FC2T+FC4T+FC8T+FC16T+FC32T+FC64T;
V2c =F2c/FT;
V2S =(9 FS2+FC2T)/FT;
V4c =F4c/FT;
V4S =(9 FS4+FC4T)/FT;
V8c =F8c/FT;
V8S =(9 FS8+FC8T)/FT;
V16c =F16c/FT;
V16S =(9 FS16+FC16T)/FT;
V32c =F32c/FT;
V32S =(9 FS32+FC32T)/FT;
V64c =F64c/FT;
V64S =(9 FS64+FC64T)/FT;
V128c=F128c/FT;

Print["CV = ",CV]
Print["Cell Number = ",Z]
Print["2c Fraction = ",V2c]
Print["2S Fraction = ",V2S]
Print["4c Fraction = ",V4c]
Print["4S Fraction = ",V4S]
Print["8c Fraction = ",V8c]
Print["8S Fraction = ",V8S]
Print["16c Fraction = ",V16c]
Print["16S Fraction = ",V16S]
Print["32c Fraction = ",V32c]
Print["32S Fraction = ",V32S]
Print["64c Fraction = ",V64c]
Print["64S Fraction = ",V64S]
Print["128c Fraction = ",V128c]

Play[Sin[2Pi 880 t],{t,0,3}]

                

もとに戻る