使用 TikZ 将二进制序列转换为 NRZ、ASK、FSK

使用 TikZ 将二进制序列转换为 NRZ、ASK、FSK

我需要创建类似这样的东西: 在此处输入图片描述

发现此代码仅执行 NRZ 和 BSequence

        \documentclass{standalone}

\usepackage{tikz-timing}

\begin{document}

\begin{tikztimingtable}[timing/slope=0, scale=2, timing/draw grid, timing/name/.append style={yshift=3.5}, timing/z/.style={black}]
    01001110     & LHLLHHHL \\
    NRZ          & LHLLHHHL \\
    RZ           & 0.25Z lzh 2{zl} 3{zh} zl 0.25Z \\
    \extracode
    \makeatletter
    \begin{pgfonlayer}{background}
        \vertlines[help lines, blue]{}
        \horlines[blue, yshift=3.5]{}
        \foreach [count=\x] \b in {0,1,0,0,1,1,1,0} {
            \node [below,font=\sffamily\bfseries\tiny,inner ysep=2pt] at (\x-.5,+.5) {\b};
        }
    \end{pgfonlayer}
\end{tikztimingtable}

\end{document}

答案1

我不知道 tikz-timing 包,但这只能用 tikz 绘制,而且不太难。一个\foreach命令用于重复周期波,一个命令\ifthenelse用于绘制或不绘制底部波 (ASK),然后你就拥有了它。

像这样:

\documentclass[border=2mm]{standalone}
\usepackage{ifthen}
\usepackage{tikz}

\def\w{1} % width (T_b)
\def\h{1} % height of the signals

% draws the sin wave
\newcommand{\mysin}[2] % position,color
{%
  \begin{scope}[shift={#1}]
    \draw[thick,#2] (0,0) sin (0.125*\w,0.5*\h) cos (0.25*\w,0) sin (0.375*\w,-0.5*\h) cos (0.5*\w,0)
                          sin (0.625*\w,0.5*\h) cos (0.75*\w,0) sin (0.875*\w,-0.5*\h) cos (\w,0);
  \end{scope}
}

\begin{document}
\begin{tikzpicture}[scale=2,line cap=round,line join=round]
  \node at (0.5,6*\h) [left] {Binary data sequence};
  \node at (0.5,4*\h) [left] {Data waveform UP-NRZ(L)};
  \node at (0.5,2*\h) [left] {Carrier signal, $\sin(2\pi ft)$};
  \node at (0.5,0)    [left] {ASK signal waveform};
  \draw (0.5,0)    --++ (11*\w,0);
  \draw (0.5,2*\h) --++ (11*\w,0);
  \draw[thick,<->] (\w,3*\h) --++ (\w,0) node[midway,above] {$T_b$};
  \def\oldi{2}
  \foreach[count=\j]\i in {1,0,1,1,0,1,0,1,1,1}
  {%
    % vertical lines
    \draw[dashed] (\j*\w,0) --++ (0,6.5*\h);
    \ifthenelse{\i=\oldi}{}{\draw[thick] (\j*\w,3.5*\h) --++ (0,\h);}
    % ASK
    \ifthenelse{\i=1}{\mysin{(\j*\w,0)}{blue}}{\draw[thick,blue](\j*\w,0) --++ (\w,0);}
    % Carier
    \mysin{(\j*\w,2*\h)}{red}
    % NRZ
    \draw[thick] (\j*\w,3.5*\h+\i*\h) --++ (\w,0);
    % bits
    \node at (\j*\w+0.5*\w,6*\h) {$\i$};
    % 
    \global\let\oldi=\i % remember \i in \oldi
    \global\let\oldj=\j % remember \j in \oldj
  }
  % last vertical lines
  \draw[dashed] (\oldj*\w+\w,0)      --++ (0,6.5*\h);
  \draw[thick]  (\oldj*\w+\w,3.5*\h) --++ (0,\h);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容