我想建立拍频原理:两个频率相近的正弦信号(S1 和 S2)的和 S 呈现出振幅的变化。我设法弄清楚了这两个正弦信号,但当我想查看和时,它与我的预期不符。
\documentclass{article}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{babel}
\begin{document}
\begin{center}
\begin{tikzpicture}[samples=1000]
\draw[->] (-5,0) -- (5.2,0) node[right] {$t$};
\draw[->] (-5,-2) -- (-5,2) node[above] {$S$};
\draw[color=blue] plot ({\x},{cos(10*\x r)});
\draw[color=green!60!black] plot ({\x},{cos(9.25*\x r)});
\draw plot ({\x},{cos(10*\x+cos(9.25*\x r)});
\end{tikzpicture}
\end{center}
\end{document}
此外,我希望能够有两张相互叠加的图表:第一张包含两个信号(S1 和 S2),另一张包含总和 S
你可以帮帮我吗 ?
答案1
对于第一个问题,你忘了一个括号。你的代码是
\draw plot ({\x},{cos(10*\x+cos(9.25*\x r)});
而且应该是
\draw plot ({\x},{cos(10*\x r)+cos(9.25*\x r)});
对于第二个问题,一个简单的方法可能是这样的:
\documentclass{standalone}
\usepackage {tikz}
\begin{document}
\begin{tikzpicture}[samples=1000]
\draw[->] (-5,0) -- (5.2,0) node[right] {$t$};
\draw[->] (-5,-2) -- (-5,2) node[above] {$S$};
\draw[color=blue] plot ({\x},{cos(10*\x r)});
\draw[color=green!60!black] plot ({\x},{cos(9.25*\x r)});
\node[color=blue] at (5,1.5) [left] {$y=\cos\omega_2x$};
\node[color=green!60!black] at (5,2) [left] {$y=\cos\omega_1x$};
% Change \y as you need, it's the distance between the two plots
\def\y{5}
\begin{scope}[shift={(0,-\y)}]
\draw[->] (-5,0) -- (5.2,0) node[right] {$t$};
\draw[->] (-5,-2) -- (-5,2) node[above] {$S$};
\draw plot ({\x},{cos(10*\x r)+cos(9.25*\x r)});
\node at (5,2) [left] {$y=\cos\omega_1x+\cos\omega_2x$};
\end{scope}
\end{tikzpicture}
\end{document}