Digital Communications Matlab Programmes
Digital Communications Matlab Programmes
To modulate an analog signal using this toolbox, start with a real message signal and a sampling rate Fs
in hertz. Represent the signal using a vector x, the entries of which give the signal’s values in time
increments of 1/Fs. Alternatively, you can use a matrix to represent a multichannel signal, where each
column of the matrix represents one channel.For example, if t measures time in seconds, then the vector
x below is the result of sampling a sine wave 8000 times per second for 0.1 seconds. The vector y
represents the modulated signal.
Fs = 8000; % Sampling rate is 8000 samples per second.
Fc = 300; % Carrier frequency in Hz
t = [0:.1*Fs]'/Fs; % Sampling times for .1 second
x = sin(20*pi*t); % Representation of the signal
y = ammod(x,Fc,Fs); % Modulate x to produce y.
figure;
subplot(2,1,1); plot(t,x); % Plot x on top.
subplot(2,1,2); plot(t,y)% Plot y below.
As a multichannel example, the code below defines a two-channel signal in
which one channel is a sinusoid with zero initial phase and the second channel
is a sinusoid with an initial phase of pi/8.
Fs = 8000;
t = [0:.1*Fs]'/Fs;
x = [sin(20*pi*t), sin(20*pi*t+pi/8)];
Analog Modulation Example
This example illustrates the basic format of the analog modulation and demodulation functions.
Although the example uses phase modulation, most elements of this example apply to other analog
modulation techniques as well. The example samples an analog signal and modulates it. Then it
simulates an additive white Gaussian noise (AWGN) channel, demodulates the received signal, and
plots the original and demodulated signals.
% Prepare to sample a signal for two seconds,
% at a rate of 100 samples per second.
Fs = 100; % Sampling rate
t = [0:2*Fs+1]'/Fs; % Time points for sampling
% Create the signal, a sum of sinusoids.
x = sin(2*pi*t) + sin(4*pi*t);
Fc = 10; % Carrier frequency in modulation
phasedev = pi/2; % Phase deviation for phase modulation
y = pmmod(x,Fc,Fs,phasedev); % Modulate.
y = awgn(y,10,'measured',103); % Add noise.
z = pmdemod(y,Fc,Fs,phasedev); % Demodulate.
% Plot the original and recovered signals.
figure; plot(t,x,'k-',t,z,'g-');
legend('Original signal','Recovered signal');
Other examples using analog modulation functions appear in the reference
pages for ammod, amdemod, ssbdemod, and fmmod.
Examples of Digital Modulation and Demodulation
This section contains examples that illustrate how to use the digital modulation and demodulation
functions.
Computing the Symbol Error Rate
The example generates a random digital signal, modulates it, and adds noise. Then it creates a scatter
plot, demodulates the noisy signal, and computes the symbol error rate.
% Create a random digital message
M = 16; % Alphabet size
x = randint(5000,1,M);
% Use 16-QAM modulation to produce y.
y=modulate(modem.qammod(M),x);
% Transmit signal through an AWGN channel.
ynoisy = awgn(y,15,'measured');
% Create scatter plot from noisy data. scatterplot(ynoisy);
% Demodulate ynoisy to recover the message.
z=demodulate(modem.qamdemod(M),ynoisy;
% Check symbol error rate.
[num,rt]= symerr(x,z)
Your numerical results and plot might vary, because the example uses random numbers.
num =83 rt =0.0166
The scatter plot does not look exactly like a signal constellation. Where the signal constellation has 16
precisely located points, the noise causes the scatter plot to have a small cluster of points approximately
where each constellation point would be.
LEGEND OFF removes the legend from the current axes and deletes
the legend handle.
LEGEND(AX,'off') removes the legend from the axis AX.
Examples:
x = 0:.2:12;
plot(x,bessel(1,x),x,bessel(2,x),x,bessel(3,x));
legend('First','Second','Third');
legend('First','Second','Third','Location','NorthEastOutside')
Examples:
» out = randint(2,3) » out = randint(2,3,4)
out = out =
0 0 1 1 0 3
1 0 1 2 3 1
See also demod, vco in the Signal Processing Toolbox, and pamdemod,
qamdemod, genqamdemod, fskdemod, psmdemod, mskdemod in the
Communications Toolbox.
Overloaded functions or methods (ones with the same name in other directories)
help laurpoly/modulate.m