使用动画包制作带有 FM 调制的动画余弦波形

使用动画包制作带有 FM 调制的动画余弦波形

我希望获得一些帮助来获得像这样的调制 FM 信号的动画:

在此处输入图片描述

这是我目前拥有的代码:

代码

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{tikz}
\usepackage{media9}
\usepackage{animate}[2014/11/27]

\usepackage{amsmath}

\begin{document}

\begin{animateinline}[
  %poster=1, % sin 2x (frames are numbered in zero-based manner)
  width=12cm,
  height=6cm,
  label=graph_switch,
  begin={\begin{tikzpicture}},
  end={\end{tikzpicture}},
  step
]{0}

% Carrier Signal
  \begin{axis}[
    hide axis,
    %xlabel={$x$},
    %ylabel={$\text{sin}(x)$},
    xmin=-4*pi,xmax=4*pi]
    \addplot[black,samples=101] {5*cos(x*180./pi)};
  \end{axis}

% Modulating Signal
    \begin{axis}[
    hide axis,
    %xlabel={$x$},
    %ylabel={$\text{sin}(x)$},
    xmin=-4*pi,xmax=4*pi]
    \addplot[blue,samples=501] {5*cos(6*x*180./pi)};
  \end{axis}

% Modulated Signal
    \begin{axis}[
    hide axis,
    %xlabel={$x$},
    %ylabel={$\text{sin}(x)$},
    xmin=-4*pi,xmax=4*pi]
    \addplot[red,samples=501] {5*cos(x*180./pi)*5*cos(6*x*180./pi)};
  \end{axis}


\end{animateinline}

\end{document} 

答案1

您正在寻找 AM 示例。(有关 FM,请参阅↗后续问题

绘制的方程式略有修改(根据维基百科页面↗幅度调制)。

以下是使用xsavebox包。这节省了最终 PDF 文件的大小和大量的编译时间。

  1. [0:pi]我们将基准信号的一个周期保存到xlrbox外面的animateinline
  2. 然后,通过在 4 个周期宽度的窗口中移动 5 个周期来创建动画。

在此处输入图片描述

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 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] {0.8*cos(x*2*180/pi)};
      \addplot[domain=0:pi,blue,samples=500] {cos(x*20*180/pi)-2};
      \addplot[domain=0:pi,red,samples=500] {(1+0.8*cos(x*2*180/pi))*cos(x*20*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}

答案2

像这样吗?我添加了用于调试的控件,您可以step根据autoplay需要进行设置。

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{tikz}
\usepackage{media9}
\usepackage{animate}[2014/11/27]

\usepackage{amsmath}

\tikzset{
    declare function={
        carrier(\t) = cos(\t);
        modulator(\t) = cos(6*\t);
    },
}

\pgfmathsetmacro\StepSize{10}
\pgfmathtruncatemacro\NumFrames{360/\StepSize}

\newcommand{\drawModulatedAM}[1]{%
    \begin{tikzpicture}
        \pgfmathsetmacro\PhaseShift{#1*\StepSize}
        \begin{axis}[
            hide axis,
            scale only axis,
            width = 12cm,
            height = 6cm,
            xmin=-360,
            xmax=360,
        ]
            \addplot[domain=-360:360,black,samples=101] {carrier(x+\PhaseShift)};
            \addplot[domain=-360:360,blue,samples=501] {modulator(x+\PhaseShift)-2.5};
            \addplot[domain=-360:360,red,samples=501] {modulator(x+\PhaseShift)*carrier(x+\PhaseShift) - 5};
        \end{axis}
    \end{tikzpicture}%
}

\begin{document}
    \begin{animateinline}[label=graph_switch,controls]{10}
        \multiframe{\NumFrames}{iFrame=0+1}{\drawModulatedAM{\iFrame}}
    \end{animateinline}
\end{document} 

结果:

在此处输入图片描述

相关内容