<s>
Pulse-density	B-Algorithm
modulation	I-Algorithm
,	O
or	O
PDM	O
,	O
is	O
a	O
form	O
of	O
modulation	B-Application
used	O
to	O
represent	O
an	O
analog	O
signal	O
with	O
a	O
binary	O
signal	O
.	O
</s>
<s>
In	O
a	O
PDM	O
signal	O
,	O
specific	O
amplitude	B-Application
values	O
are	O
not	O
encoded	O
into	O
codewords	O
of	O
pulses	O
of	O
different	O
weight	O
as	O
they	O
would	O
be	O
in	O
pulse-code	B-Algorithm
modulation	I-Algorithm
(	O
PCM	B-Algorithm
)	O
;	O
rather	O
,	O
the	O
relative	O
density	O
of	O
the	O
pulses	O
corresponds	O
to	O
the	O
analog	O
signal	O
's	O
amplitude	B-Application
.	O
</s>
<s>
Pulse-width	B-Algorithm
modulation	I-Algorithm
(	O
PWM	O
)	O
is	O
a	O
special	O
case	O
of	O
PDM	O
where	O
the	O
switching	O
frequency	O
is	O
fixed	O
and	O
all	O
the	O
pulses	O
corresponding	O
to	O
one	O
sample	O
are	O
contiguous	O
in	O
the	O
digital	O
signal	O
.	O
</s>
<s>
In	O
a	O
pulse-density	B-Algorithm
modulation	I-Algorithm
bitstream	O
,	O
a	O
1	O
corresponds	O
to	O
a	O
pulse	O
of	O
positive	O
polarity	O
( +A	O
)	O
,	O
and	O
a	O
0	O
corresponds	O
to	O
a	O
pulse	O
of	O
negative	O
polarity	O
( −A	O
)	O
.	O
</s>
<s>
A	O
run	O
consisting	O
of	O
all	O
1s	O
would	O
correspond	O
to	O
the	O
maximum	O
(	O
positive	O
)	O
amplitude	B-Application
value	O
,	O
all	O
0s	O
would	O
correspond	O
to	O
the	O
minimum	O
(	O
negative	O
)	O
amplitude	B-Application
value	O
,	O
and	O
alternating	O
1s	O
and	O
0s	O
would	O
correspond	O
to	O
a	O
zero	O
amplitude	B-Application
value	O
.	O
</s>
<s>
The	O
continuous	O
amplitude	B-Application
waveform	O
is	O
recovered	O
by	O
low-pass	B-Algorithm
filtering	I-Algorithm
the	O
bipolar	O
PDM	O
bitstream	O
.	O
</s>
<s>
A	O
single	O
period	O
of	O
the	O
trigonometric	O
sine	O
function	O
,	O
sampled	B-Algorithm
100	O
times	O
and	O
represented	O
as	O
a	O
PDM	O
bitstream	O
,	O
is	O
:	O
</s>
<s>
In	O
pulse-density	B-Algorithm
modulation	I-Algorithm
,	O
a	O
high	O
density	O
of	O
1s	O
occurs	O
at	O
the	O
peaks	O
of	O
the	O
sine	O
wave	O
,	O
while	O
a	O
low	O
density	O
of	O
1s	O
occurs	O
at	O
the	O
troughs	O
of	O
the	O
sine	O
wave	O
.	O
</s>
<s>
A	O
PDM	O
bitstream	O
is	O
encoded	O
from	O
an	O
analog	O
signal	O
through	O
the	O
process	O
of	O
delta-sigma	O
modulation	B-Application
.	O
</s>
<s>
This	O
process	O
uses	O
a	O
one-bit	O
quantizer	B-Algorithm
that	O
produces	O
either	O
a	O
1	O
or	O
0	O
depending	O
on	O
the	O
amplitude	B-Application
of	O
the	O
analog	O
signal	O
.	O
</s>
<s>
Because	O
in	O
the	O
real	O
world	O
,	O
analog	O
signals	O
are	O
rarely	O
all	O
the	O
way	O
in	O
one	O
direction	O
,	O
there	O
is	O
a	O
quantization	B-Algorithm
error	O
,	O
the	O
difference	O
between	O
the	O
1	O
or	O
0	O
and	O
the	O
actual	O
amplitude	B-Application
it	O
represents	O
.	O
</s>
<s>
In	O
this	O
way	O
,	O
every	O
error	O
successively	O
influences	O
every	O
other	O
quantization	B-Algorithm
measurement	O
and	O
its	O
error	O
.	O
</s>
<s>
This	O
has	O
the	O
effect	O
of	O
averaging	O
out	O
the	O
quantization	B-Algorithm
error	O
.	O
</s>
<s>
The	O
process	O
of	O
decoding	O
a	O
PDM	O
signal	O
into	O
an	O
analog	O
one	O
is	O
simple	O
:	O
one	O
only	O
has	O
to	O
pass	O
the	O
PDM	O
signal	O
through	O
a	O
low-pass	B-Algorithm
filter	I-Algorithm
.	O
</s>
<s>
This	O
works	O
because	O
the	O
function	O
of	O
a	O
low-pass	B-Algorithm
filter	I-Algorithm
is	O
essentially	O
to	O
average	O
the	O
signal	O
.	O
</s>
<s>
The	O
average	O
amplitude	B-Application
of	O
pulses	O
is	O
measured	O
by	O
the	O
density	O
of	O
those	O
pulses	O
over	O
time	O
,	O
thus	O
a	O
low-pass	B-Algorithm
filter	I-Algorithm
is	O
the	O
only	O
step	O
required	O
in	O
the	O
decoding	O
process	O
.	O
</s>
<s>
A	O
digital	O
model	O
of	O
pulse-density	B-Algorithm
modulation	I-Algorithm
can	O
be	O
obtained	O
from	O
a	O
digital	O
model	O
of	O
the	O
delta-sigma	O
modulator	B-Application
.	O
</s>
<s>
Consider	O
a	O
signal	O
in	O
the	O
discrete	O
time	O
domain	O
as	O
the	O
input	O
to	O
a	O
first-order	O
delta-sigma	O
modulator	B-Application
,	O
with	O
the	O
output	O
.	O
</s>
<s>
where	O
is	O
the	O
frequency-domain	O
quantization	B-Algorithm
error	O
of	O
the	O
delta-sigma	O
modulator	B-Application
.	O
</s>
<s>
This	O
demonstrates	O
the	O
noise	O
shaping	O
effect	O
of	O
the	O
delta-sigma	O
modulator	B-Application
:	O
the	O
quantization	B-Algorithm
noise	O
is	O
"	O
pushed	O
"	O
out	O
of	O
the	O
low	O
frequencies	O
up	O
into	O
the	O
high-frequency	O
range	O
.	O
</s>
<s>
Using	O
the	O
inverse	O
Z-transform	B-Algorithm
,	O
we	O
may	O
convert	O
this	O
into	O
a	O
difference	O
equation	O
relating	O
the	O
input	O
of	O
the	O
delta-sigma	O
modulator	B-Application
to	O
its	O
output	O
in	O
the	O
discrete	O
time	O
domain	O
,	O
</s>
<s>
There	O
are	O
two	O
additional	O
constraints	O
to	O
consider	O
:	O
first	O
,	O
at	O
each	O
step	O
the	O
output	O
sample	O
is	O
chosen	O
so	O
as	O
to	O
minimize	O
the	O
"	O
running	O
"	O
quantization	B-Algorithm
error	O
.	O
</s>
<s>
The	O
quantization	B-Algorithm
error	O
of	O
each	O
sample	O
is	O
fed	O
back	O
into	O
the	O
input	O
for	O
the	O
following	O
sample	O
.	O
</s>
<s>
The	O
following	O
pseudo-code	O
implements	O
this	O
algorithm	O
to	O
convert	O
a	O
pulse-code	B-Algorithm
modulation	I-Algorithm
signal	O
into	O
a	O
PDM	O
signal	O
:	O
</s>
