CommunicationsLaboratory 20161206
CommunicationsLaboratory 20161206
CommunicationsLaboratory 20161206
Laboratory
Implementing a Software-Defined
Acoustic Modem
c
2015
c 2015 LC Potter
All rights reserved.
The routine plottf.m and Figures 1.5, 1.7, 2.1, 2.2, 4.2, and 4.4 are adapted from
[31] with permission from the author. Figure B.5 is provided courtesy of Aaron
Wise; Figure B.6 is used with permission.
This book is provided by the copyright holder as is. Any express or implied war-
ranties, including, but not limited to, the implied warranties of merchantability
and fitness for a particular purpose are disclaimed. In no event shall the authors
be liable for any direct, indirect, incidental, special, exemplary or consequential
damages (including, but not limited to, procurement of substitute goods or ser-
vices; loss of use, data, or profits; or business interruption) however caused and
on any theory of liability, whether in contract, strict liability, or tort (including
negligence or otherwise) arising in any way out of the use of this book or any
information, theories, or software contained or described in it, even if advised of
the possibility of such damage.
Neither the names of the authors nor the name of The Ohio State University may
be used to endorse or promote products derived from this book, or the software
contained in it, without specific prior written permission.
Contents
Preface vii
1 Introduction 1
1.1 A Physical Layer Model . . . . . . . . . . . . . . . . . 1
1.2 Software Radio . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Background . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3.1 Sampling and aliasing . . . . . . . . . . . . . . 6
1.3.2 Frequency upconversion . . . . . . . . . . . . . 7
1.3.3 Frequency downconversion . . . . . . . . . . . . 9
1.4 Explorations . . . . . . . . . . . . . . . . . . . . . . . 12
1.4.1 Getting started with audio I/O . . . . . . . . . 13
1.4.2 Spectral content of signals . . . . . . . . . . . . 14
1.4.3 Low-pass filtering . . . . . . . . . . . . . . . . . 16
1.4.4 Amplitude modulation . . . . . . . . . . . . . . 17
1.4.5 AM demodulation . . . . . . . . . . . . . . . . 18
1.5 Demonstration . . . . . . . . . . . . . . . . . . . . . . 19
1.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . 19
iii
iv CONTENTS
3 Digital Modulation 37
3.1 Background . . . . . . . . . . . . . . . . . . . . . . . . 37
3.1.1 Digital modulation . . . . . . . . . . . . . . . . 37
3.1.2 Symbol detection . . . . . . . . . . . . . . . . . 40
3.1.3 Bit and symbol error rates . . . . . . . . . . . . 42
3.2 Explorations . . . . . . . . . . . . . . . . . . . . . . . 45
3.3 Demonstration . . . . . . . . . . . . . . . . . . . . . . 47
3.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . 48
5 Synchronization 63
5.1 Background . . . . . . . . . . . . . . . . . . . . . . . . 64
5.1.1 Symbol timing . . . . . . . . . . . . . . . . . . 64
5.1.2 Frame timing for flat channels . . . . . . . . . 66
5.2 Explorations . . . . . . . . . . . . . . . . . . . . . . . 68
5.3 Demonstration . . . . . . . . . . . . . . . . . . . . . . 74
5.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . 75
6 Frequency Recovery 77
6.1 Background . . . . . . . . . . . . . . . . . . . . . . . . 77
6.1.1 Frequency recovery . . . . . . . . . . . . . . . . 77
6.1.2 Frequency-selective fading channel model . . . 81
6.1.3 Channel measurement . . . . . . . . . . . . . . 81
6.2 Explorations . . . . . . . . . . . . . . . . . . . . . . . 82
6.3 Demonstration . . . . . . . . . . . . . . . . . . . . . . 85
6.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . 85
7 Acoustic Modem 87
7.1 Background . . . . . . . . . . . . . . . . . . . . . . . . 87
7.1.1 Mobile app . . . . . . . . . . . . . . . . . . . . 87
7.1.2 Data packet . . . . . . . . . . . . . . . . . . . . 88
7.1.3 Spectral efficiency . . . . . . . . . . . . . . . . 88
CONTENTS v
8 Frequency-Selective Fading 95
8.1 Background . . . . . . . . . . . . . . . . . . . . . . . . 97
8.1.1 Frame timing for ISI channels . . . . . . . . . . 97
8.1.2 Frequency recovery for ISI channels . . . . . . 97
8.1.3 Linear equalizer for ISI channels . . . . . . . . 99
8.2 Explorations . . . . . . . . . . . . . . . . . . . . . . . 100
8.3 Demonstration . . . . . . . . . . . . . . . . . . . . . . 102
8.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . 102
B RF Experiments 141
B.1 Low-cost DIY Modulation . . . . . . . . . . . . . . . . 141
B.1.1 AM . . . . . . . . . . . . . . . . . . . . . . . . 141
B.1.2 FM . . . . . . . . . . . . . . . . . . . . . . . . 143
B.2 Commerical SDR Solutions . . . . . . . . . . . . . . . 145
C Functions 147
plottf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
firlpf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
char2psk template . . . . . . . . . . . . . . . . . . . . . . . 152
psk2char template . . . . . . . . . . . . . . . . . . . . . . . 153
srrc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
eyediagram . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
makepilots . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
packetdetect . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Glossary 159
Bibliography 163
Index 167
Preface
vii
viii PREFACE
Lee C. Potter
Riverlea, Ohio
Yang Yang
San Diego, California
x PREFACE
CHAPTER 1
Introduction
1
2 CHAPTER 1. INTRODUCTION
frequency transmission.
The receiver processing chain mirrors the transmission chain, but
with added complexity to handle synchronization of the receiver to
the transmitter and to accommodate signal distortions, or impair-
ments, due to transmission or resulting from thermal noise at the
receiver. Receiver design to mitigate these impairments is consid-
ered in Chapter 5 and Chapter 6; additional techniques to overcome
channel impairments are presented in Chapters 8 through 12.
Symbols are illustrated in Figure 1.2(a) for the case of the quad-
rature phase shift keying (QPSK) symbol constellation, also known
as 4-ary quadrature amplitude modulation (4-QAM). In QPSK, pairs
of bits are mapped to one of four equal energy symbols. The map-
ping of bits to symbols and the decoding of noisy symbols back to
bits are considered in Chapter 3. A typical impulse response used
for pulse shaping is illustrated in Figure 1.2(b). The role of the pulse
shaping filter and the associated design trade-offs are considered in
Chapter 4. Moving down the transmission chain in Figure 1.1, the in-
phase channel of a 47-bit baseband message is shown in Figure 1.2(c),
and the corresponding bandpass signal with acoustic carrier fre-
quency 1800 Hz is shown in Figure 1.2(d).
In this laboratory course, students are guided through a sequence
of directed explorations, culminating in the design and implementa-
tion of an acoustic modulator/demodulator (modem). The acoustic
modem implemented in this course works much like a fax modem.
Matched Filtering
ỹ[n] ṽ[k]
and Symbol Sync ṽ(t) QAM Demodulation r(t)
Channel Symbol Digital Baseband Analog Baseband
Bits Bits Symbols Frame Sync L grx [k] Signal ADC LPF RF Signal
Decoding Mapping Signal
Channel
Symbols Equalization
Figure 1.1: Physical layer communication processing chain for transmission and reception.
3
4 CHAPTER 1. INTRODUCTION
0.1
Re
amplitude
0.05
(11) (10)
4-QAM −0.05
−3 −2 −1 0 1 2 3
Symbol intervals
(a) (b)
Baseband Signal, I Channel Bandpass Signal
0.25 0.4
amplitude
0.2 0.2
0.15 0
0.1 −0.2
amplitude
0.05 −0.4
0 0.05 0.1 0.15 0.2 0.25
0 time(s)
−3
x 10
−0.05 6
magnitude
−0.1
4
−0.15
2
−0.2
−0.25 0
0 0.05 0.1 0.15 0.2 0.25 −4000 −3000 −2000 −1000 0 1000 2000 3000 4000
time(s) frequency (Hz)
(c) (d)
Antenna
ADC DDC
LNA LPF
Data
out
ADC DDC
LPF
DAC DUC
PA LPF
Data
in
DAC DUC
LPF
1.3 Background
This section provides a brief review of concepts explored in the labo-
ratory exercises. First, sampling and aliasing are reviewed. Second,
upconversion and downconversion are defined for the real-valued sig-
nal case. Complex-valued sampling and quadrature modulation are
explored in Chapter 2.
(k − 1)fs kfs
≤ |f | ≤ , for some positive integer k. (1.2)
2 2
1.3. BACKGROUND 7
0.5
amplitude
−0.5
−1
0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1
time (seconds)
0.5
amplitude
−0.5
−1
0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1
time (seconds)
Figure 1.4: Illustration of sampling and aliasing.
m(t) × s(t)
∼ cos(2πfc t)
1 |M(f)| 1 |S(f)|
2W
1/2
f f
-W W -fc fc
∼ 2 cos(2πfct)
Figure 1.7: Amplitude demodulation.
In Equation 1.6 and Figure 1.7, the low-pass filter (LPF) has a
passband cutoff Bp ≥ W Hz and stopband cutoff Bs ≤ (2fc − W ) Hz,
where W is the one-sided bandwidth of the baseband signal, m(t).
The filter’s magnitude response is illustrated in Figure 1.8.
1
1/2
f
−2fc − W −2fc −2fc + W −Bs −Bp −W W Bp Bs 2fc − W 2fc 2fc + W
distorted:
v(t) = LPF m(t) cos(2πfc t) × 2 cos(2π(fc + f∆ )t + φ)
| {z }
cos(2πf∆ t+φ) + cos(2π(2fc +f∆ )t+φ)
= m(t) cos(2πf∆ t + φ) . (1.7)
| {z }
time-varying attenuation
Interpolation
Interpolation is a digital filtering procedure that increases the sam-
pling rate by an integer factor, L:
∞
X sin(π(k − nL)/L)
y[k] = x[n] . (1.8)
n=−∞
π(k − nL)/L
x[n] y[k]
L
LPF
2
amplitude
−1
−2
−3
−0.5 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
time (seconds)
Decimation
L
LPF
1.4 Explorations
Here, as in each chapter, a guided set of explorations is presented.
Useful commands are introduced and used in example snippets of
code to reinforce and visualize key concepts. Chapter by chapter,
students build towards a fully functional acoustic modem.
Each chapter is designed for a single laboratory session with a
brief report and a demonstration. In subsequent chapters, exercises
are increasingly less scripted, with freedom for creative detours and
experimentation. Students are encouraged to be brief and direct
in reporting; to this end, questions to be answered in the report
are enumerated in the margins. The recommended demonstration is
detailed in a separate subsection.
Microphone input
For Matlab to recognize a sound recording device in some Windows
configurations, an external microphone must be inserted into the mi-
crophone jack of the PC tower before starting Matlab. Right-click
on the volume controls in the system tray (a speaker icon typically
located at the bottom right of the Windows screen), select “Audio
Devices” and select the “Recording” tab. Ensure that there is some
reaction from the microphone as shown by the volume bars beside the
microphone entry. If there is no reaction, then go to the properties
of the microphone (double click) and adjust the microphone volume
and/or boost until an input reaction is observed. More generally,
from right-click on the speaker icon, you can select playback devices,
recording devices, and volume control options. From these command
windows, you can select a playback device and a recording device.
By clicking on the icon for a device, you can enable the device, check
device properties, and set sound levels.
1.4. EXPLORATIONS 13
Workflow suggestions
For numerical and graphical explorations, several practices may be
helpful. First, students are advised to create a memory folder for lab-
oratory work; download files and select the folder using the “browse
for folder” icon in the Matlab tool bar. For example, the explo-
rations in Chapter 1 use the function plottf.m, which is given in
Appendix C. A useful practice is to create a new script file (available
at the top left of the menu bar) for each chapter. An editor window
can then be used to copy and execute code snippets, write new com-
mands, or edit and re-run codes. For each chapter, the code snippets
appearing in the chapter are available as a stand-alone .m script, such
as Chapter1snippets.m. All scripts and functions are available for
download at OpenStax CNX and Mathworks Matlab Courseware.
Students are encouraged to embrace the development of engi-
neering skills, and software design skills in particular, that are a
part of this laboratory experience. To this end, we highlight several
suggestions in Appendix A. Subsections of code developed in each
laboratory section will eventually be integrated into a single work-
ing modem; thus, purposeful attention to a few simple practices will
greatly simplify work as the lessons progress.
Valid values of the sampling rate depend on the specific audio hard-
ware installed. Typical values supported by most sound cards are
8000, 11025, 22050, 44100, 48000, and 96000 samples per second.
The code snippet in Table 1.1 provides an example. Typing your
own code as you do example exercises will help in building and re-
taining familiarity with simple commands. In addition, code snippets
are available for download; see links given in Appendix C. If, in exe-
cuting the function audiorecorder, you encounter the error message
no audio device found, then exit Matlab, unplug and re-plug the
microphone into the PC input jack, and re-start Matlab.
Playing audio
Similarly, two commands allow a user to play audio through a sound
card from within Matlab.
(a) Follow the example in Table 1.1 to record and plot 2 seconds
of speech.
(b) Follow the examples in Table 1.2 to play a tone and the recorded
speech.
Suggested explorations:
(d) Use the zoom tool in the figure to look more closely at speech in Q1.1
the time domain. What qualitative differences do you observe
between vowels and consonants? Is a DC bias present in your
recorded speech signal?
(e) Look more closely at speech in the frequency domain. What Q1.2
are the lowest and highest frequencies displayed in the graph,
and why? What band of frequencies is non-negligibly occupied
by the speech signal? How would a DC bias be evident in
the frequency domain? (Hint: use the zoom option with the
frequency domain plot to observe X(f ) for f = 0.)
(g) With sampling rate fixed at Fs=8000 sps, specify four values
Q1.3 of f0, 0 < f0 < 16000, so that cos(2*pi*f0*(0:Fs/2)/Fs)
sounds like one-half second of a 440 Hz tone.
(h) Experiment with the audioplayer command to discover what
sampling rates are supported by your sound card hardware; an
unsupported rate will return an error message when the play
command is invoked.
(j) View both your whitenoise and pinknoise signals in the time
and frequency domains. Comparing the two signals, what do
you observe in each domain?
1.4. EXPLORATIONS 17
(k) [Optional] Repeat step (j) for several smaller values of filter
length small than the Lh=49 used above. What do you observe?
0
Magnitude (dB)
−50 One−half
Sampling rate
Passband Stopband
Edge, Fpb Edge, Fsb
−100
−150
0 500 1000 1500 2000 2500 3000 3500 4000
Frequency (Hz)
Linear Phase
Phase (degrees)
−500
−1000
−1500
−2000
0 500 1000 1500 2000 2500 3000 3500 4000
Frequency (Hz)
fc=4000;%4000 Hz
s = cos(2*pi*fc*t) .* pinknoise;
figure;plottf(s,1/Fs);
title(’Modulated Bandpass Noise’)
Q1.4 (n) Keep Fs=16000. Experiment with various values of the carrier
frequency, fc, from the previous step. What do you observe
for carrier frequencies 6, 500 ≤ fc ≤ 16, 000 Hz?
Q1.5 (o) For the bandlimited noise pinknoise above, suppose you wish
to modulate to a carrier frequency of 19, 000 Hz. Suggest an
appropriate sampling rate.
1.4.5 AM demodulation
For frequency downconversion, follow the diagram in Figure 1.7. Re-
call 2 cos(α) × cos(β) = cos(α − β) + cos(α + β). The role of the
low-pass filter is to remove this second term, the so-called “double
frequency” term.
(q) Omit the filter convolution step in the demodulator, and again
view the result. What do you observe?
1.5 Demonstration
For demonstration, use the Communication Laboratory mobile app
to transmit an acoustic signal using the app’s default settings. The
app is freely available at iTunes and Google Play; a description of
the app is found in Section 7.1.1.
Record the transmission with sampling frequency Fs=44100. View
the received signal using the plotttf.m function. Observe and re-
port the following parameters from your graph.
1.6 Summary
In Chapter 1, basic signals and systems concepts have been reviewed:
sampling, aliasing, interpolation, low-pass filtering, frequency upcon-
version and frequency downconversion. The exercises introduced the
recording and playing of audio-rate signals. And, the explorations
served to introduce the commands and conventions summarized in
Table 1.3.
20 CHAPTER 1. INTRODUCTION
2.1 Background
2.1.1 Quadrature amplitude modulation
In quadrature amplitude modulation two real-valued messages are
modulated simultaneously, resulting in a bandpass spectrum that
is not conjugate symmetric about the carrier frequency, fc . The
modulation exploits the orthogonality of the sine and cosine functions
Z 1/(2fc )
sin(2πfc t) cos(2πfc t)dt = 0. (2.1)
−1/(2fc )
23
24 CHAPTER 2. QUADRATURE AMPLITUDE MODULATION
The two modulated waveforms, sometimes called “I” and “Q” for
short, are combined to produce the modulated waveform, s(t), given
by
s(t) = mI (t) cos(2πfc t) − mQ (t) sin(2πfc t). (2.2)
mI (t) × “in-phase”
cos(2πfc t)
∼ + s(t)
sin(2πfc t) −
90◦
mQ (t) × “quadrature”
× LPF vI (t)
2 cos(2πfc t)
r(t) ∼
2 sin(2πfc t)
−
× LPF vQ (t)
Re{m̃(t)ej2πfc t } (2.6)
= Re mI (t) + jmQ (t) cos(2πfc t) + j sin(2πfc t)
= mI (t) cos(2πfc t) − mQ (t) sin(2πfc t) = s(t). (2.7)
ej2πfc t 2e−j2πfc t
|M (f )| |R(f )|
|M (f − fc )| |2R(f + fc )|
|S(f )| |V (f )|
(
H(f ), fc − W ≤ |f | ≤ fc + W
Hbp (f ) = (2.10)
0, else.
s(t) r(t)
m̃(t) Re hbp (t) LPF ṽ(t)
complex
baseband
equivalent
channel
w̃(t)
12
10
slope = 2 π f∆ Ts
Phase (rad)
2 Intercept = φ
0
0 500 1000 1500 2000
Time sample, k
Filtering example
0.3
0.2
input
0.15 output
0.1
0.05
−0.05
−0.1
0 50 100 150 200 250
sample index
Digital upconversion
Quadrature Modulator
I
Interpolator _ Inv Sinc DAC
Q
sin cos
DDS
Digital downconversion
The AD6654 is a mixed-signal IF-to-baseband receiver consisting of
a 14-bit, 92.16M sps analog-to-digital converter (ADC) and a multi-
channel digital downconverter (DDC). It has been optimized for
wideband standards such as CDMA2000, UMTS, and TD-SCDMA.
The AD6654 is used as part of a radio system that digitally demodu-
lates and filters IF sampled signals. The basic operation is abstracted
in Figure 2.8.
2.3 Explorations
In this chapter, students explore quadrature modulation and the
complex-baseband signal representation. The quadrature modula-
tion and demodulation steps are illustrated on the right-hand side of
Figure 1.1. For the laboratory exploration, work through the guided
steps below using an acoustic carrier frequency. Recommendations
for preparing a brief, descriptive laboratory report are included in
the steps marked in the margins.
2.3. EXPLORATIONS 33
LPF L I
DAC
LPF L Q
-2sin 2cos
DDS
(a) Verify Equation 2.12. Referring to Equation 2.8, derive the I Q2.1
and Q received signals, in terms of mI (t) and mQ (t), when the
receiver operates with reference signal
(b) Create and plot a complex exponential signal s(t) = exp(j2πf t).
Here is an example code snippet:
(c) Use the rotate tool from the figure menu bar to adjust the view
of the time-domain plot of the complex-valued signal. What
do you see? Likewise, explain the visual appearance of the
frequency domain plot.
34 CHAPTER 2. QUADRATURE AMPLITUDE MODULATION
(1/sqrt(2) + 1j/sqrt(2))*ones(1,50).
Q2.2 (e) View, using plottf.m, the demodulated signal in step (d) be-
fore and after applying the low-pass filter that removes the
double-frequency terms. For reporting, present the graphs;
briefly compare and explain the two frequency domain plots.
2.4. DEMONSTRATION 35
(f) For the received signal generated in step (d), create an IQ plot Q2.3
by plotting the quadrature signal (vertical axis) versus the in-
phase signal (horizontal axis). Mark a red circle for every Lth
point, as in the following code snippet for some signal, v, and
L = 10.
figure %create new figure window
plot(real(v),imag(v));
L=10;
hold on; %keep existing plot and overlay
plot(real(v(1:L:end)),imag(v(1:L:end)),’ro’);
%option ’ro’ uses red circles as markers
hold off;title(’IQ Plot’)
xlabel(’In-phase’);ylabel(’Quadrature’)
Additionally, plot the phase difference between the message
samples, m̃(t), and the received signal, ṽ(t). Take note to ac-
commodate the filter delay, which is one-half the filter order.
Further, truncate the list of received delayed samples to be
the same length as the list of message samples. For reporting,
present the IQ plot of the received signal.
(g) Recreate the IQ plot and phase difference plot from step (f), but
add a phase offset, φ, at the demodulator. That is, implement
the demodulator as in Figure 2.3 but with receiver oscillator
2e−j(2πfc t+φ) for φ 6= 0. What do you observe in your plots?
Why?
(h) Recreate the IQ plot and phase difference plot from step (f), Q2.4
but insert both a phase offset, φ, and a frequency offset, f∆ ,
at the demodulator. Try two or three different offsets, both
negative and positive. What do you observe in your plots?
Why?
For reporting, present the IQ plot and the phase difference
plot for one of your parameter selections. Briefly interpret the
graphs.
2.4 Demonstration
For demonstration, use the Communication Laboratory mobile app
to transmit a carrier tone. Descriptions of the app and how to down-
36 CHAPTER 2. QUADRATURE AMPLITUDE MODULATION
2.5 Summary
In Chapter 2, quadrature amplitude modulation and coherent quad-
rature demodulation have been explored. Complex baseband was
presented as a convenient mathematical notation for representing
QAM signals. The exercise also introduced the practical impair-
ments of frequency and phase offsets, which are compensated in the
receiver design to be implemented in Chapter 6. The explorations
served to introduce the commands and conventions summarized in
Table 2.1.
3.1 Background
37
38 CHAPTER 3. DIGITAL MODULATION
Im Im
01 11
0 1 Re Re
00 10
Im Im
011 0000 0100 1100 1000
010 001
110 000 Re Re
0011 0111 1111 1011
111 100
M
1 X
|ãi |2 = 1. (3.3)
M i=1
Table 3.1: Bit assignments for (a) BPSK and (b) QPSK digital mod-
ulation.
Input bits Symbol
MSB, LSB
Input bit Symbol √
11 (1 + j)/ √2
1 1
01 (−1 + j)/√2
0 -1
00 (−1 − j)/√ 2
10 (1 − j)/ 2
(a) (b)
end
EbperN0dB = 6;
EbperN0 = 10^(EbperN0dB/10);
varw = (EbperN0*log2(M))^(-1)/2; %per channel sample var
w = sqrt(varw)*(randn(1,N) + 1j*randn(1,N));
y = a + w; %add noise
% make scatter plot
figure;
plot(real(y),imag(y),’x’,’MarkerSize’,8,’LineWidth’,2);
title(’Scatter Plot’,’fontsize’,13)
xlabel(’In-phase’,’fontsize’,13);
ylabel(’Quadrature’,’fontsize’,13);
axis([-1.5 1.5 -1.5 1.5]);axis square% set axes extents
grid % draw grid lines
Scatter Plot
1.5
0.5
Quadrature
−0.5
−1
−1.5
−1.5 −1 −0.5 0 0.5 1 1.5
In−phase
Figure 3.2: Example scatter plot for 160 noisy QPSK symbols.
N0
var(w̃) = SNR−1 = . (3.6)
Es
BPSK
Considering the special case of BPSK, the energy per bit, Eb , is
simply Eb = Es . For ã = 1, an error occurs if the real part, yI =
Re(ỹ), is less than zero. The real part carries half the noise variance,
and hence the variance of Re(w̃) is N0 /(2Eb ). This distribution is
shown in Figure 3.3. The probability of bit error for BPSK when
transmitting ã = 1, then, is the area under the curve for yI ≤ 0.
3.1. BACKGROUND 43
Es
QPSK
Consider next the error probability for QPSK in two cases. First,
suppose the bandwidth, W = T −1 , is identical for BSPK and QPSK
and fix the energy per symbol, Es . Then, QPSK provides twice the
data rate as BPSK, but suffers a worse bit error rate. The worse
bit error rate is evident from Figure 3.1 where we observe that √ the
distance between nearest QPSK constellation points is only 2/2,
compared to a distance of 2 for BPSK.
p Thus, following Equation 3.7
the BER for QPSK is given by Q 2Eb /N0 ; but, for a fixed symbol
44 CHAPTER 3. DIGITAL MODULATION
0
BPSK
10
−1
10
Probability of Bit Error
−2
10
theory
simulation
−3
10
−4
10
−5
10
−4 −2 0 2 4 6 8 10
E /N (dB)
b O
energy, the energy per bit, Eb , for QPSK is one-half the energy per
bit for BSPK.
Second, set the data rate equal for BPSK and QPSK. Then, the
signal bandwidth W = T −1 for BPSK must double, thereby doubling
the receiver noise power, N0 W . Thus, for equal data rate, QPSK
and BPSK have the same bit error rate, but QPSK uses only half
the spectral bandwidth. For this reason, QPSK is said to be more
spectrally efficient than BPSK.
In summary, in a bandwidth-limited application, QPSK is pre-
ferred over BPSK, because QPSK can offer the same rate of correct
bits using only half the bandwidth. On the other hand, in a power-
limited application BPSK may be preferred.
The detection error analysis above is a simple example demon-
strating that communication engineers can analytically predict per-
formance and evaluate system design trade-offs without expensive
build-and-test cycles. And, the quality of a prediction is limited
only by the validity of the attendant assumptions, such as channel
models (including AWGN) and amplifier linearity. Given that engi-
3.2. EXPLORATIONS 45
neers are able to design both the transmitter and receiver, modeling
assumptions can typically be very accurate for commercial systems.
Limiting bounds on performance provide additional insight to de-
sign trade-offs; Shannon’s channel capacity bound is considered in
Chapter 9.
3.2 Explorations
In this lesson students will implement the digital modulation and
demodulation steps shown in Figure 1.1. In particular, students
are given template functions in char2psk.m and psk2char.m found
in Appendix C. From these templates, two functions will be con-
structed: one function to map a character string to a sequence of
symbols, and a second function to map noisy received symbols to a
character string. The code templates provide examples of the for-
mat, syntax, and comment style for students to consider. Use of
well-commented modular code will facilitate construction of an end-
to-end acoustic digital modem.
The steps adopted in the code templates for mapping an ASCII
character string to bits are illustrated in Table 3.2. The command
double converts an ASCII character to a decimal label. Next, the
command dec2bin converts the decimal numbers to a binary repre-
sentation of specified length, which here is 8 bits. Then, .’ performs
a 90◦ rotation of the bit array, turning rows into columns, and the
command reshape reads the transposed bit array, column by col-
umn, into a single long row.
A lab report should provide answers to the four questions enu-
merated in the page margins and the bit error rate curve measured
in the demonstration.
str=’abc’;
str_dec=double(str);
str_bin=dec2bin(str_dec,8);
bits=reshape(str_bin.’,1,8*length(str));
str_dec =
97 98 99
str_bin =
01100001
01100010
01100011
bits =
011000010110001001100011
(c) Verify that your two functions from steps (a) and (b) work
together to properly map characters to bits to symbols and
back again. (Save these functions for re-use in subsequent lab-
oratory sessions as you continue to design and construct an
acoustic modem.)
Q3.1 (d) Suppose the pulse-shaping function, gtx (t), in Equation 3.1 has
two-sided bandwidth of (1 + α)/T Hz, where T is the symbol
period. What is the bandwidth efficiency of BPSK in bits per
second per Hertz ? What is the bandwidth efficiency of QPSK?
Of 64-QAM?
Q3.2 (e) Suppose a random bit stream is BPSK modulated such that
each symbol has energy Eb . In an AWGN channel, what is the
average probability of bit error for a minimum distance decoder
3.3. DEMONSTRATION 47
(f) Create a scatter plot of 1000 simulated received QPSK symbols. Q3.3
Refer to the example given in Section 3.1.2 and set the noise
power for the complex additive white Gaussian noise to be 5 dB
per symbol. From the analysis given in Section 3.1.3, what
BER do you expect?
(g) Qualitatively and intuitively, describe how BER and Es are Q3.4
evidenced in the signal space scatter plot.
(h) [Optional] Extend your functions from steps (a) and (b) to
implement 8-PSK modulation.
(i) [Optional] Extend your functions from steps (a) and (b) to
implement 16-QAM modulation.
3.3 Demonstration
Create a simulator for QAM symbols in additive white Gaussian
noise. Via simulation, create bit error (BER) curves for BPSK and
QPSK as a function of Eb /N0 over the range −4 dB to 10 dB in
0.25 dB steps. Use N=1e6 random trials. (Note that, in general, to
simulate an error rate of 10−d you should use at least N = 10d+1
random trials.) Compare your empirical result to your conclusion
from step (e). You can re-use your code from step (b) to implement
the minimum distance decoder, and the simulation was considered in
step (f) (and in step (k)). Hint: one method for counting bit errors
is
48 CHAPTER 3. DIGITAL MODULATION
BER = length(find(Rxbits-Txbits))/N;
where Rxbits and Txbits are the length N bit streams at the receiver
and transmitter, respectively.
3.4 Summary
In Chapter 3, digital modulation has been explored with emphasis on
the special cases of binary and quadrature phase-shift keying. The
exercises prepare students to implement the initial steps and final
steps of the modem processing chain depicted in Figure 1.1: mapping
text to bits to symbols at the transmitter, and mapping receiver
samples to symbols to bits to text. The explorations introduced
several new commands and conventions summarized in Table 3.3.
3.4. SUMMARY 49
4.1 Background
A sequence of symbols, ã[n], is not suitable for direct transmission
over a communication channel. Symbols must be converted to a
waveform for transmission. In a process known as pulse shaping,
symbols are converted to a sampled-data baseband message; then,
as seen in Figure 1.1, the sampled data are converted to an ana-
log voltage signal through a digital-to-analog converter (DAC) and
mixed to a frequency band suitable for the communication channel.
From Equation 3.1, the sampled-data baseband message is given by
X
m̃[k] = ã[n]gtx (kTs − nT ) (4.1)
n
51
52
w̃[k]
Additive White
Gaussian Noise
Matched Filtering
ỹ[n] ṽ[k]
and Symbol Sync ṽ(t) QAM Demodulation r(t)
Channel Symbol Detection Digital Baseband Analog Baseband
Bits Bits Symbols Frame Sync L grx [k] Signal ADC LPF RF Signal
Decoding Mapping Signal
Channel
Symbols Equalization
Eye Diagram
Figure 4.1: Fractionally sampled baseband system model for physical layer digital communication processing.
CHAPTER 4. PULSE SHAPING & ISI
4.1. BACKGROUND 53
DAC
ã[n] ã↑ [k] m̃[k]
P
L gtx [k] sinc t m̃(t)
T
T
k
L
w̃[k]
To force ỹ[n] = ã[n], we therefore require that the pulse p(t) must
have gain 1 at the time origin and a value of zero at every integer
multiple of the symbol interval. Any waveform with this property is
called a Nyquist pulse, and the property is simply stated as p(nT ) =
δ[n], where δ[n] is the Kronecker delta sequence,
(
1 n=0
δ[n] = (4.3)
0 n=
6 0.
p(t)
1
p(nT ) = δ[n]
t
−3T −2T −T 0 T 2T 3T
∞
1 X
P (f − k/T ) = 1. 1
T k=−∞
3
f
− 2T − T1 1
− 2T 0 1
2T
1
T
3
2T
0.08
0.6
0.06
0.04
0.4
0.02
0.2
0
−0.02
0
−0.04
−5 0 5 −1 −0.5 0 0.5 1
time (in symbol periods) frequency (normalized to T=1)
Figure 4.5: Square-root raised cosine pulse in time domain (left) and
frequency domain (right).
ing of Figure 4.3 the first symbol appears in the upsampled sequence
ỹ↑ [k] with a delay of (Ng -1) due to the combined action of the
transmitter and receiver filters.
4.2 Explorations
In this lesson, students implement a digital baseband modem for an
additive white Gaussian noise channel with ideal channel response,
58 CHAPTER 4. PULSE SHAPING & ISI
1 1
0.5 0.5
0 0
−0.5 −0.5
−1 −1
−1.5 −1.5
0 200 400 600 800 1000 1200 1400 1600 1800 −0.5 0 0.5
Sample number relative symbol index
Figure 4.6: Left: upsampled received BPSK signal, ỹ↑ [k] with
symbol-rate samples marked as circles. Right: eye diagram.
Q4.1 (a) Use the functions srrc.m and plottf.m (with Ts=1) to con-
struct and view square-root raise cosine pulse shape filters with
the following values for excess bandwidth, α ∈ [0, 1], trunca-
tion half-width, D, and upsampling, L. (Note L must be an
integer.)
4.2. EXPLORATIONS 59
• D = 3, α = 0.10, L = 10.
• D = 3, α = 0.75, L = 10.
• D = 8, α = 0.10, L = 10.
(b) Using the three settings given in step (a), plot the result of Q4.2
the filter convolved with itself, conv(g tx,g tx). Does the
Nyquist property approximately hold for the settings above?
Why or why not? What do you observe about the effects
of α and D when comparing the three plots to each other?
From the three plots, identify the largest amplitude sample of
conv(g tx,g tx) contributing to ISI; i.e., which symbol-rate
sample deviates most from the ideal Nyquist pulse? Finally,
suppose the symbol ã[20] = 1 is transmitted; for each of the
three settings above; determine the interference (sign and am-
plitude) caused by that symbol at the received symbol for sam-
ple index n = 23.
(d) Short answer: Express the quantities listed below in terms of Q4.4
these modem parameters: DAC sampling rate fs ; QAM con-
stellation size, M ; upsampling factor, L; excess bandwidth, α;
SRRC truncation, D.
• Symbol period.
• Baud rate.
• Bit rate.
• Approximate pulse duration, in seconds, for gtx (t).
• Two-sided bandwidth of the baseband analog signal.
60 CHAPTER 4. PULSE SHAPING & ISI
bits=round(rand(1,1000));
a=2*bits-1;
• D = 3, α = 0.75, L = 15
• D = 3, α = 0.10, L = 15
• D = 8, α = 0.10, L = 15
4.3 Demonstration
Use your complex baseband simulator to consider sample timing er-
rors with and without noise. For example, a sample timing offset of
2 samples can be inserted for a row-vector y up via the command
Offset = 2; y up = [ rand(1,Offset) y up];
First compute the BER and plot an eye diagram for two pulse
designs in the noiseless case with a sample timing offset of 5 samples:
• D = 8, α = 0.1, L = 21
• D = 8, α = 0.75, L = 21
Which pulse is more susceptible to sample timing errors? Why?
Second, repeat with 6 dB SNR in the real part of ỹ↑ [k] and noise
of equal variance in the imaginary part. Note,
1
6 dB = 10 log10 ⇒ σ 2 = 10−6/10 .
σ2
(You are invited to optionally experiment by changing the noise vari-
ance and the timing offset.)
4.4 Summary
In Chapter 4, pulse shaping and matched filtering have been intro-
duced to complete a baseband signal representation for a digital mo-
dem. The eye diagram has been used to visualize the baseband re-
ceived signal and to observe the effects of ISI and symbol timing
error for an AWGN channel. The explorations introduced the new
commands summarized in Table 4.1.
62 CHAPTER 4. PULSE SHAPING & ISI
63
64 CHAPTER 5. SYNCHRONIZATION
2 2
1 1
real
real
0 0
−1 −1
−2 −2
5 10 15 20 25 30 5 10 15 20 25 30
2 2
1 1
imaginary
imaginary
0 0
−1 −1
−2 −2
5 10 15 20 25 30 5 10 15 20 25 30
Figure 5.1: Eye diagrams without (left) and with (right) channel
impairments. Data are shown for a BPSK constellation.
5.1 Background
Matched Filtering
ỹ[n] ṽ[k]
and Symbol Sync ṽ(t) QAM Demodulation r(t)
Channel Symbol Digital Baseband Analog Baseband
Bits Bits Symbols Frame Sync L grx [k] Signal ADC LPF RF Signal
Decoding Mapping Signal
Channel
Symbols Equalization
IQ Samples after Symbol Timing Recovery IQ Samples after Symbol Timing Recovery
1.5 1.5
1 1
0.5 0.5
0 0
−0.5 −0.5
−1 −1
−1.5 −1.5
−1.5 −1 −0.5 0 0.5 1 1.5 −1.5 −1 −0.5 0 0.5 1 1.5
Figure 5.3: Scatter plots of sampled matched filter outputs for QPSK
signalling. Left: poor symbol timing. Right: good symbol timing.
⌊N/L⌋−1
X
pb = min ỹ↑ [p + nL] − γp 2 . (5.2)
p∈{0,...,L−1}
n=0
The matched filter output also gives the ML estimate of the unknown
amplitude,
ỹ(τb)
H̃est = R . (5.5)
|m̃(λ)|2 dλ
That is, H̃est is the ratio of the observed peak value to the known
noiseless autocorrelation peak from the training signal m̃(t). Note
that the complex-valued scalar H̃est contains both the gain and the
phase modeling the flat fading channel response. For sampled data
and ±1 marker symbols, Equation 5.5 tells us
Ntr −1
consider a Barker code. A length Ntr Barker code {ak }k=0 is a
sequence of binary symbol values, ±1, such that
NtrX
−i−1
ak ai+k ≤ 1 for i 6= 0. (5.7)
k=0
5.2 Explorations
In this lesson, students continue development of an acoustic modem
by implementing symbol timing recovery and frame timing recovery
in the baseband receiver processing chain. The baseband channel
model considered is a flat fading channel with additive white Gaus-
sian noise. The processing chain is illustrated in Figures 5.2, 4.1, and
4.3.
5.2. EXPLORATIONS 69
autocorrelation
14
12
10
0
−10 −5 0 5 10
lag number
For the laboratory exploration, work through the five steps below
to implement a baseband modem in simulation. The suggestions
below explicitly enumerate items for a brief lab report: an equation
for Question 5.1 in step (a), one figure for Question 5.2, a brief
paragraph for Question 5.3, one figure for Question 5.4, and code
appended for Question 5.5.
Important: to aid with debugging and understanding, insert a
graph at each step of the processing chain depicted in Figures 1.1 and
5.2; refer to Table 5.3 for code suggestions to create graphs. Keep
commented and tested code from this chapter for your continuing
use as you build towards a working acoustic modem.
y = zeros(1,100);
tau = 23; %delay >= 0; start=1+tau
y( (1+tau) : (1+tau)+length(pilots)-1) = pilots;
0.4
0.2
−0.2
−0.4
−0.6
−0.8
0 20 40 60 80 100 120 140
received signal
3
−1
−2
10
8 Cross−Correlation Peak
6
−2
−4
−6
−8
0 10 20 30 40 50 60 70 80
Figure 5.5: Frame timing example for a flat fading channel. Top:
marker sequence convolved with pulse waveform. Middle: received
waveform before matched filtering. Bottom: correlation of marker
sequence with downsampled matched filter outputs. Peak reveals
location of the marker sequence.
5.2. EXPLORATIONS 71
and pilots. Write a general expression to solve for the sample Q5.1
index of y at which the first symbol of the pilot sequence oc-
curs. The solution is found from the sample index of the peak
of the absolute value of the cross-correlation output. Express
your answer in terms of the sample index of the peak of the
correlation output and the length of the pilot sequence. If the
correlation output is named CorrOutput, then the peak value
and the index at which it occurs can be found via
[value,indx] = max(abs(CorrOutput));
peak = CorrOutput(indx);
Suggestions:
(c) [Optional] Using the baseband processing from step (b), view
the changes to the received IQ symbols for channel gain H 6= 1
and nonzero noise variance.
(d) Armed with baseband processing from step (b), next consider
estimation of the proper symbol timing. Augment your base-
band receiver processing chain from step (b) by implement-
ing the CMA symbol timing recovery algorithm described in
Equation 5.1 and Equation 5.2. To begin, review the defini-
tion of variance of a list of numbers and calculation of variance
using var in Matlab. Re-use your code from step (b); set
N = 500. For your tests, a suggested parameter set for pulse
shaping is: D=5, alpha=0.5, and L=10.
Table 5.3 provides suggested plotting commands that you can
insert into your code to use the power of visualization in de-
bugging and interpreting your results. (Note: you may need to
modify variable names to match your code.)
Verify the correctness of your algorithm using scatter plots of
Q5.2 IQ samples before and after symbol timing recovery. Test your
5.2. EXPLORATIONS 73
% transmitted signal
figure;
plot(m,’bo’);title(’Baseband Tx Message’)
% eye diagram
eyediagram(y_up,L,length(a),’complex’);
% CMA criterion
figure;plot(0:L-1,cma_test);
title(’CMA variance criterion’)
% upsampled MF outputs; superimpose downsampled values
plot(p_est:length(y_up),real(y_up(p_est:end)));hold on
plot(p_est:L:length(y_up),real(y_up(p_est:L:end)),’ro’)
title(’Downsampling of MF Outputs’)
% video illustrating all choices for downsampling
figure
for kk=1:L
plot(kk:length(y_up),real(y_up(p_est:end)));hold on
plot(kk:L:length(y_up),real(y_up(p_est:L:end)),’ro’);
title(’Symbol timing from CMA’,’fontsize’,13);hold off
pause(0.5)% view at two frames per second
end
% correlation output
figure;plot(xc);
title(’Cross-correlation for frame timing’)
% scatter plot
figure;
plot(real(y_up(start:L:end)), ...
imag(y_up(start:L:end)),’ko’);
grid on; axis image;
title{’IQ samples after symbol timing recovery’)
74 CHAPTER 5. SYNCHRONIZATION
(e) Augment your baseband receiver processing chain from step (d)
to insert frame synchronization explored in step (a). Note the
frame synchronization operates on the downsampled matched
filter outputs, ỹ[n]. Verify operation of your frame synchro-
nization by running the simulation with nonzero tau greater
than L.
(f) Augment your baseband receiver processing chain from step (e)
to insert the flat fading channel equalization from Equation 5.5.
Verify operation of your frame synchronization by running the
simulation with several choices of gain and phase for H.
Q5.4 Generate one figure illustrating the combined performance of
the CMA symbol timing recovery, frame timing recovery, and
flat fading channel equalization; provide a descriptive caption
and list simulation values for both the modem parameters and
the channel impairment parameters.
Q5.5 For your report, append code for the software simulator as
augmented at step (f). Provide two or three figures illustrat-
ing execution of your modem simulator as performed in the
Demonstration below; with the figures, provide a descriptive
caption and a table listing both the modem parameters and
the channel impairment parameters.
5.3 Demonstration
Demonstrate your complex-baseband modem simulator using a mix
of parameter settings for the channel impairment variables given in
5.4. SUMMARY 75
Table 5.2.
5.4 Summary
In Chapter 5, techniques have been introduced to recover symbol
timing and frame timing at the receiver. In addition, frame timing
also provided equalization for a flat fading channel response. The
exercises provide a complete working baseband modem; in the next
chapter, the processing will be extended to operate the modem using
bandpass signals at an acoustic carrier frequency. The explorations in
this chapter introduced the new commands summarized in Table 5.4.
6.1 Background
The complex-baseband equivalent model completed in Chapter 5 is
shown in Figure 6.1. In the illustration, the baseband signal is shown
upsampled to L samples per symbol, and the model is therefore
referred to as “fractionally sampled.” In this chapter, the process-
ing is extended to perform analog quadrature amplitude modulation
(QAM) and demodulation using an acoustic carrier frequency. Due
to the inherent mismatch between transmitter and receiver oscilla-
tors, a frequency recovery step is inserted in the receiver processing
chain. The bandpass model is depicted in Figure 6.2.
77
78 CHAPTER 6. FREQUENCY RECOVERY
w̃[k]
DUC s(t)
ã[n] ã↑ [k] m̃[k] s[k]
L gtx [k] Re DAC
ej2πfc Ts k
DDC r(t)
ỹ[n] ỹ↑ [k] ṽ[k] r[k]
L grx [k] ADC
2e−j2πfc Ts k
where T is the symbol period and the index n counts the sampled
marker sequence from n = 0. The phase offset term e−jφ may be
6.1. BACKGROUND 79
ã[n]
angle = (2πf∆ T ) n, (6.3)
ỹ[n]
Frequency Recovery
0
Phase error in received pilot symbols
LS line fit
−0.1
Unwrapped phase (radians)
−0.2
−0.3
−0.4
−0.5
−0.6
−0.7
−0.8
0 2 4 6 8 10 12
Symbol number
Wrapped Phase and Linear Fit Unwrapped Phase and Linear Fit
8
3
7
Unwrapped phase (radians)
2
Wrapped phase (radians)
6
1
5
0 4
3
−1
2
−2
1
−3 0
0 5 10 15 20 25 0 5 10 15 20 25
Symbol number Symbol number
Figure 6.4: Phase difference (dots) and linear fit (dashed line) per-
formed without (left) and with (right) phase unwrapping.
6.1. BACKGROUND 81
Thus, the impairments in the baseband signal due to the flat fading
channel model are limited to a gain, a phase, and a time delay.
More generally, a frequency-selective fading channel model pro-
vides a gain and phase that vary as a function of frequency. The most
common frequency-selective channel model is a multi-path model, in
which the received signal is a noisy sum of delayed and attenuated
versions of the transmitted signal. For K paths, each with complex-
valued gain Ak and path delay τk , the so-called K-tap impulse re-
sponse model is
K
X
h̃(t) = Ak δ(t − τk ). (6.5)
k=1
The different delayed signal versions result from multiple propagation
paths between the transmitter and receiver. At radio frequencies,
causes of multi-path include atmospheric ducting and reflections from
buildings or mountains. The constructive and destructive interfer-
ence of the multiple arriving signals causes a frequency-dependent at-
tenuation. Timing recovery and equalization for a frequency-selective
fading channel are considered in Chapter 8.
1 1 n o
{ỹ[n] ⋆ c∗ [−n]} = h̃[n] ⋆ c[n] + w̃[n] ⋆ c∗ [−n]
N N
1 1
= h̃[n] ⋆ c[n] ⋆ c∗ [−n] + {w̃[n] ⋆ c∗ [−n]}
N N
1
≈ h̃[n] ⋆ δ[n − N ] + {w̃[n] ⋆ c∗ [−n]}
N
≈ h̃[n − N ]. (6.7)
6.2 Explorations
In this lesson, students complete development of a bandpass QAM
modem simulator by implementing quadrature modulation to an
acoustic carrier frequency and creating a frequency recovery step
in the receiver processing chain. The baseband channel model con-
sidered is a flat fading channel with additive white Gaussian noise.
The processing chain is illustrated in Figure 1.1 and Figure 5.2.
For the laboratory exploration, work through the three steps be-
low to implement a bandpass modem in simulation. Recommenda-
tions for preparing a brief, descriptive laboratory report are included
in the suggested steps.
Important: to aid with debugging and understanding, insert a
graph at each step of the processing chain depicted in Figure 1.1.
(b) Augment your bandpass receiver processing chain from step (a)
by implementing the frequency recovery algorithm described
in Section 6.1.1. And, use the estimated frequency offset to
correct the phase of the received symbols.
To begin, review the online help for the commands unwrap and
polyfit. Test your frequency recovery algorithm using the
following suggested modem parameters:
For each test, view the results by plotting a scatter plot before
and after the frequency recovery step. For reporting, simply
provide IQ scatter plots for two of the four cases considered,
along with a list of the simulation parameters for the modem,
including channel impairments.
6.3 Demonstration
Demonstrate your bandpass modem simulator implemented in step
(b) for a combination of channel impairment variables of your choice.
6.4 Summary
In Chapter 6, a technique has been introduced to recover a frequency
offset at the receiver. In addition, flat versus frequency-selective
fading channel models have been explored via an optional channel
sounding experiment. The explorations introduced new commands
summarized in Table 6.1.
7.1 Background
7.1.1 Mobile app
An acoustic quadrature amplitude modulation transmitter is avail-
able as a mobile app. The app may be obtained for Apple devices at
the iTunes App Store1 , and a version for Android devices is available
at Google Play.
The acoustic transmitter app can be operated in two modes: car-
rier tone and text transmission. In carrier tone mode, the app simply
transmits the waveform cos(2πfc t) for a 400 millisecond duration at a
user-specified carrier frequency fc < 22.05 kHz. In the text transmis-
sion mode, the pilot sequence may be selected as either a 13-symbol
Barker code or a 51-symbol pseudo-random sequence. The routine
makepilots.m is provided in Appendix C to define these pilot se-
quences. The data payload is fixed at 50 ASCII characters; a text
string of fewer than 50 characters entered on the app is augmented
with the underscore symbol, , to achieve a 50 character payload.
The user-defined inputs for text transmission are listed in Table 7.1.
1
App Name: Acoustic Transmitter; App SKU: Acoustic Transmitter.
87
88 CHAPTER 7. ACOUSTIC MODEM
The home page and settings page of the app are illustrated in
Figure 7.1.
header payload
1 … Ntr 1 … Np
7.2 Explorations
In this chapter, students implement and experimentally verify an
acoustic modem. The acoustic modem should be designed to achieve
a spectral efficiency η > 1. For the transmitter, students may use
their code from Chapter 3 and Chapter 6 to transmit from one com-
puter to another. Alternatively, the app described in Section 7.1.1
may be used as an implementation of the transmitter on a mobile
device.
The laboratory report should contain these brief elements:
(i) A table listing choices for all modem parameters: audio sam-
pling frequency, carrier frequency, symbol period, pulse shape
parameters, digital modulation format, pilot sequence;
(ii) Also include in the table the following parameters: packet
length (in symbols); data rate (bits per second); the experimen-
tally estimated frequency offset, in Hertz, between the transmit
and receive devices; bit error rate (BER); the number of bits
measured to report the BER; and, the estimated frequency off-
set, in Hertz, between the transmit and receive devices.
(iii) A short paragraph describing the physical experimental setup
for the transmitter and receiver;
(iv) A time and frequency plot (plottf) of the received audio-
frequency bandpass signal;
(v) Scatter plot of the received symbols before timing recovery and
downsampling;
(vi) Scatter plot of the received symbols after timing recovery and
downsampling;
(vii) A final scatter plot of the received symbols after frequency
recovery.
Students are encouraged to consider four suggestions given below
for achieving the design goals; see Appendix A for a brief discussion
of recommended software design practices.
7.3 Demonstration
Demonstrate your acoustic modem.
7.4 Summary
In Chapter 7, the physical layer communication design steps explored
in Chapters 1 through 6 have been integrated to implement and
verify a spectrally efficient modem operating at an acoustic car-
rier frequency. The implementation is designed for a flat-fading
channel. The baseband processing translates seamlessly to narrow-
band communication using a radio-frequency channel, as explored in
94 CHAPTER 7. ACOUSTIC MODEM
Frequency-Selective Fading
95
96 CHAPTER 8. FREQUENCY-SELECTIVE FADING
Eye Diagram
1.5
0.5
-0.5
-1
-1.5
10 20 30 40 50 60 70 80 90
Eye Diagram
1.5
0.5
-0.5
-1
-1.5
10 20 30 40 50 60 70 80 90
Figure 8.1: BPSK eye diagrams for no ISI (top) and ISI (bottom).
8.1. BACKGROUND 97
8.1 Background
8.1.1 Frame timing for ISI channels
For frame timing in the presence of a frequency-selective fading chan-
nel, we consider the approach proposed by Moose [24]. The method
relies on a periodic pilot sequence and is used, for example, in IEEE
802.11a/g [15].
A length K FIR symbol-rate model of the channel impulse re-
sponse,
{h̃[n]}K−1
n=0 ,
(8.2)
Because the (K −1) symbols prior to the start of pilots are unknown,
the summation in the cross-correlation in Equation 8.2 runs from
(K − 1) to (Np − 1), rather than 0 to (Np − 1).
K−1
X
ỹ[n + Np ] = ej2πf∆ (n+Np )T h̃[i]ã[n + Np − i] + w̃[n + Np ]. (8.4)
i=0
K−1
X
j2πf∆ Np T j2πf∆ nT
ỹ[n + Np ] = e e h̃[i]ã[n − i] + w̃[n + Np ]
i=0
= ej2πf∆ Np T ỹ[n] + {w̃[n + Np ] − w̃[n]} . (8.6)
noise w̃[n]
ỹ[n] q̃[n]
channel h̃[n] equalizer b̃[n]
pilots
+ ẽ[n]
ã[n]
delay ∆
M
X
q̃[n] = b̃[k]ỹ[n − k]. (8.8)
k=0
2Np −1 M 2
X X
J∆ (b) = b̃[k]ỹ[n + ∆ − k] − ã[n] . (8.9)
n=0 k=0
100 CHAPTER 8. FREQUENCY-SELECTIVE FADING
8.2 Explorations
In this lesson, students modify their acoustic modem simulator from
Chapter 6 to implement frequency and timing recovery that is robust
to a frequency-selective fading channel.
For the laboratory exploration, work through the three steps be-
low to implement in simulation a bandpass modem for ISI channels.
Recommendations for preparing a brief, descriptive laboratory report
are included in the suggested steps below.
8.3 Demonstration
Demonstrate your modem simulator for a five-tap ISI channel and
other channel impairment variables of your choice.
8.4 Summary
In Chapter 8, a technique has been introduced to recover frame tim-
ing and a frequency offset in the presence of an ISI channel. In
addition, a linear equalizer was developed to combat the effect of the
channel impairment on data symbols. The explorations introduced
new commands summarized in Table 8.1.
9.1 Background
9.1.1 Channel capacity
Suppose that we encounter a low signal-to-noise ratio (SNR), but
would like to achieve a low probability of error. Into the 1940s,
the conventional wisdom was to repeat the same symbol multiple
times and use a majority vote at the receiver. While this approach
does reduce the probability of error, the rate of information bits per
symbol reduces linearly with the number of repetitions. Indeed, to
drive the error arbitrarily small, the bit rate must go to zero!
Using elementary arguments, Shannon showed that it is indeed
possible to communicate at an arbitrarily low probability of error
yet maintain a non-zero data rate, C, called the channel capacity.
103
104 CHAPTER 9. CHANNEL CODING
The three errors are identifiable because not all text strings are al-
lowable words. That is, English has redundancy. A reader’s guess
at the correction may be described as making the fewest changes so
9.1. BACKGROUND 105
yH T = cH T + eH T
= 0 + eH T
= s (9.7)
occured, then the syndrome is zero. If one error occurs, then the non-
zero syndrome identifies the most likely error pattern, ê; this error
vector is then added to y to yield the decoded string of bits. For two
or more errors, the syndrome decoding may or may not return the
correct codeword. For block codes with minimum distance greater
than 3, syndrome decoding can be extended to detect and correct
more than one bit error per block of n received bits.
If bit errors occur in bursts, then direct use of a channel code will
not allow detection and correction of the cluster of errors. An effec-
tive method of dealing with burst errors is to interleave (shuffle) the
coded data so that the channel with bursts of errors is approximately
transformed into a channel with independent errors [35]. A simple
approach is the block interleaver, which reads in coded bits row by
row, then reads out bits to the modulator column by column.
9.2. EXPLORATIONS 109
9.2 Explorations
In this chapter, students implement and experimentally verify a (7, 4)
block code. The brief laboratory report should contain answers to
the questions enumerated in the margins; subroutines for channel
coding and decoding with the (7, 4) block code should be appended.
(a) Block codes are often listed by triples, (n, k, d), where (n−k) is Q9.1
the number of parity bits, k is the number of information bits,
and d is the minimum distance between codewords. Compare
and contrast the rates for three block codes: (7, 4, 3), (8, 4, 4),
(16, 5, 8).
(b) Expand your BPSK simulation from Chapter 3 to include chan- Q9.2
nel coding. Create function calls that perform (7, 4) block cod-
ing and decoding. Repeat the bit error rate simulation from the
demonstration in Section 3.3, but generate the plot for Eb /N0
only on the range 0 to 10 dB. For comparison, overlayp the the-
oretical curve for uncoded BPSK data, BER = Q( 2Eb /N0 ),
found in Chapter 3. For your report, present the BER curve
and append code for your block coding and decoding functions.
Although binary arithmetic is computationally efficient, a Mat-
lab implementation of yG using double precision real variables
is simple to compute using modulo-2 arithmetic, mod(y*G,2).
For example, re-use random bit generation from Chapter 3:
k = 4; N = 250;
bits = round(rand(1,k*N));%random 0’s and 1’s
% use function from part 9(b)
codedbits = blockcode74(bits);
110 CHAPTER 9. CHANNEL CODING
Q9.3 (c) Block codes are often listed by triples, (n, k, d), where (n − k)
is the number of parity bits, k is the number of information
bits, and d is the minimum distance between codewords. The
probability of error for a (n, k, d) linear block code is bounded
by [21] s !
k k 2Eb
P ≤ (2 − 1)Q d , (9.8)
n N0
whereas the probability of error for the uncoded case was found
in Chapter 3 to be
s !
2Eb
P =Q (9.9)
N0
C = log2 (1 + SNR)
1
= ln (1 + SNR)
ln 2
1
≤ SNR.
ln 2
Continuing, use the definitions SNR = Es /N0 and Es = Eb R,
where Es is energy per symbol, Eb is energy per bit, and Rb
is bit rate. The derivation also requires that bit rate cannot
exceed capacity: Rb ≤ C. Express your answer in dB by com-
puting 10 log10 of the power quantity and rounding to two sig-
nificant digits.
9.3 Demonstration
Demonstrate execution of the codes developed in step (b).
112 CHAPTER 9. CHANNEL CODING
9.4 Summary
In Chapter 9, the concept of channel capacity was introduced as a
fundamental bound on the rate at which data can be transmitted
through a noisy channel. Block coding was presented as a simple
way to insert structured redundancy into a transmitted bit stream, in
order to allow detection and correction of errors at the receiver. The
explorations introduced a new command summarized in Table 9.3.
113
114 CHAPTER 10. OFDM PART 1
10.1 Background
In this and the next chapter, we focus on the discrete-time baseband
equivalent channel model,
ỹ = h̃ ∗ ã + w̃. (10.1)
y = h ∗ a, (10.4)
1 NX−1
Xk = √ xn e−j2πkn/N (10.9)
N n=0
1 NX−1
xn = √ Xk ej2πkn/N . (10.10)
N k=0
[1 2 3] [5 4 6 1 3 2]
= 1 x [5 4 6 1 3 2]
+ 2 x [2 5 4 6 1 3]
+ 3 x [3 2 5 4 6 1]
= [18 20 29 25 23 11]
[1 2 3] ∗ [3 2 5 4 6 1 3 2]
= 1 x [3 2 5 4 6 1 3 2]
+ 2x [3 2 5 4 6 1 3 2]
+ 3x [3 2 5 4 6 1 3 2]
= [3 8 18 20 29 25 23 11 13 6]
Observe that
we further know that DFT10 (ak ) is vector with all but the kth entry
being zero. In other words, the symbol sequence ak only has the kth
frequency component.
According to Equation 10.6, which we restate below, if we trans-
mit ak on the channel with response h, then the received signal
also only has the kth frequency component. More precisely, we will
have the received signal being Hk ak , where Hk is the kth element in
DFT10 (h).
DFTN (h ⊛ a) = DFTN (h) × DFTN (a).
In Figure 10.2, we plot both DFT(h) and the absolute value of the
received the symbols after transmitting ak for ten sample times with
k = 8 through a channel with response h. From the figure, we can
verify that the gain in amplitude after transmitting a8 is |H8 |, which
conforms with Equation 10.6.
DFT 10(h)
10 10
7 7
absolute value
6 6
5 5
4 4
3 3
2 2
1 1
0 0
0 2 4 6 8 10 20 30 40 50 60 70 80
frequency index sample index
10.2 Explorations
A lab report should provide answers to the following questions.
(a) Given the definition of DFT in Equation 10.9, verify the cor- Q10.1
rectness of Equation 10.6.
120 CHAPTER 10. OFDM PART 1
Q10.2 (b) Let x1 = [1, 2, 3, 4, 5, 6], x2 = [5, 2, 4, 3, 1, 6], and h = [1, 2, 1, 1].
Q10.3 (c) For N = 6, find DFTN (x) for x = [1, 1, 1, 1, 1, 1]. Repeat for
x = [1, −1, 1, −1, 1, −1].
10.3 Demonstration
Demonstrate the execution of the codes developed in step (d).
10.4 Summary
In Chapter 10, we introduced a frequency-domain channel equal-
ization technique for combating frequency selectivity in wide-band
wireless systems. We showed that by prepending a cyclic prefix with
length larger than the channel memory onto the transmitted packet,
we can equalize the channel gain on a per-frequency-tone basis with
low-complexity FFT and IFFT operations. This chapter serves as
a stepping stone for implementing OFDM in the next chapter. The
explorations introduced new commands summarized in Table 10.1.
121
122 CHAPTER 11. OFDM PART 2
11.1 Background
11.1.1 Orthogonal frequency division multiplexing
Let us simplify the notation for the procedures shown in Equation 11.1
as the following.
equivalent channel
a ===========⇒ H · A
Note that after a is sent through the equivalent channel, the receiver
obtains the point-wise product of the N -point channel frequency re-
sponse and the N -point DFT of a. This point-wise product is the
key to realizing that it is possible to convert the multi-tap channel
into N single-tap channels, with each channel corresponding to a
term in the point-wise product. The idea is the following: instead of
sending a, let us send the N -point IDFT version of a, denoted as b,
through the equivalent channel, which results in the procedures in
Equation 11.2.
a b b
...
...
Bits Modulation Symbols
...
Series
Parallel to
Bits Modulation Symbols Add Prepend
Parallel
Series to
Pilot
CP OFDM
...
IFFT Packet
Bits
...
Bits Modulation Symbols Symbols Symbols
... ... ...
...
Bits Modulation Symbols
h Multi-tap
Channel
...
Bits Modulation Symbols
...
Parallel
Series to
CP
Discard
Bits Modulation Symbols Remove
Series
Parallel to
Bits FFT
...
Bits Modulation Symbols Symbols Symbols
... ... ...
...
H·a b h b∗h if P ≥ L − 1
From the above result, we can observe that the nth symbol in each
symbol vector, a1 , a2 , a3 , · · · , experiences the same one-tap channel
gain H[n]. In other words, the procedure in Equation 11.3 effectively
converts the multi-tap channel into N -single tap channels, where for
any symbol vector a, the nth symbol experiences a channel with gain
H[n].
Because the transmitted symbol vector, b, is the IDFT of the
data symbol vector, a, we know that the data symbols in a are the
124 CHAPTER 11. OFDM PART 2
0.5
-0.5
-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
0.5
-0.5
-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Figure 11.2: The time domain waves of the five frequency subcarriers
in DFT5 .
a[0]
...
...
Bits Modulation Symbols
...
Series
Parallel to
Bits Modulation Symbols Add Prepend
Parallel
Series to
Pilot
CP OFDM
...
IFFT Packet
Bits
...
Bits Modulation Symbols Symbols Symbols
... ... ...
...
Bits Modulation Symbols
Single-tap Multi-tap
Channel
H[0] Channel
...
Bits Modulation Symbols
...
Parallel
Series to
CP
Discard
Bits Modulation Symbols Remove
Series
Parallel to
Bits FFT
...
Bits Modulation Symbols Symbols Symbols
... ... ...
...
H[0] · a[0] if P ≥ L − 1
Time-Frequency
Resource Grid
a1 [0] a2 [0]
a1 [1] a2 [1] am [1] subcarrier 1
a1 [2] a2 [2] am [2] subcarrier 2
a1 [3] a2 [3] ... am [3] subcarrier 3
a1 [4] a2 [4] am [4] subcarrier 4
... ... ...
a1 [N − 1] a2 [N − 1] am [N − 1] subcarrier N-1
Time
11.2 Explorations
A lab report should provide answers to the following questions.
(b) Write and test subroutines for each step in the above equation. Q11.2
(c) Write a function that combines the subroutines from step (b) Q11.3
to create a baseband simulator for OFDM. The example .m file
header below provides defining requirements for the function.
[Output_symbol_matrix]=...
OFDM_Transceiver(Input_symbol_stream,M,N,h,P)
% --------- Input ---------
% Input_symbol_stream is a row vector of length M*N
% N is the IFFT and FFT size.
% P is the cyclic prefix length
% h is the channel impulse response in vector form
% --------- Output ---------
% Output is a M by N matrix, with the n-th row
% being the output of the n-th subcarrier.
% --------- Requirement ---------
% ’conv’ command is invoked only once.
% Calculation of the FFT of h is not allowed.
M=100;
N=1024;
P=10;
h=[1,2,2*1j,-1j];
Input_symbol_stream=ones(1,M*N);
(e) [Optional] Use the baseband simulator from step (d) and the
acoustic modem from Chapter 7 as a foundation from which
to construct an acoustic transmitter and receiver using orthog-
onal frequency division multiplexing. At the transmitter, the
waveform bb will serve as input to the pulse shaping filter. At
the receiver, pilot symbols will be used to estimate a complex-
valued channel gain for each time-frequency grid point; for a
channel that is static across time, a simple strategy is to place
a known pilot symbol at every location in the first column of
the grid shown in Figure 11.4. In an attempt to create an ISI
channel, rather than a narrow-band flat fading channel, select
a low-carrier frequency and short symbol interval. The result-
ing bandpass acoustic signal should haves a large fractional
bandwidth, defined as the bandwidth divided by the carrier fre-
quency.
11.3 Demonstration
Demonstrate the execution of the codes developed in step (c).
11.4 Summary
In Chapter 11, the orthogonal frequency division multiplexing scheme
was derived. ODFM is the fundamental building block in almost
all wide-band wireless systems, and the scheme effectively converts
a wide-band multi-tap channel into multiple orthogonal single-tap
sub-channels. Explorations guided students through implementation
of an OFDM transceiver.
CHAPTER 12
Adaptive Processing
129
130 CHAPTER 12. ADAPTIVE PROCESSING
ADC LPF
Costas
T
ejθk Loop
2ej(2π(fc +f∆ ) L k+φ) θk
Figure 12.1: Feedback loops for adaptive carrier phase recovery: (a)
Costas loop; (b) decision-directed phase recovery.
12.1 Background
T
dk = 2πf∆ k + φ. (12.6)
L
Thus, we seek a tracking loop to provide zero steady-state error for
a disturbance that contains a ramp, {2πf∆ T /L}k, and a step, φ. To
this end, we use a Type 2 controller with two poles at z = 1 [11],
(K1 + K2 )z − K1
C(z) = . (12.7)
(z − 1)2
Im{ṽ[k]ejθk } Re{ṽ[k]ejθk }
n o n o
= Im m[k]e−jdk ejθk Re m[k]e−jdk ejθk
= |m[k]|2 sin(θk − dk ) cos(θk − dk )
= |m[k]|2 sin(2[θk − dk ]). (12.8)
Disturbance d[k]
Error
e[k]
Reference Controller Plant
C[Z] P [Z]
−
where αn is the phase angle of the symbol a b[n] and βn is the phase
angle of the phase-corrected sample, ỹ[n]ejθn . Thus, we have the
relation n o
Im a b[n]ỹ ∗ [n]e−jθ
sin(αn − βn ) = (12.17)
|a
b[n]| |ỹ[n]|
For small angle errors, we invoke the approximation sin α = α to
define an error signal as
n o
b[n]ỹ ∗ [n]e−jθ
Im a
ek = sin(αn − βn ) = . (12.18)
|a
b[n]| |ỹ[n]|
12.2 Explorations
In this chapter, students implement and experimentally verify adap-
tive carrier phase recovery algorithms. A lab report should provide
answers to the questions enumerated in the page margins and present
commented code, as a subroutine, for the adaptive computations.
figure;
plot(angle(symbols./symbols_est)*180/pi,’r’);
hold on;grid;ylabel(’degrees’);
plot(angle(exp(1i*thetaGD))*180/pi);
legend(’OpenLoop Error’,’\theta_{grad}[k]’,...
’location’,’best’)
(c) Artificially insert into your modem receiver software a step er- Q12.3
ror at some time point in the demodulation carrier phase. Ap-
ply the gradient descent carrier phase tracking as implemented
in step (b). To view the action of the tracker in your modem
simulator, plot both the symbol angle error before tracking
and the tracker output signal, θk , from Equation 12.15. Try
for several choices of step size, µ. What do you observe?
Display the decoded text message both before and after the
decision-directed tracker. Due to mis-estimation of the carrier
frequency, the received symbol phase will drift and eventually
cause errors in the decoded text string. To view the action
of the tracker in your modem simulator, plot the angle error
before tracking, and the symbol-rate tracker signals, e[n] and
θ[n]. For example,
figure;
plot(angle(symbols./symbols_est)*180/pi,’r’);
hold on;grid;ylabel(’degrees’);
plot(angle(exp(1i*theta))*180/pi);
plot(PhError*180/pi,’g--’);
legend(’OpenLoop Error’,’\theta[k]’,...
’e[k]’,’location’,’best’)
12.3 Demonstration
In Chapters 6 and 7, a small error in frequency estimation at the
receiver could lead to an accumulated phase error that destroyed
decoding performance in a long data packet. Demonstrate any one
of your adaptive carrier phase recovery algorithms as a means for
correctly decoding a long data packet in the presence of a small
frequency offset or frequency drift.
138 CHAPTER 12. ADAPTIVE PROCESSING
12.4 Summary
In Chapter 12, adaptive processing has been introduced as a closed-
loop procedure for tracking carrier phase at the receiver. For real-
valued baseband messages, the Costas loop was derived, using both
gradient descent and a second-order tracking controller for update
equations. For general symbol constellations, a decision-directed
phase tracking procedure was introduced, again using both gradient
descent and a second-order controller to derive update equations.
The adaptive and decision-directed approaches introduced here
are representative of a wealth of procedures developed over the past
four decades (see, e.g., [27, 10, 22, 18]). For example, decision-
directed techniques have been developed for the channel equalization
challenge introduced in Chapter 8.
APPENDIX A
Software Design Suggestions
139
140 APPENDIX A. SOFTWARE DESIGN SUGGESTIONS
B.1.1 AM
Mathematically, an envelope detector for large-carrier AM reception
is described by
π
v(t) = LPF{ |r(t)| } − A ≈ m(t). (B.1)
2
The envelope detector is a noncoherent receiver in that it does not use
knowledge of the phase of the carrier signal. The gain π2 compensates
141
142 APPENDIX B. RF EXPERIMENTS
red black C3
L C1 R1 C2 R2
for the loss incurred when lowpass filtering the rectified signal,
1
R 4fc
0 cos(2πfc t)dt 2
1 = . (B.2)
4fc
π
x L C y
B1
9V
C1 R2 C5
1-33μF 27k L1 10pF
Audio IN Rf OUT
(mono) to antenna
R1 C2 C3 C4 (optional)
10k 0.01μF 0.01μF 10pF
Q1
2N3904
R3
470
B.1.2 FM
The basic regenerative circuit for FM modulation and demodula-
tion was introduced by E. H. Armstrong in 1915 [1, 19]. A super-
regenerative FM transmitter can be implemented using a single tran-
sistor design [28, 20]. The circuit schematic is given in Figure B.3
[28]; note that capacitor C4 is a variable capacitor for tuning. Many
other designs can be found from DIY sources [34].
Similarly, a single-transistor design may be used to implement a
super-regenerative FM receiver. A circuit schematic [2, 7, 5] is given
in Figure B.4; note that IC1 is an LM386 audio amplifier. Many
alternatives, e.g. [23], can be found online.
Rather than build an FM modulator and demodulator, students
144 APPENDIX B. RF EXPERIMENTS
L2 10k
10k 0.1μF
MPF102 G 0.01μF
G
0.047μF
6 inches
of 18 D
guage + 1
wire 10μF IC1
15pF
1k
+9V
+
+
+ 0.047μF 220μF
15-120pF
L1 100μF 0.047μF
0.001μF
suited for use with general QAM constellations; but, PSK digital
modulation can perform well.
Function Description
plottf.m Make time and frequency plots
firlpf.m Design low-pass filter design
char2psk.m Template for PSK digital modulation
psk2char.m Template for PSK digital demodulation
srrc.m Design square-root raised cosine filter
eyediagram.m Make eye diagram
makepilots.m Make pilot sequence
packetdetect.m Detect data packet
1
http://cnx.org
2
http://www.mathworks.com/academia/courseware
147
148 APPENDIX C. FUNCTIONS
plottf
function hh = plottf(x,Ts,str)
plot_type = 0;
if nargin==3,
if str==’f’,
plot_type = 1;
elseif str==’t’,
plot_type = 2;
end;
end;
if plot_type==1,
hh = plot(f,abs(Xs)); % plot magnitude spectrum
xlabel(’frequency [Hz]’);
ylabel(’magnitude’);% label the axes
elseif plot_type==2,
if isreal(x),
hh = plot(t,x);% plot the real waveform
xlabel(’time [sec]’);
ylabel(’amplitude’); % label the axes
else
hh = plot3(t,real(x),imag(x)); % plot the complex waveform
149
xlabel(’time [sec]’);
ylabel(’real’); zlabel(’imag’); % label the axes
end;
else
subplot(2,1,1);
if isreal(x),
hh = plot(t,x); % plot the real waveform
xlabel(’time [sec]’);
ylabel(’amplitude’); % label the axes
else
hh = plot3(t,real(x),imag(x)); % plot the complex waveform
xlabel(’time [sec]’);
ylabel(’real’); zlabel(’imag’); % label the axes
end;
subplot(2,1,2);
hh = [hh,plot(f,abs(Xs))]; % plot magnitude spectrum
xlabel(’frequency [Hz]’);
ylabel(’magnitude’) % label the axes
subplot(2,1,1);
end;
150 APPENDIX C. FUNCTIONS
firlpf
function [h]=firlpf(Lh,fpass,fstop,fsample)
%FIRLPF Least-squares design of linear-phase low-pass filter.
%
% [h] = firlpf(Lh,fpass,fstop,fsample) designs Type I, length Lh,
% linear-phase low-pass filter via least-squares design.
% Lh must be odd.
%
% Lh filter length (odd)
% fpass edge of passband (Hz)
% fstop edge of stopband (Hz)
% fsample sampling rate (Hz)
% h designed impulse response
%% argument check
if(nargin < 4)
error(’Too few input arguments for FIRLPF.’)
end
if(fpass >= fstop)
error(’Passband edge must be less than stopband edge’)
end
if(fsample <= 2*fstop)
error(’Sampling rate is sub-Nyquist’)
end
if( mod(Lh,2) ~= 1);
Lh=Lh+1;
warning(’Lh incremented for Type I FIR filter.’);
end
%% normalized frequency (radians per sample)
fpass = fpass / (fsample/2) * pi;
fstop = fstop / (fsample/2) * pi;
%% apply orthogonality principle for LS solution
indx=(1:(Lh-1)/2);
RHS = [fpass sin(fpass*indx)./indx].’;
% diagonal of matrix
tmp=zeros(1,length(indx)+1);
tmp(1) = pi - (fstop - fpass);
tmp(2:end)=tmp(1)/2+(sin(2*indx*fpass)-sin(2*indx*fstop))./(4*indx);
LHS = diag(tmp);
% off-diagonals
for row=0:(Lh-1)/2;
for col=row+1:(Lh-1)/2;
LHS(row+1,col+1) = ...
(sin((col+row)*fpass)-sin((col+row)*fstop))/2/(col+row)+...
151
(sin((col-row)*fpass)-sin((col-row)*fstop))/2/(col-row);
LHS(col+1,row+1) = LHS(row+1,col+1);%symmetry
end
end
g = LHS\RHS;g=g.’;%solve linear system
h = [g(end:-1:2)/2 g(1) g(2:1:end)/2];%linear phase impulse response
%end of function
152 APPENDIX C. FUNCTIONS
char2psk template
%% template for char2psk.m
function [a,bits] = char2psk(str,M);
% char2psk.m
% Function to map a charater string to PSK symbols
% (See also psk2char.m)
%
% Inputs:
% str string variable with text
% M size of PSK constellation (2 or 4)
% or, user can select ’bpsk’ or ’qpsk’
% Outputs:
% a output list of PSK symbols (complex-valued)
% bits output list of bits (logical)
%% error checks
if(nargin ~= 2)
error(’Error: char2psk.m requires two input arguments.’)
end
%% text to symbols
% first, string to decimal to binary
str_binary = dec2bin(double(str),8);
% convert array row-by-row to one long string
bits = reshape(str_binary.’,1,8*length(str));
% binary to symbols
switch M
case {2,’bpsk’,’BPSK’}
M = 2;
a = (2*bin2dec(bits.’)-1).’;
case {4,’qpsk’,’QPSK’}
M = 4;
%
%create your QPSK code here
%
end
bits=(bits==’1’);% convert char to logical
% end of function
153
psk2char template
%% template for psk2char.m
function [str,bits] = psk2char(y,M)
% psk2char.m
% Function to decode M-PSK symbols to a string of ASCII text.
% (See also char2psk.m)
%
% Inputs:
% M size of PSK constellation (2 or 4; or ’bpsk or ’qpsk’)
% y list of PSK IQ points (complex numbers)
% Outputs:
% strbin string variable with ASCII text
% bits list of 0/1 bits (as logical variables)
%
% Digital Communication Laboratory
% Autumn 2014
%% error checks
if(nargin ~= 2)
error(’Error: psk2char.m requires two input arguments’)
end
if (isnumeric(y) ~= 1 || isempty(y))
error(’Error: the input y must be numeric.’)
end
%% symbol slicing
% first, symbol string to string of integer labels: 0,1,...,log2(M)
% labels are integers; use double data type
switch M
case {2,’bpsk’,’BPSK’}
M = 2;
labels = (real(y) >= 0);
case {4,’qpsk’,’QPSK’}
M = 4;
%
%create code here; see Figure 3.1(b) for labeling quadrants
%
end
% second, labels into string of bits
N = length(labels)*log2(M)/8;%number of characters
tmp = dec2bin(labels,log2(M));%label to binary
strbin = reshape(tmp.’,8,N).’;%array, labels to 8 bits/character
% third, convert from char to logical:
bits = logical(bin2dec(reshape(tmp.’,1,N*8).’).’);
% fourth, convert binary to decimal ASCII to character
str=char(bin2dec(strbin)).’;%
% end of function
154 APPENDIX C. FUNCTIONS
srrc
function g = srrc(D,alpha,L)
% SRRC Fractionally-sampled square-root raised cosine pulse.
%
% [g] = srrc(D,alpha,L) creates a fractionally-sampled square-root
% raised cosine pulse
%
% D one-half the length of srrc pulse in symbol durations
% alpha excess bandwith (valude between 0 and 1);
% alpha=0 gives a sinc pulse
% L samples per symbol (oversampling factor);
% L must be a positive integer
% g samples of the srrc pulse
%% argument check
if(nargin < 3)
error(’Too few input arguments for SRRC’)
end
if( min( [D,alpha,L] ) < 0 )
error(’Inputs must be non-negative for SRRC.’)
end
if( round(L) ~= L )
error(’Input L must be a non-negative integer for SRRC.’)
end
%% compute samples
k = -D:(1/L):D; % k is t/T
g = (sin(pi*(1-alpha)*k)+(4*alpha*k).*cos(pi*(1+alpha)*k)) ./ ...
((pi*k) .* (1-(4*alpha*k).^2))/sqrt(L);
%% fill in for denominator zeros
g(k==0) = (1 + (4/pi-1)*alpha)/sqrt(L);
g(abs(abs(4*alpha*k)-1) < sqrt(eps)) = ...
alpha/sqrt(2*L)*( (1+2/pi)*sin(pi/4/alpha) + ...
(1-2/pi)*cos(pi/4/alpha));
%end of function
155
eyediagram
function [] = eyediagram(y_up,L,N,IQ)
% eyediagram.m
% Function to plot an eye diagram
%
% y_up upsampled matched filter outputs
% L downsampling factor (integer)
% N number of symbols
% IQ string, ’complex’, if both I and Q are desired
%
% Note that first sample of y_up is assumed to occur at a symbol time.
%% error checks
if(nargin < 2)
error(’Error: eyediagram.m requires two input arguments’)
end
if(nargin == 3), IQ=’real’; end
if(strcmp(IQ,’complex’))
IQ=1;%plot both I and Q
else
IQ=0;
end
%N-2 segments for N symbols
%% plots
if(IQ == 0)
% plot eye diagram, I channel only
figure;
plot(-floor(L/2)/L+(0:L-1)/L,real(Y_up));% superimpose them
title(’Eye Diagram’,’fontsize’,13);
xlabel(’relative symbol index’,’fontsize’,13);
else
% plot eye diagram, I & Q channels
figure;
subplot(211);plot(-floor(L/2)/L+(0:L-1)/L,real(Y_up));
title(’Eye Diagram’,’fontsize’,13);
subplot(212);plot(-floor(L/2)/L+(0:L-1)/L,imag(Y_up));
xlabel(’relative symbol index’,’fontsize’,13);
end
156 APPENDIX C. FUNCTIONS
makepilots
function [pilots] = makepilots(opt)
%MAKEPILOTS generate pilot sequence
%
% [pilots] = makepilots(opt) generates a sequence of pilot symbols
%
% opt indicator to select pilot sequence:
% Barker: ’barker13’, ’B’, ’b’, ’Barker’, or ’barker’ (default)
% PN: ’pn51’, ’PN’, ’pn’, or ’pseudorandom’
% split Barker: ’splitbarker’ or ’splitBarker’
%
% The length-13 Barker code and length-51 pseudo-random code
% generated here are employed in the acoustic transmitter mobile
% app available at iTunes Apps or Google Play.
packetdetect
function [ rx_Trim ] = packetdetect( yup , L, pkt_len)
%PACKETDETECT energy detector to approximately locate a data packet;
% trims a received upsampled signal
%
% [rx_Trim] = packetdetect(yup,L,pkt_len)
%
% yup fractionally sampled matched filter output
% L upsampling factor
% pkt_len packet length (including both header and payload)
Mask=ones(1,pkt_len*L);
Energy_Corr=conv(abs(yup).^2,Mask);
Energy_Corr=Energy_Corr(length(Mask):end);
[~,Max_Energy_Index]=max(Energy_Corr);
End_Packet_Index=min(length(yup),Max_Energy_Index+(pkt_len+3)*L);
rx_Trim=yup(Max_Energy_Index-3*L-round(max(10,L)*rand(1,1)) : ...
End_Packet_Index);
%for educational use:
% randomized offset to test frame timing;
% presumes at least 4L noise samples precede packet
end
158 APPENDIX C. FUNCTIONS
Glossary
Notation
The indexing conventions f (t), f [k], and f [n] are adopted to suggest
a continuous-time signal representation, a fractionally-sampled base-
band signal representation, and a symbol-rate sampled signal repre-
sentation, respectively. A tilde, as in m̃, denotes a complex-valued
quantity carrying both in-phase and quadrature components.
Symbol Quantity
fc carrier frequency
fs sampling frequency
Ts sampling period
T symbol period
M constellation size
gtx (t), gtx [k] pulse shaping filter
Gtx (f ) Fourier transform of gtx (t)
D pulse half-width, in symbol intervals
L upsampling factor
α excess bandwidth; a pulse shaping parameter
W one-sided baseband bandwidth (Hertz)
p(t) convolution of pulse shape and matched filter
P (f ) Fourier transform of p(t)
Ntr length of pilot, or training, symbol sequence
159
160 GLOSSARY
Symbol Quantity
Acronyms
ADC analog-to-digital converter
AM amplitude modulation
ASCII American standard code for information interchange
AWGN additive white Gaussian noise
BER bit error rate
BPSK binary phase-shift keying
CDMA code-division multiple access
CMA constant modulus algorithm
CP cyclic prefix
DAC digital-to-analog converter
DDC digital downconverter
DFT, IDFT discrete Fourier transform, inverse DFT
DDS direct digital synthesis
DPSK differential phase-shift keying
DSP digital signal processor
DUC digital upconverter
FFT, IFFT fast Fourier transform, inverse FFT
FIR finite impulse response
I in-phase
I/O input/output
IF intermediate frequency
ISI inter-symbol interference
PA power amplifier
PSK phase-shift keying
LNA low-noise amplifier
LPF low-pass filter
NCO numerically controlled oscillator
OFDM orthogonal frequency division multiplexing
PHY physical layer
Q quadrature
QAM quadrature amplitude modulation
QPSK quadrature phase-shift keying
RF radio frequency
SDR software-defined radio
SNR signal to noise ratio
sps samples per second
SRRC square-root raised cosine pulse
UHF ultra-high frequency (300 – 1,000 MHz)
VCO voltage-controlled oscillator
162 GLOSSARY
Bibliography
[8] Evan Everett and Michael Wu. Eec 433 architeture for
wireless communications. www.warpproject.org/trac/wiki/
Rice_ELEC_433. Accessed: 2015-06-12). 145
163
164 BIBLIOGRAPHY
167
168 INDEX
randn, 16
recordblocking, 13
rtl, 146
sampling, 6
sampling rate, 6
save, 92
scatter plot, 40
signal space, 38
sinc interpolation, 10
software-defined radio, 2
spectral efficiency, 44, 88
square-root raised cosine, 55
srrc.m, 58, 154
subcarrier frequency, 124
subplot, 34
symbol timing, 64