Quasi-periodic decoupled system: periodic solution (rational slope (Subscript[ω, 1])/(Subscript[ω, 2]))

Clear[tmax]
ω1=2; (*ω natural frequency*)
ω2=3;
tmax=3 π;

Style[StringForm["Ratio of fundamental frequencies ``",ω1/ω2] ,Red,17]
Style[StringForm["Is ω1/ω2 rational?: ``",ω1/ω2∈Rationals] ,Red,17]
dθ1=ω1; (*θ phase*)
dθ2=ω2;
sp=StreamPlot[{dθ1,dθ2},{θ1,0,2 π},{θ2,0,2 π},FrameLabel->{θ1[t],θ2[t]},LabelStyle->20];
integ=NDSolve[{
θ1'[t]==ω1,
θ2'[t]==ω2,
θ1[0]==0,θ2[0]==1},
{θ1,θ2},{t,0,tmax}];
plot1=ParametricPlot[Evaluate[{θ1[t],θ2[t]}/.integ],{t,0,tmax},AxesLabel->{θ1[t],θ2[t]},ImageSize->260,PlotStyle->Red,LabelStyle->20];
plot2=Plot[Evaluate[θ1[t]/.integ],{t,0,tmax},AxesLabel-> {t,θ1[t]},PlotRange-> All,ImageSize->260,LabelStyle->20];
plot3=Plot[Evaluate[θ2[t]/.integ],{t,0,tmax},AxesLabel-> {t,θ2[t]},PlotRange-> All,ImageSize->260,LabelStyle->20];
Show[sp,plot1]
Row[{plot1,plot2,plot3}]
sinp1=Plot[Evaluate[Cos[θ1[t]]/.integ],{t,0,tmax},AxesLabel-> {t,Cos[θ1]},PlotRange-> All,ImageSize->420,LabelStyle->20];
sinp2=Plot[Evaluate[Sin[θ2[t]]/.integ],{t,0,tmax},AxesLabel-> {t,Sin[θ2]},PlotRange-> All,ImageSize->420,LabelStyle->20];
Row[{sinp1,sinp2}]

pplo1=ParametricPlot[Evaluate[{
Cos[θ1[t]],
D[Cos[θ1[t]],t]}/.integ],
{t,0,tmax},
AxesLabel-> {"cos θ1","(∂_t)cos θ1"},PlotLabel->"Phase portrait of cos θ1",PlotRange->{{-1.01,1.01},All},ImageSize->360,LabelStyle->20];

pplo2=ParametricPlot[Evaluate[{
Sin[θ2[t]],
D[Sin[θ2[t]],t]}/.integ],
{t,0,tmax},
AxesLabel-> {"sin θ2","(∂_t)sin θ2"},PlotLabel->"Phase portrait of sin θ2",PlotRange->{{-1.01,1.01},All},ImageSize->360,LabelStyle->20];
Row[{pplo1,pplo2}]

Power spectrum of the signals

Clear[tmax]
ω1=2; (*ω natural frequency*)
ω2=3;
tmax=10 π;

Style[StringForm["Ratio of fundamental frequencies ``",ω1/ω2] ,Red,17]
Style[StringForm["Is ω1/ω2 rational?: ``",ω1/ω2∈Rationals] ,Red,17]
integ=NDSolve[{
θ1'[t]==ω1,
θ2'[t]==ω2,
θ1[0]==0,θ2[0]==1},
{θ1,θ2},{t,0,tmax}];
sinp1=Plot[Evaluate[Cos[θ1[t]]/.integ],{t,0,tmax},AxesLabel-> {t,Cos[θ1]},PlotRange-> All,ImageSize->380,LabelStyle->20];
sinp2=Plot[Evaluate[Sin[θ2[t]]/.integ],{t,0,tmax},AxesLabel-> {t,Sin[θ2]},PlotRange-> All,ImageSize->380,LabelStyle->20];

sr=11;(*Sampling Rate: keep Nyquist limit in mind*)
signal=Table[Evaluate[Cos[θ1[t]]/.integ[[1]]],{t,0,tmax,1/sr}];(*sample values*)
signal2=Table[Evaluate[Sin[θ2[t]]/.integ[[1]]],{t,0,tmax,1/sr}];(*sample values*)
ft=Fourier[signal,FourierParameters->{-1,-1}];(*num fourier transform*)
ft2=Fourier[signal2,FourierParameters->{-1,-1}];(*num fourier transform*)
ff=Table[2 π (n-1) sr/Length[signal],{n,Length[signal]}];(*frequency values x-axis*)
specter1=ListLinePlot[Transpose[{ff,Log[Abs[ft]^2]}][[1;;Round[0.5 Length[signal]]]],PlotRange->All,Frame->True,FrameLabel->{"Frequency ω","Spectral Power Level"},ImageSize->380,LabelStyle->20];
specter2=ListLinePlot[Transpose[{ff,Log[Abs[ft2]^2]}][[1;;Round[0.5 Length[signal]]]],PlotRange->All,Frame->True,FrameLabel->{"Frequency ω","Spectral Power Level"},ImageSize->380,LabelStyle->20];
Row[{sinp1,specter1}]
Row[{sinp2,specter2}]

Quasi-periodic decoupled system: quasi-periodic solution (irrational slope (Subscript[ω, 1])/(Subscript[ω, 2]))

Clear[tmax,ω1,ω2]
ω1=E; (*ω natural frequency*)
ω2=1;
tmax=3 π;

Style[StringForm["Ratio of fundamental frequencies ``",ω1/ω2] ,Red,17]
Style[StringForm["Is ω1/ω2 rational?: ``",ω1/ω2∈Rationals] ,Red,17]
dθ1=ω1; (*θ phase*)
dθ2=ω2;
sp=StreamPlot[{dθ1,dθ2},{θ1,0,2 π},{θ2,0,2 π},FrameLabel->{θ1[t],θ2[t]},LabelStyle->20];
integ=NDSolve[{
θ1'[t]==ω1,
θ2'[t]==ω2,
θ1[0]==0,θ2[0]==1},
{θ1,θ2},{t,0,tmax}];
plot1=ParametricPlot[Evaluate[{θ1[t],θ2[t]}/.integ],{t,0,tmax},AxesLabel->{θ1[t],θ2[t]},ImageSize->260,PlotStyle->Red,LabelStyle->20];
plot2=Plot[Evaluate[θ1[t]/.integ],{t,0,tmax},AxesLabel-> {t,θ1[t]},PlotRange-> All,ImageSize->260,LabelStyle->20];
plot3=Plot[Evaluate[θ2[t]/.integ],{t,0,tmax},AxesLabel-> {t,θ2[t]},PlotRange-> All,ImageSize->260,LabelStyle->20];
Show[sp,plot1]
Row[{plot1,plot2,plot3}]
sinp1=Plot[Evaluate[Cos[θ1[t]]/.integ],{t,0,tmax},AxesLabel-> {t,Cos[θ1]},PlotRange-> All,ImageSize->420,LabelStyle->20];
sinp2=Plot[Evaluate[Sin[θ2[t]]/.integ],{t,0,tmax},AxesLabel-> {t,Sin[θ2]},PlotRange-> All,ImageSize->420,LabelStyle->20];
Row[{sinp1,sinp2}]
pplo1=ParametricPlot[Evaluate[{
Cos[θ1[t]],
D[Cos[θ1[t]],t]}/.integ],{t,0,tmax},
AxesLabel-> {"cos θ1","(∂_t)cos θ1"},PlotLabel->"Phase portrait of cos θ1",PlotRange->{{-1.01,1.01},All},ImageSize->360,LabelStyle->20];
pplo2=ParametricPlot[Evaluate[{
Sin[θ2[t]],
D[Sin[θ2[t]],t]}/.integ],{t,0,tmax},
AxesLabel-> {"sin θ2","(∂_t)sin θ2"},PlotLabel->"Phase portrait of sin θ2",PlotRange->{{-1.01,1.01},All},ImageSize->360,LabelStyle->20];
Row[{pplo1,pplo2}]

Power spectrum of the signals

Clear[tmax]
ω1=E; (*ω natural frequency*)
ω2=1;
tmax=10 π;

Style[StringForm["Ratio of fundamental frequencies ``",ω1/ω2] ,Red,17]
Style[StringForm["Is ω1/ω2 rational?: ``",ω1/ω2∈Rationals] ,Red,17]
integ=NDSolve[{
θ1'[t]==ω1,
θ2'[t]==ω2,
θ1[0]==0,θ2[0]==1},
{θ1,θ2},{t,0,tmax}];
sinp1=Plot[Evaluate[Sin[θ1[t]]/.integ],{t,0,tmax},AxesLabel-> {t,Sin[θ1]},PlotRange-> All,ImageSize->380,LabelStyle->20];
sinp2=Plot[Evaluate[Sin[θ2[t]]/.integ],{t,0,tmax},AxesLabel-> {t,Sin[θ2]},PlotRange-> All,ImageSize->380,LabelStyle->20];

sr=11;(*Sampling Rate: keep Nyquist limit in mind*)
signal=Table[Evaluate[Cos[θ1[t]]/.integ[[1]]],{t,0,tmax,1/sr}];(*sample values*)
signal2=Table[Evaluate[Sin[θ2[t]]/.integ[[1]]],{t,0,tmax,1/sr}];(*sample values*)
ft=Fourier[signal,FourierParameters->{-1,-1}];(*num fourier transform*)
ft2=Fourier[signal2,FourierParameters->{-1,-1}];(*num fourier transform*)
ff=Table[2 π (n-1) sr/Length[signal],{n,Length[signal]}];(*frequency values x-axis*)
specter1=ListLinePlot[Transpose[{ff,Log[Abs[ft]^2]}][[1;;Round[0.5 Length[signal]]]],PlotRange->All,Frame->True,FrameLabel->{"Frequency ω","Spectral Power Level"},ImageSize->380,LabelStyle->20];
specter2=ListLinePlot[Transpose[{ff,Log[Abs[ft2]^2]}][[1;;Round[0.5 Length[signal]]]],PlotRange->All,Frame->True,FrameLabel->{"Frequency ω","Spectral Power Level"},ImageSize->380,LabelStyle->20];
Row[{sinp1,specter1}]
Row[{sinp2,specter2}]

Creation of this notebook was supported by IT Academy program of Information Technology Foundation for Education (HITSA).