这个问题是基于给出的优雅解决方案而提出的这里。
我已经更新了方程式。对于调频 (FM) 信号,这些是方程式:
Carrier = cos(2*pi*fc*t)
Modulation = sin(2*pi*fm*t)
FM = cos(2*pi*fc*t+5*sin(2*pi*fm*t))
我正在尝试获取这个图的 FM:
您能帮助我获得正确的输出吗?谢谢!
这是我根据原始解决方案修改后的代码:
代码
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{animate}
\usepackage{xsavebox} % xlrbox
\usepackage{calc} % \widthof{...}, \real{...}
\usepackage{amsmath}
\begin{document}
%
%save two cycles in an xlrbox
\begin{xlrbox}{TwoCycles}
\begin{tikzpicture}
\begin{axis}[hide axis]
\addplot[domain=-2*pi:2*pi,black,samples=501] {sin(x*2*180/pi)};
\addplot[domain=-2*pi:2*pi,blue,samples=501] {cos(x*10*180/pi)-2.5};
\addplot[domain=-2*pi:2*pi,red,samples=501] {cos(x*10*180/pi + 5*sin(x*2*180/pi))-5};
\end{axis}
\end{tikzpicture}
\end{xlrbox}%
%
\begin{animateinline}[controls,loop,width=12cm,height=6cm]{10}
\multiframe{36}{i=0+1}{
\makebox[\widthof{\theTwoCycles}][l]{% window
\makebox[\widthof{\theTwoCycles}/\real{72}*\real{-\i}]{}% offset
\theTwoCycles\theTwoCycles%
}
}
\end{animateinline}
\end{document}
答案1
180/pi
PGF 的三角函数要求其参数以度为单位。因此,绘制第三条曲线时,必须将整个参数乘以。
[0:pi]
此外,通过在 中仅保存一个周期的基信号,然后在四个周期宽度的窗口中移动五个周期,进一步优化了尺寸xlrbox
。将线连接设置为,round
以防止图中出现火花。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% uncomment \def\export{} below to export animation
%% to multipage PDF a.pdf and run
%%
%% convert -density 300 -delay 4 -loop 0 -alpha remove a.pdf b.gif
%%
%% to get an animated GIF b.gif at 100/4 = 25 frames per s
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\def\export{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifdefined\export
\documentclass[export]{standalone}
\else
\documentclass{standalone}
\fi
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{animate}
\usepackage{xsavebox} % xlrbox
\usepackage{calc} % \widthof{...}, \real{...}
\usepackage{amsmath}
\begin{document}
%
%save ONE cycle in an xlrbox
\begin{xlrbox}{OneCycle}
\begin{tikzpicture}
\begin{axis}[
hide axis,
x=1cm,y=1cm,
/tikz/line cap=rect, /tikz/line join=round
]
\addplot[domain=0:pi,black,samples=250] {cos(x*2*180/pi)};
\addplot[domain=0:pi,blue,samples=500] {cos(x*20*180/pi)-2.5};
\addplot[domain=0:pi,red,samples=500] {cos((x*20 + 6*sin(x*2*180/pi))*180/pi)-5};
\end{axis}
\end{tikzpicture}
\end{xlrbox}%
%
\begin{animateinline}[controls,loop]{10}
\multiframe{18}{i=0+1}{
\makebox[\widthof{\theOneCycle}*\real{4}][l]{% window = FOUR cycles
\makebox[\widthof{\theOneCycle}/\real{18}*\real{-\i}]{}% offset
\theOneCycle\theOneCycle\theOneCycle\theOneCycle\theOneCycle% moving FIVE cycles
}
}
\end{animateinline}
\end{document}