Sei sulla pagina 1di 8

Representing Analog Signals

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.

AWGN Add white Gaussian noise to a signal.


Y = AWGN(X,SNR) adds white Gaussian noise to X. The SNR is in dB.
The power of X is assumed to be 0 dBW. If X is complex, then
AWGN adds complex noise.

Y = AWGN(X,SNR,SIGPOWER) when SIGPOWER is numeric, it represents


the signal power in dBW. When SIGPOWER is 'measured', AWGN measures
the signal power before adding noise.

Y = AWGN(X,SNR,SIGPOWER,STATE) resets the state of RANDN to STATE.

Y = AWGN(..., POWERTYPE) specifies the units of SNR and SIGPOWER.


POWERTYPE can be 'db' or 'linear'. If POWERTYPE is 'db', then SNR
is measured in dB and SIGPOWER is measured in dBW. If POWERTYPE is
'linear', then SNR is measured as a ratio and SIGPOWER is measured
in Watts.

Example: To specify the power of X to be 0 dBW and add noise to produce


an SNR of 10dB, use:
X = sqrt(2)*sin(0:pi/8:6*pi);
Y = AWGN(X,10,0);

Example: To specify the power of X to be 0 dBW, set RANDN to the 1234th


state and add noise to produce an SNR of 10dB, use:
X = sqrt(2)*sin(0:pi/8:6*pi);
Y = AWGN(X,10,0,1234);

Example: To specify the power of X to be 3 Watts and add noise to


produce a linear SNR of 4, use:
X = sqrt(2)*sin(0:pi/8:6*pi);
Y = AWGN(X,4,3,'linear');

Example: To cause AWGN to measure the power of X, set RANDN to the


1234th state and add noise to produce a linear SNR of 4, use:
X = sqrt(2)*sin(0:pi/8:6*pi);
Y = AWGN(X,4,'measured',1234,'linear')

PMMOD Phase modulation.


Y = PMMOD(X,Fc,Fs,PHASEDEV) uses the message signal X to phase
modulate the carrier frequency Fc (Hz). Fc and X have sample frequency
Fs (Hz), where Fs >= 2*Fc. PHASEDEV (radians) is the frequency deviation of
the modulated signal.

Y = PMMOD(X,Fc,Fs,PHASEDEV,INI_PHASE) specifies the initial phase


(radians) of the modulated signal.

See also pmdemod, fmmod, fmdemod.

Reference page in Help browser


doc pmmod

LEGEND Display legend.


LEGEND(string1,string2,string3, ...) puts a legend on the current plot
using the specified strings as labels. LEGEND works on line graphs,
bar graphs, pie graphs, ribbon plots, etc. You can label any
solid-colored patch or surface object. The fontsize and fontname for
the legend strings matches the axes fontsize and fontname.

LEGEND(H,string1,string2,string3, ...) puts a legend on the plot


containing the handles in the vector H using the specified strings as
labels for the corresponding handles.

LEGEND(M), where M is a string matrix or cell array of strings, and


LEGEND(H,M) where H is a vector of handles to lines and patches also
works.

LEGEND(AX,...) puts a legend on the axes with handle AX.

LEGEND OFF removes the legend from the current axes and deletes
the legend handle.
LEGEND(AX,'off') removes the legend from the axis AX.

LEGEND TOGGLE toggles legend on or off. If no legend exists for the


current axes one is created using default strings. The default
string for an object is the value of the DisplayName property
if it is non-empty and otherwise it is a string of the form
'data1','data2', etc.
LEGEND(AX,'toggle') toggles legend for axes AX

LEGEND HIDE makes legend invisible.


LEGEND(AX,'hide') makes legend on axes AX invisible.
LEGEND SHOW makes legend visible. If no legend exists for the
current axes one is created using default strings.
LEGEND(AX,'show') makes legend on axes AX visible.

LEGEND BOXOFF makes legend background box invisible when legend is


visible.
LEGEND(AX,'boxoff') for axes AX makes legend background box invisible when
legend is visible.
LEGEND BOXON makes legend background box visible when legend is visible.
LEGEND(AX,'boxon') for axes AX making legend background box visible when
legend is visible.

LEGH = LEGEND returns the handle to legend on the current axes or


empty if none exists.

LEGEND with no arguments refreshes all the legends in the current


figure (if any). LEGEND(LEGH) refreshes the specified legend.

LEGEND(...,'Location',LOC) adds a legend in the specified


location, LOC, with respect to the axes. LOC may be either a
1x4 position vector or one of the following strings:
'North' inside plot box near top
'South' inside bottom
'East' inside right
'West' inside left
'NorthEast' inside top right (default)
'NorthWest inside top left
'SouthEast' inside bottom right
'SouthWest' inside bottom left
'NorthOutside' outside plot box near top
'SouthOutside' outside bottom
'EastOutside' outside right
'WestOutside' outside left
'NorthEastOutside' outside top right
'NorthWestOutside' outside top left
'SouthEastOutside' outside bottom right
'SouthWestOutside' outside bottom left
'Best' least conflict with data in plot
'BestOutside' least unused space outside plot

LEGEND(...,'Orientation',ORIENTATION) creates a legend with the


legend items arranged in the specified ORIENTATION. Allowed
values for ORIENTATION are 'vertical' (the default) and 'horizontal'.
[LEGH,OBJH,OUTH,OUTM] = LEGEND(...) returns a handle LEGH to the
legend axes; a vector OBJH containing handles for the text, lines,
and patches in the legend; a vector OUTH of handles to the
lines and patches in the plot; and a cell array OUTM containing
the text in the legend.

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')

b = bar(rand(10,5),'stacked'); colormap(summer); hold on


x = plot(1:10,5*rand(10,1),'marker','square','markersize',12,...
'markeredgecolor','y','markerfacecolor',[.6 0 .6],...
'linestyle','-','color','r','linewidth',2); hold off
legend([b,x],'Carrots','Peas','Peppers','Green Beans',...
'Cucumbers','Eggplant')

RANDINT Generate matrix of uniformly distributed random integers.


OUT = RANDINT generates a "0" or "1" with equal probability.

OUT = RANDINT(M) generates an M-by-M matrix of random binary numbers.


"0" and "1" occur with equal probability.

OUT = RANDINT(M,N) generates an M-by-N matrix of random binary numbers.


"0" and "1" occur with equal probability.

OUT = RANDINT(M,N,RANGE) generates an M-by-N matrix of random integers.

RANGE can be either a scalar or a two-element vector:


Scalar : If RANGE is a positive integer, then the output integer
range is [0, RANGE-1]. If RANGE is a negative integer,
then the output integer range is [RANGE+1, 0].
Vector : If RANGE is a two-element vector, then the output
integer range is [RANGE(1), RANGE(2)].

OUT = RANDINT(M,N,RANGE,STATE) resets the state of RAND to STATE.

Examples:
» out = randint(2,3) » out = randint(2,3,4)
out = out =
0 0 1 1 0 3
1 0 1 2 3 1

» out = randint(2,3,-4) » out = randint(2,3,[-2 2])


out = out =
-3 -1 -2 -1 0 -2
-2 0 0 1 2 1

See also rand, randsrc, randerr.

Reference page in Help browser


doc randint

MODULATE Signal modulation for communications simulations.


Y = MODULATE(X,Fc,Fs,METHOD,OPT) modulates the message signal X with a
carrier frequency Fc and sampling frequency Fs, using the modulation
scheme in METHOD. OPT is an extra sometimes optional parameter whose
purpose depends on the modulation scheme you choose.

Fs must satisfy Fs > 2*Fc + BW, where BW is the bandwidth of the


modulated signal.

METHOD MODULATION SCHEME


'am', Amplitude modulation, double side-band, suppressed carrier
'amdsb-sc' OPT not used.
'amdsb-tc' Amplitude modulation, double side-band, transmitted carrier
OPT is a scalar which is subtracted from X prior to
multiplication by the carrier cosine. It defaults to
min(min(X)) so the offset message signal is positive and
has a minimum value of zero.
'amssb' Amplitude modulation, single side-band
OPT not used.
'fm' Frequency modulation
OPT is a scalar which specifies the constant of frequency
modulation kf. kf = (Fc/Fs)*2*pi/max(max(abs(X))) by
default for a maximum frequency excursion of Fc Hertz.
'pm' Phase modulation
OPT is a scalar which specifies the constant of phase
modulation kp. kp = pi/max(max(abs(x))) by default for a
maximum phase excursion of +/-pi radians.
'pwm' Pulse width modulation
If you let OPT = 'centered', the pulses are centered on the
carrier period rather than being "left justified".
'ppm' Pulse position modulation
OPT is a scalar between 0 and 1 which specifies the pulse
width in fractions of the carrier period. It defaults to .1.
'qam' Quadrature amplitude modulation
OPT is a matrix the same size as X which is modulated in
quadrature with X.

If X is a matrix, its columns are modulated.


[Y,T] = MODULATE(...) returns a time vector the same length as Y.

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

Reference page in Help browser


doc modulate

DEMOD Signal demodulation for communications simulations.


X = DEMOD(Y,Fc,Fs,METHOD,OPT) demodulates the carrier signal Y with a
carrier frequency Fc and sampling frequency Fs, using the demodulation
scheme in METHOD. OPT is an extra, sometimes optional, parameter whose
purpose depends on the demodulation scheme you choose.

Fs must satisfy Fs > 2*Fc + BW, where BW is the bandwidth of the


modulated signal.

METHOD DEMODULATION SCHEME


'am', Amplitude demodulation, double side-band, suppressed carrier
'amdsb-sc' OPT not used.
'amdsb-tc' Amplitude demodulation, double side-band,transmitted carrier
OPT is a scalar which is subtracted from the decoded message
signal. It defaults to zero.
'amssb' Amplitude demodulation, single side-band
OPT not used.
'fm' Frequency demodulation
OPT is a scalar which specifies the constant of frequency
modulation kf, which defaults to 1.
'pm' Phase demodulation
OPT is a scalar which specifies the constant of phase
modulation kp, which defaults to 1.
'pwm' Pulse width demodulation
By setting OPT = 'centered' you tell DEMOD that the pulses
are centered on the carrier period rather than being
"left justified".
'ppm' Pulse position demodulation
OPT is not used.
'qam' Quadrature amplitude demodulation
For QAM signals, use [X1,X2] = DEMOD(Y,Fc,Fs,'qam')

If Y is a matrix, its columns are demodulated.

See also modulate in the Signal Processing Toolbox, and pamdemod,


qamdemod, genqamdemod, fskdemod, psmdemod, mskdemod in the
Communications Toolbox.

Reference page in Help browser

Potrebbero piacerti anche