(copy from Proper meaning (and origin) of PCM (pulse code modulation)? - Stack Overflow):
Apologies first, as StackOverflow is possibly not the right forum for this question; in that case please suggest a move in the comments. But it is motivated by usage in documentation like ALSA project - the C library reference: PCM (digital audio) interface - and at least there is code (below) for the images.
The thing is - when I hear the term "Pulse Code Modulation", the first thing that pops in my mind is this:
I guess, that would be the BCD representation of a level, encoded as serial signal transitions (MSB first).
But then, I read the above PCM link, or Pulse-code modulation - Wikipedia, and it turns out it is not so; for comparison:
It seems that U1 in the above image would be PAM (pulse amplitude modulation); U3 would be PWM (pulse width modulation) - and it is U2 that would represent PCM (pulse code modulation).
But then, when I look at U2 - I'd also call that "pulse amplitude modulation"; in a way, U2 is also amplitude modulation, no? Why is it then called "pulse code modulation" instead? I guess the word "code" is what confuses me most here, and makes me first think of something like U4 above - for the case of U4 it is clear, but which is this "code", which had been "modulated" onto the signal in the case of U2?
Here is the Latex source for the images:
\documentclass{standalone}
\def\plotchoice{4} % 1 - last; 3 - first three; 4 - all four
\usepackage{pgfplots}
\pgfplotsset{compat=1.5.1}
\usepackage{pgfplotstable}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{fit}
\usetikzlibrary{pgfplots.groupplots}
\usepackage{tikz-timing}
\renewcommand{\ttdefault}{pcr} % courier for boldface typewriter
% to have the H character filled:
% (( note - if { LL LH HL H 0.9H 0.1L}:
% must split last H to 0.9H 0.1 (so to
% end on L, without drawing beyond range)
% else the fill of H is not good. ))
\tikztimingdef{HL}{
-- ++(\slope,-\height)
[fill=black] \tikztiminguse{HH}{#1-\slope}
}
% define H and L as A and B with added text
\tikztimingmetachar{A}{H N[
rectangle,align=center,
xshift=-0.5\xunit,yshift=-0.5\yunit,
font=\large\tt\bfseries,
color=black!65,
]{1}}
\tikztimingmetachar{B}{L N[
rectangle,align=center,
xshift=-0.5\xunit,yshift=+0.5\yunit,
font=\large\tt\bfseries,
color=black!65,
]{0}}
\makeatletter
% http://tex.stackexchange.com/questions/33703/extract-x-y-
\newcommand{\gettikzxy}[3]{%
\tikz@scan@one@point\pgfutil@firstofone#1\relax
\edef#2{\the\pgf@x}%
\edef#3{\the\pgf@y}%
}
\newlength{\trx}\newlength{\try}
\def\getlengths{%
\gettikzxy{(refsize)}{\rx}{\ry}
% %re-convert \rx back to length, so can scale it directly in style= below:
\setlength{\trx}{\rx}\setlength{\try}{\ry}
\typeout{rx \rx , ry \ry ; (\the\trx , \the\try)}
\gettikzxy{(refnull)}{\rx}{\ry}
\addtolength{\trx}{-\rx}
\addtolength{\try}{-\ry}
\typeout{orx \rx , ory \ry ; (\the\trx , \the\try)}
}
\makeatother
\begin{document}
\pgfplotstableread[col sep=&,row sep=\\]{
0 & 0 \\
1 & 1 \\
2 & 3 \\
3 & 2 \\
4 & 2 \\
}\mytable
% note: remember picture has side effect of cancelling xlabels at=edge bottom
\begin{tikzpicture}%[remember picture]
\begin{groupplot}[
group style={
group name=my plots,
group size=1 by \plotchoice,
xlabels at=edge bottom,
xticklabels at=edge bottom,
vertical sep=0pt,
},
footnotesize,
width=10cm,
height=4cm, % of single subplot
xlabel={$t$\,[s]},
xmin=-0.5, xmax=4.5,
ymin=0, ymax=3.5,
xtick={-0.5,0,...,4.5},
ytick={1,2,3},
tickpos=left,
ytick align=outside,
xtick align=outside,
axis x line=middle,
axis x line*=bottom,
axis y line=middle,
axis y line*=left,
ylabel style={align=right,anchor=north,shift={(-3.2em,+0.4em)},font=\small},
]
\ifnum\plotchoice>2 %
\typeout{plotchoice > 2}
\nextgroupplot[ybar,bar width={1pt},restrict x to domain=0:3.5,ylabel=U1]
\addplot[fill=black,draw=black,mark=*]
table[] \mytable;
\node[] (refnull) at ({axis cs:0,0}) {};
\node[] (refsize) at ({axis cs:1,1}) {};
\nextgroupplot[const plot,ylabel=U2]
\addplot[fill=black,draw=black,line width=2pt] table[] \mytable \closedcycle;
\nextgroupplot[ylabel=U3]
\addplot [] coordinates {(0,0)};
\pgfplotsextra{ % must have, else \gettikzxy will not work!
\getlengths
\timing[line width=2pt,
%style={x=0.333\trx,y=1\try}, %ok, but \xunit,\yunit are not set
%timing/.style={xunit=0.333\trx,yunit=1\try}, % nowork
% like this - so \xunit,\yunit are set:
timing/xunit={0.333\trx},
timing/yunit={1\try},
name=tgraph1,
]
at ({axis cs:0,0})
{ LLL HLL HHH HHL };
}
\fi
\ifnum\ifnum\plotchoice=1 1\else\ifnum\plotchoice=4 1\else0\fi\fi =1 %
\typeout{plotchoice 1 or 4}
\nextgroupplot[ylabel=U4]
\addplot [] coordinates {(0,0)};
\ifnum\plotchoice=1{
\node[] (refnull) at ({axis cs:0,0}) {};
\node[] (refsize) at ({axis cs:1,1}) {};
}\else\fi
\pgfplotsextra{ % must have, else \gettikzxy will not work!
%\typeout{; (\the\trx , \the\try)} % 0pt here! so must do again:
\getlengths %
\timing[line width=2pt,
timing/xunit={0.5\trx},
timing/yunit={1\try},
name=tgraph2,
]
at ({axis cs:0,0})
{ BB BA AA AB};
}
\fi
\end{groupplot}
\coordinate (refdelta) at ($(refsize)-(refnull)$) ;
% vertical lines spanning all plots:
\foreach \ix in {0,1,...,4} {
\draw[draw=black!30,dashed,line width=1pt]
let \p1 = ($(refnull)+\ix*(refdelta)$),
\p2 = (my plots c1r\plotchoice.south),
\p3 = (my plots c1r1.north)
in %
(\x1,\y2) -- (\x1,\y3) ;
}
% vertical lines plot 3:
\ifnum\plotchoice>2
\foreach \ix in {0,1,2,3} {
\foreach \ixx in {1,2,3} {
\draw[draw=black!30,dashed,line width=0.5pt]
let \p1 = ($(refnull)+\ix*(refdelta)+\ixx*0.333*(refdelta)$),
\p2 = (my plots c1r3.south),
\p3 = (my plots c1r3.center)
in %
(\x1,\y2) -- (\x1,\y3) ;
}
}
\fi
% vertical lines plot 4:
\ifnum\ifnum\plotchoice=1 1\else\ifnum\plotchoice=4 1\else0\fi\fi =1 %
\foreach \ix in {0,1,2,3} {
\foreach \ixx in {1,2} {
\draw[draw=black!30,dashed,line width=0.5pt]
let \p1 = ($(refnull)+\ix*(refdelta)+\ixx*0.5*(refdelta)$),
\p2 = (my plots c1r\plotchoice.south),
\p3 = (my plots c1r\plotchoice.center)
in %
(\x1,\y2) -- (\x1,\y3) ;
}
}
\fi
\end{tikzpicture}
\end{document}