1
$\begingroup$

(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:

test_p4.png

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:

test_p3.png

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}
$\endgroup$
2
  • 1
    $\begingroup$ The code bits can be sent in parallel. (multi-channel equivalent) $\endgroup$
    – hotpaw2
    Apr 1, 2014 at 15:20
  • $\begingroup$ Thanks for the comment, @hotpaw2 - good to keep that in mind; but here I was more interested in what sort of a waveform is applicable to the term PCM, in the basic, serial transmission sense. Cheers! $\endgroup$
    – sdaau
    Apr 1, 2014 at 16:08

2 Answers 2

1
$\begingroup$

PAM is a good visual representation of PCM and can be thought of as a first step in creating a PCM data stream. Pulse Code Modulation is commonly used in telephone transmission systems. The most common format is an 8 bit representation of 16 bit linear fixed point audio data (voice) that is band limited to roughly 300 to 3600 Hz. The sampling rate is 8Khz. The 8 bit representation of 16 bit is achieved using a logorithmic compression scheme (u-law in the US, a-law elsewhere). After the data is compressed, it is serialized for transmission. Note that PCM doesn't have to be compressed or 8 bits. 16 bit linear PCM is also a common format, but not in telephone transmission systems.

The format for u-law or alaw encoded PCM is as follows:

Serial bit stream, each byte is a compressed audio dample:

       byte N         byte N+1         byte N+2
...|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|...
                    s e e e m m m m

8000 samples/second X 8 bits/sample = 64Kbps bit rate.

s = sign bit e = exponent m = mantissa

So for telephone quality audio, you first bandlimit your audio signal and then sample it using a 16bit analog to digital converter. Next compress each sample using u-law or a-law log encoding. Finally, serialize the data into a bit stream.

In telephone transmisions systems, this would represent a baseband signal. The PCM streams are up converted to higher bit rates and time multiplexed with other audio channels. A T1 telephone trunk contains 24 time multiplesed PCM audio channels, while E1 contains 32.

$\endgroup$
4
  • $\begingroup$ Many thanks for the answer, @BZ - especially the review of PCM use in telephony. I would just like to confirm, for clarity's sake: my problem is that by PCM, a lot of places basically mean a "sampled and held" PAM, which even if quantized, is essentially "analog" (in the sense that the information is encoded as a level, say, voltage). Your answer mentions, however, mentions the s e e e m m m m encoding, which implies that PCM is a binary encoding in the time domain - and as such, it cannot be "level-encoded" "analog" at the same time... $\endgroup$
    – sdaau
    Apr 1, 2014 at 17:22
  • $\begingroup$ ... so in proper terms, then PCM would refer to the specific binary signal encodings in the time domain (as used in, say, telephony), is that correct? (If it is so, then conversely, I would say that the "level-encoded" "sampled-and-held" waveform as shown on U2 in OP isn't really "PCM", just an "analog" representation of the information it carries; would this also be correct?). $\endgroup$
    – sdaau
    Apr 1, 2014 at 17:25
  • 1
    $\begingroup$ Correct. PCM is a binary sequence digital representation. The levels shown by the OP are "analog" representations or can be thought of as pulse amplitude modulation (PAM). $\endgroup$
    – user2718
    Apr 1, 2014 at 18:02
  • $\begingroup$ Many thanks again, @BZ - much appreciated; Cheers! $\endgroup$
    – sdaau
    Apr 1, 2014 at 18:20
1
$\begingroup$

In the end, I worked out that PCM is a function that multiplies a signal with a Dirac comb, rounds them to a quantisation level, and takes the discrete data points as samples and stores them in memory (the digital domain). LPCM refers to PCM with linear quantisation levels rather than using A-law etc. The point of PCM is that it is specifically a set of quantised samples of an analogue signal that was in the analogue domain, and it's now an analogue signal stored in the digital domain. PCM implies that it is an analogue signal that is sampled and doesn't apply to digital signals, which are sampled and processed in the digital domain, but this wouldn't be referred to as PCM.

Analogue PAM is a function that multiplies an analogue signal in the analogue domain by a Dirac comb, with infinite quantisation levels, so it is just sampling without a quantisation step, and then the samples can be sent on the medium with a suitable pulse shape filtering. When you quantise the samples into the digital domain, because the digital domain has finite discrete quantisation levels, any PAM representation sent on the medium is now digital PAM, regardless of whether the amplitudes are directly mapped to a single or more than one pulse, because it is just a quantisation bitstream. Analogue PAM only applies to samples of an analogue signal in the analogue domain. A digital signal in the analogue domain needs to be quantised and processed digitally, not sampled and pulse shaped and further transmitted as analogue PAM.

Digital PAM is a line code that takes a bit stream, regardless of whether this digital data is a set of samples of an analogue signal (PCM data), or a layer 2 packet in a network, and maps chunks of the data to discrete amplitudes (voltages) and then it is sent on a wired medium, with a suitable pulse shaping. It can either be sent baseband or it can be modulated with a carrier.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.