Intro to Lab

advertisement
Communications II
Experiment V
COMMUNICATIONS II
EXPERIMENT 5
Group member 1
Name:
Number:
Group member 2
Name:
Number:
1. OBJECTIVES


Sampling in MATLAB
Encoding and Pulse Shape Filtering
2. BASIC INFORMATION
2.1 Sampling in Matlab
Consider representing a sine wave of frequency f = 100 Hz. The sampling theorem asserts that
the sampling rate must be greater than the Nyquist rate of 200 samples per second. But in
order to visualize the wave clearly, it is often useful to sample considerably faster.The
following Matlab code calculates and plots the first 1/10 second of a 100 Hz sine wave with a
sampling rate of fs =1/Ts=10000 samples per second.
% sine100hz.m generate 100 Hz sine wave with sampling rate fs=1/Ts
f=100;
time=0.1;
Ts=1/10000;
t=Ts:Ts:time;
w=sin(2*pi*f*t);
plot(t,w)
xlabel('seconds')
ylabel('amplitude')
%
%
%
%
%
%
frequency of wave
total time in seconds
sampling interval
define a "time" vector
define the sine wave
plot the sine vs. time
% label the axes
RUN sine100hz.m and see that it plots the first 10 periods of the sine wave. Each period lasts
0.01 seconds, and each period contains 100 points. Type
plot(w(1:100))
and VERIFY this. Changing the variables time or Ts displays different numbers of cycles of
the same sine wave, while changing f plots sine waves with different underlying frequencies.
When the sampling is rapid compared to the underlying frequency of the signal (for instance,
the program sine100hz.m creates 100 samples in each period), then the plot appears and acts
much like an analog signal, even though it is still, in reality, a discrete time sequence. Such a
sequence is called oversampled relative to the signal period. The following program simulates
the process of sampling the 100 Hz oversampled sine wave.
% sine100hzsamp.m: simulated sampling of the 100 Hz sine wave
f=100; time=0.05; Ts=1/10000; t=Ts:Ts:time;
% freq and time vectors
w=sin(2*pi*f*t);
% create sine wave w(t)
ss=10;
% take 1 in ss samples
wk=w(1:ss:end);
% the "sampled" sequence
ws=zeros(size(w)); ws(1:ss:end)=wk;
% sampled waveform ws(t)
1
Communications II
Experiment V
plot(t,w)
hold on, plot(t,ws,'r'), hold off
xlabel('seconds'), ylabel('amplitude')
% plot the waveform
% plot "sampled" wave
% label the axes
Running sine100hzsamp.m results in the plot shown in Figure 1, where the continuous" sine
wave w is downsampled by a factor of ss=10; that is, all but one of each ss samples is
removed. Thus, the waveform w represents the analog signal that is to be sampled at the
effctive sampling interval ss*Ts. The spiky signal ws corresponds to the sampled signal ws(t),
while the sequence wk contains just the amplitude values at the tips of the spikes.
Figure 1: Removing all but one of each N points from an oversampled waveform simulates
the sampling process.
1
0.8
0.6
0.4
amplitude
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0
0.005
0.01
0.015
0.02
0.025 0.03
seconds
0.035
0.04
0.045
0.05
2.2 Encoding and Pulse Shape Filtering
Text is commonly encoded using ASCII, and Matlab automatically represents any string file
as a list of ASCII numbers. For instance, let
str='I am text'
be a text string. This can be viewed in its internal form by typing
real(str),
which returns the vector 73 32 97 109 32 116 101 120 116, which is the (decimal) ASCII
representation of this string. This can be viewed in binary using
dec2base(str,2,8),
which returns the binary (base 2) representation of the decimal numbers, each with 8 digits.
The Matlab function letters2pam, provided on the CD, changes a text string into the 4-level
alphabet ±1; ±3. Each letter is represented by a sequence of 4 elements, for instance the letter
I is -1 -3 1 -1. TYPE
str='I'
letters2pam(str)
and verify.
The function is invoked with the syntax letters2pam(str). (The inverse operation is
pam2letters. Thus pam2letters(letters2pam(str)) returns the original string.)
2
Communications II
Experiment V
Even though the original message is translated into the desired alphabet, it is not yet ready for
transmission: it must be turned into an analog waveform. In the binary case, a simple method
is to use a rectangular pulse of duration T seconds to represent +1, and the same rectangular
pulse inverted (i.e., multiplied by -1) to represent the element -1. This is called a polar
nonreturn-to-zero line code. The problem with such simple codes is that they use bandwidth
ineffciently. Recall that the Fourier transform of the rectangular pulse in time is the sinc(f)
function in frequency , which dies away slowly as f increases. Thus, simple codes like the
nonreturn-to-zero are compact in time, but wide in frequency, limiting the number of
simultaneous nonoverlapping users in a given spectral band.
More generally, consider the four-level signaling ±1; ±3. This can be turned into an analog
signal for transmission by choosing a pulse shape p(t) (that is not necessarily rectangular and
not necessarily of duration T) and then transmitting
p(t - kT) if the kth symbol is 1
-p(t - kT) if the kth symbol is - 1
3p(t - kT) if the kth symbol is 3
-3p(t - kT) if the kth symbol is - 3
Thus, the sequence is translated into an analog waveform by initiating a scaled pulse at the
symbol time kT, where the amplitude scaling is proportional to the associated symbol value.
Ideally, the pulse would be chosen so that

the value of the message at time k does not interfere with the value of the message at other
sample times (the pulse shape causes no intersymbol interference),

the transmission makes efficient use of bandwidth, and

the system is resilient to noise.
Unfortunately, these three requirements cannot all be optimized simultaneously, and so the
design of the pulse shape must consider carefully the tradeoff that are needed.
To see concretely how pulse shaping works, let's pick a simple nonrectangular shape and
proceed without worrying about optimality. Let p(t) be the symmetrical blip shape shown in
the top part of Figure 2, and defined in pulseshape0.m by the hamming command. The text
string in str is changed into a 4-level signal, and then the complete transmitted waveform is
assembled by assigning an appropriately scaled pulse shape to each data value. The output
appears in the bottom of Figure 2. Looking at this closely, observe that the first letter T is
represented by the four values -1 -1 -1 -3, which corresponds exactly to the first four negative
blips, three small and one large.
3
Communications II
Experiment V
Figure 2: The process of pulse shaping replaces each symbol of the alphabet (in this case,
±1, ±3) with an analog pulse (in this case, the short blip function shown in the top panel).
The program pulseshape0.m represents the “continuous-time” or analog signal by
oversampling both the data sequence and the pulse shape by a factor of M. This technique was
discussed in Section 2.1 above, where an “analog” sine wave sine100hzsamp.m was
represented digitally at two sampling intervals, a slow digital interval Ts and a faster rate
(shorter interval) Ts=M representing the underlying analog signal. The pulse shaping itself is
carried out by the filter command which convolves the pulse shape with the data sequence.
% pulseshape0.m: applying a pulse shape
str='Transmit this text string';
m=letters2pam(str); N=length(m);
M=10; mup=zeros(1,N*M); mup(1:M:end)=m;
ps=hamming(M);
x=filter(ps,1,mup);
to a text string
% message to be transmitted
% 4-level signal of length N
% oversample by M
% blip pulse of width M
% convolve pulse shape with data
t=1/M:1/M:length(x)/M;
subplot(2,1,1), plot(0:0.1:0.9,ps)
xlabel('The pulse shape')
subplot(2,1,2), plot(t,x)
xlabel('The waveform representing "Transmit this text"')
4
Communications II
Experiment V
3. EXPERIMENT

Copy exp5 folder to your computer, start Matlab and change the directory of
Matlab to exp5.
3.1 sine100hz.m







Type “sine100hz” in Matlab command window and make sure you observe
first 10 periods of the sine wave. Copy your result into Fig 3.
Type plot(w(1:100)) and verify that first 100 samples is a complete period.
Copy your result into Fig 4.
Change Ts to Ts=1/5000. Copy the output of your result into Fig 5.
Determine how many samples there are in one period. Plot one period of the
signal and copy your result into Fig 6.
Repeat the above procedure for Ts=1/1000. Copy your results into Fig 7 and
Fig 8
Repeat the above procedure for Ts=1/500. Copy your result into Fig 9 and Fig
10.
For what value of Ts there are 20 samples in one period? Repeat the above for
this value of Ts and copy your result into Fig 11 and Fig 12.
Answer: Ts=

Note that for f=100 Hz Nyquist rate fs is 200 Hz which corresponds to
Ts=1/200. In above we make sure that the sampling rate is higher than the
Nyquist rate.
3.2 sine100hzsamp.m






Type “sine100hzsamp” in Matlab command window and make sure you can
observe Figure 1.
For the signal w, Ts=1/10000 and to produce the signal wk we take every
ss=10 samples of the original signal therefore effective sampling time for ws
becomes ss*Ts=1/1000. Using plotspec plot the spectrum of ws. Copy your
result into Fig 13
Change ss=11 and produce a figure as in Figure 1. Copy your result into Fig
14.
Repeat the above for ss=15. Copy your result into Fig 15.
Repeat the above for ss=30. Copy your result into Fig 16.
Repeat the above for ss=200. Copy your result into Fig 17.
3.3 pulseshape0.m
 Type “pulseshape0” in Matlab command window and make sure you can
observe Figure 2.
 In pulseshpe0.m each symbol duration (and pulse duration) is T=1 second.
Each symbol is transmitted with analog signal p(t) however in order to
represent the analog signal in MATLAB during each pulse duration M=10
samples are taken. To fınd the spectrum of x type plotspec(x,1/M) and copy
your result into Fig. 18. What is the approximate bandwidth of x?
5
Communications II
Experiment V
Answer:


square wave: In pulseshape0.m make ps=ones(M,1) to change the pulse
shaping filter to a square wave. Run the program and copy the output as in Fig
2 into Fig 19.
Plot the spectrum by typing plotspec(x,1/M). Copy your result into Fig. 20.
What is the approximate bandwidth of x? Is this larger or smaller than the
result above.
Answer:




Answer: T:
r:



In pulseshape0 change ps to hamming pulse back.
Change str to have only first two letters: str='Tr';
type m=letters2pam(str)
What are the 4 symbols representing letter T and letter r
Run pulseshape0
Type grid on
Copy your result into Fig. 21. Can you observe the 8 symbols representing Tr
6
Communications II
Experiment V
4. RECORDS
Figure 3
Figure 4
Figure 5
7
Communications II
Experiment V
Figure 6
Figure 7
Figure 8
8
Communications II
Experiment V
Figure 9
Figure 10
Figure 11
9
Communications II
Experiment V
Figure 12
Figure 13
Figure 14
10
Communications II
Experiment V
Figure 15
Figure 16
Figure 17
11
Communications II
Experiment V
Figure 18
Figure 19
Figure 20
12
Communications II
Experiment V
Figure 21
13
Download