demod
Demodulation for communications simulation
Description
Examples
Frequency Modulation and Demodulation
Generate a 150 Hz sinusoid sampled at 8 kHz for 1 second. Embed the modulated signal in white Gaussian noise of variance 0.1².
fs = 8e3; t = 0:1/fs:1-1/fs; s = cos(2*pi*150*t) + randn(size(t))/10;
Frequency modulate the signal at a carrier frequency of 3 kHz using a modulation constant of 0.1.
fc = 3e3;
rx = modulate(s,fc,fs,"fm",0.1);
Frequency demodulate the signal using the same carrier frequency and modulation constant. Compute and plot power spectrum estimates for the transmitted, received, and demodulated signals.
y = demod(rx,fc,fs,"fm",0.1); pspectrum([s;rx;y]',fs,Leakage=0.85) legend(["Transmitted" "Received" "Demodulated"] ... + " signal",Location="best")
Input Arguments
y
— Modulated signal
real vector | real matrix
Modulated message signal, specified as a real vector or matrix. Except for the
methods pwm
and ppm
, y
is the
same size as x
.
fc
— Carrier frequency
real positive scalar
Carrier frequency used to modulate the message signal, specified as a real positive scalar.
fs
— Sample rate
real positive scalar
Sample rate, specified as a real positive scalar.
method
— Method of modulation used
'am'
(default) | 'amdsb-tc'
| 'amssb'
| 'fm'
| 'pm'
| 'pwm'
| 'ppm'
| 'qam'
Method of modulation used, specified as one of:
am
oramdsb-sc
— Amplitude demodulation, double sideband, suppressed carrier. Multipliesy
by a sinusoid of frequencyfc
and applies a fifth-order Butterworth lowpass filter usingfiltfilt
.x = y.*cos(2*pi*fc*t); [b,a] = butter(5,fc*2/fs); x = filtfilt(b,a,x);
amdsb-tc
— Amplitude demodulation, double sideband, transmitted carrier. Multipliesy
by a sinusoid of frequencyfc
and applies a fifth-order Butterworth lowpass filter usingfiltfilt
.x = y.*cos(2*pi*fc*t); [b,a] = butter(5,fc*2/fs); x = filtfilt(b,a,x);
If you specify
opt
,demod
subtracts scalaropt
fromx
. The default value foropt
is 0.amssb
— Amplitude demodulation, single sideband. Multipliesy
by a sinusoid of frequencyfc
and applies a fifth-order Butterworth lowpass filter usingfiltfilt
..x = y.*cos(2*pi*fc*t); [b,a] = butter(5,fc*2/fs); x = filtfilt(b,a,x);
fm
— Frequency demodulation. Demodulates the FM waveform by modulating the Hilbert transform ofy
by a complex exponential of frequency-fc
Hz and obtains the instantaneous frequency of the result..y=cos(2*pi*fc*t + opt*cumsum(x))
cumsum
is a rectangular approximation of the integral ofx
.modulate
usesopt
as the constant of frequency modulation. If you do not specify theopt
parameter,modulate
uses a default ofopt = (fc/fs)*2*pi/(max(max(x)))
so the maximum frequency excursion fromfc
isfc
Hz.pm
— Phase demodulation. Demodulates the PM waveform by modulating the Hilbert transform ofy
by a complex exponential of frequency-fc
Hz and obtains the instantaneous phase of the result.y=cos(2*pi*fc*t + opt*x)
modulate
usesopt
as the constant of phase modulation. If you do not specify theopt
parameter,modulate
uses a default ofopt = pi/(max(max(x)))
so the maximum phase excursion is π radians.pwm
— Pulse-width demodulation. Finds the pulse widths of a pulse-width modulated signaly
.demod
returns inx
a vector whose elements specify the width of each pulse in fractions of a period. The pulses iny
should start at the beginning of each carrier period, that is, they should be left justified.modulate(x,fc,fs,'pwm','centered')
yields pulses centered at the beginning of each period. The length ofy
islength(x)*fs/fc
.ppm
— Pulse-position demodulation. Finds the pulse positions of a pulse-position modulated signaly
. For correct demodulation, the pulses cannot overlap.x
is lengthlength(t)*fc/fs
.qam
— Quadrature amplitude demodulation.[x1,x2] = demod(y,fc,fs,'qam')
multipliesy
by a cosine and a sine of frequencyfc
and applies a fifth-order Butterworth lowpass filter usingfiltfilt
.x1 = y.*cos(2*pi*fc*t); x2 = y.*sin(2*pi*fc*t); [b,a] = butter(5,fc*2/fs); x1 = filtfilt(b,a,x1); x2 = filtfilt(b,a,x2);
The input argument
opt
must be the same size asy
.
opt
— Optional input for some methods
real vector
Optional input, specified for some methods. Refer to method
for
more details on how to use opt
.
Output Arguments
x
— Demodulated message signal
real vector | real matrix
Demodulated message signal, returned as a real vector or matrix.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Version History
Introduced before R2006aR2024a: demod
supports C/C++ code generation
The demod
function supports C/C++ code generation. You must
have MATLAB®
Coder™ to use this functionality.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)