0% found this document useful (0 votes)
569 views9 pages

Test.m Fmod.m SPLL.M: %how To Use It: Simply Copy The 3 Files To A Matlab Path Directory and Type "Test". The Test.m

This document describes using a phase-locked loop (PLL) as an FM demodulator. It provides code for an FM modulator that modulates a carrier signal with an audio message signal. It then uses a software PLL (SPLL) to recover the original audio message signal from the modulated carrier. The document tests the demodulation by modulating a 500 Hz signal onto a 10 kHz carrier, then recovering the 500 Hz signal using the SPLL. Plots of the modulated carrier, PLL outputs, and recovered signal are presented to demonstrate the PLL functioning as an FM demodulator.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
569 views9 pages

Test.m Fmod.m SPLL.M: %how To Use It: Simply Copy The 3 Files To A Matlab Path Directory and Type "Test". The Test.m

This document describes using a phase-locked loop (PLL) as an FM demodulator. It provides code for an FM modulator that modulates a carrier signal with an audio message signal. It then uses a software PLL (SPLL) to recover the original audio message signal from the modulated carrier. The document tests the demodulation by modulating a 500 Hz signal onto a 10 kHz carrier, then recovering the 500 Hz signal using the SPLL. Plots of the modulated carrier, PLL outputs, and recovered signal are presented to demonstrate the PLL functioning as an FM demodulator.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

PLL as FM Demodulator

%test.m
%$fmod.m
%spll.m
%How to use it: Simply copy the 3 files to a Matlab path directory and type "test". The test.m
%file produces a 500 hz signal which is modulated onto a 10 kHz carrier with a call to fmod.m.
%It then recovers the 500 Hz signal using a call to spll.m. The output of the LPF is the recovered
%signal.
%*************************************************************************%
% Filename
TEST.M
%
%
This file tests a phase-locked loop by creating an FM signal %
%
and demodulation the FM signal using an SPLL.
%
%
%
% Date
2/4/06
%
% Author Paul Sand, PE-I
%
% References
%
%
R. Best
%
%*************************************************************************%
clear all;
N = 5000;
Fs = 40000;
Ts = 1/Fs;
fc = 10000;
t = [0:Ts:(N*Ts)- Ts];

%
%
%
%
%

total # of samples
sampling rate
sampling interval
carrier frequency
time index for samples

%
%
%
%
%

% Initialize the variables.


PD_GAIN = 2.0;
LF_GAIN0 = 1.0;
LF_GAIN1 = 1.0;
VCO_FC
= fc;
VCO_GAIN = 50000;
VCO_AMP = 1.0;

%
%
%
%
%
%

Phase detector gain


LPF gain
not really needed
VCO center frequency
(rad/sec)/volts
amplitude of VCO freq

%
%
%
%
%
%
%

% FM modulate a test signal. When choosing a modulating frequency one has %


% to make sure the LPF in the PLL can handle it. To use a higher frequency%
% one may have to redesign the LPF. A simple task.
%
TestFreq = 500;
% Modulating frequency
%
msg = sin(2*pi*TestFreq*t);
% compute vector
%
fmmsg = fmod(msg, fc, Fs, 1.0, 0.05);
% modulate the carrier
%
% Recover the 500 Hz signal using an SPLL.
%
[pd_out,lfsum,lf_out,vco_phase,vco_out] =
spll(fmmsg,Fs,PD_GAIN,LF_GAIN0,LF_GAIN1,VCO_FC,VCO_GAIN,VCO_AMP);
%-------------------------------------------------------------------------%

% PLOTS
startplot = 1;
endplot = 300;

figure(101);
subplot(2,1,1);
plot(t(startplot:endplot), fmmsg(startplot:endplot));
title('FM 10 kHz carrier modulated with a 500 Hz message signal');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid;
subplot(2,1,2);
plot(t(startplot:endplot), lf_out(startplot:endplot));
title('PLL Loop filter output');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid;
%-------------------------------------------------------------------------%
figure(102)
subplot(2,1,1);
plot(t(startplot:endplot), fmmsg(startplot:endplot));
title('FM 10 kHz carrier modulated with a 500 Hz message signal');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid;
subplot(2,1,2);
plot(t(startplot:endplot), pd_out(startplot:endplot));
title('PLL Phase Detector output');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid;
%-------------------------------------------------------------------------%
figure(103)
subplot(2,1,1);
plot(t(startplot:endplot), fmmsg(startplot:endplot));
title('FM output');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid;
subplot(2,1,2);
plot(t(startplot:endplot), vco_out(startplot:endplot), 'r');
title('VCO output (PLL tracking the input signal)');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid;
%-------------------------------------------------------------------------%
% Get rid of DC and normalize
lf_out = lf_out - mean(lf_out);
yn = lf_out/max(lf_out);
%soundsc(yn, Fs);

% elimninate any DC bias


% normalize & return

%
%

figure(104)
plot(t(startplot:endplot), lfsum(startplot:endplot), 'r');
title('PLL Integrator output');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid;
%-------------------------------------------------------------------------%

function [outfm] = fmod(msg, fc, fs, Ac, kf)


% FMOD()
- This function performs frequency modulation, FM. The
%
%
integration of the message signal is perform here.
%
%
%
%
t
%
%
Equation:
s(t) = Ac*cos(wc*t + 2pi*kf * SUM m(t) )
%
%
0
%
% msg - message signal vector (see note
%
% fc - carrier frequency
%
% fs - sampling rate for digitizing
%
% Ac - amplitude of carrier
%
% kf - modulation index
%
%
%
% Note: If the message is sampled at a lower frequency, say 8 kHz, it
%
%
must be interpolated to the sampling rate supplied here before %
%
calling this function.
%
%-------------------------------------------------------------------------%
%*************************************************************************%
% Filename FMOD.M
%
%
%
% Date
1/8/06
%
% Author
PWS
%
%*************************************************************************%
t = 0:1/fs:(length(msg)-1)/fs;
% number of samples
%
if( nargin < 5)
kf = (fc/fs) * (2*pi)/(max(max(abs(msg))));
end;

%modulation index %

outfm = Ac * cos(2*pi*fc*t + 2*pi*kf * cumsum(msg));

function [pd_out,lfvect,uf,vco_phase, vco_out] = spll(sigin, Fs,


PD_GAIN,lf_Gain0,lf_Gain1,vco_fc,VCO_GAIN,VCO_AMP)
%
% SPLL() - Implements a software phase-locked loop.
%
% Inputs:
%
sigin
- signal input vector
%
Fs
- sampling frequency
%
PD_GAIN - gain of the phase detector Volts/rad
%
lf_Gain0 - gain of the Direct Path of the loop filter
%
lf_Gain1 - gain of the Integral Path of the loop filter
%
(set to 1.0 in test program. Not really needed)

%
%
%
%
%
%
%
%
%
%

%
vco_fc
- center frequency of the vco
%
%
VCO_GAIN - gain of the VCO in rad/(Volts-sec)
%
%
VCO_AMP - amplitude of the VCO
%
%
%
% Outputs:
%
%
pd_out
- output of the phase detector
%
%
intvect
- output of the integrator in vector format
%
%
loop_out - output of the loop filter
%
%
vco_phase - VCO phase history
%
%
vco_out
- output of the VCO
%
%-------------------------------------------------------------------------%
Ts = 1/Fs;
% sampling period
%
N = length(sigin);
% number of samples
%
t = [0:Ts:(N*Ts)-Ts];
% time index for samples
%
pd_out = zeros(N,1);
% phase detector output
%
vco_phase = zeros(N,1);
% VCO output
%
uf = zeros(1,N);
lfvect = zeros(1,N);
% The low pass filter used in this phase-locked loop is a Butterworth
% 1st order IIR filter. This filter was designed using Matlab's FDATOOL.
% The coefficients are: Fs = 40 kHz, Fcutoff = 1000 Hz. Pole = a1 and
% a Zero = -1.
b0 = 0.0729596572;
b1 = 0.0729596572;
a1 = -0.8540806854;

%
%
%
%

% MAIN LOOP
vco_out(1) = VCO_AMP * cos(vco_phase(1));
% initial VCO output
pd_out(1) = PD_GAIN * sigin(1) * vco_out(1);
% initial phase det out
uf(1)
= lf_Gain0*(b0*pd_out(1) + b1*0 - a1*0);
lfsum = 0;

%
%
%

for n = 2:N
% There are various ways to compute the next VCO phase. One way is to
% create a time index nT such that we compute w*(nT), i.e. w*0T, w*1T,
% w*2T, etc. Another way is to compute w*T and just add that value
% each time keeping a running total. The end result is the same.
% The TOTAL phase is a running summation of both the frequency term &
% the phase term.
% Another issue for the successful operation of a PLL is the VCO_GAIN.
% This gain must account for the sampling time interval. Because this
% time multiplies the output of the LFP the numerical value can be
% very small. For example, at 40 kHz sampling, T = 1/40000 = 25e-6. If
% the VCO_GAIN is not large enough this phase term will have no
% noticable affect. A good start is to make the VCO_GAIN equal to the
% sampling frequency.
%
wc*t
k*uf*T
vco_phase_change = (2*pi*vco_fc*Ts) + VCO_GAIN*uf(n-1)*Ts;
vco_phase(n)
= vco_phase(n-1) + vco_phase_change;
% To insure that the phase term does not grow to infinity addition is
% performed modulo 2*pi.
if(vco_phase(n) > 2*pi)
vco_phase(n) = vco_phase(n) - 2*pi;
end;
vco_out(n) = VCO_AMP * cos(vco_phase(n));

%
%
%
%
%
%
%
%
%
%
%
%
%
%

%
%

% PHASE DETECTOR
pd_out(n) = PD_GAIN * (sigin(n) * vco_out(n));

% LOW PASS FILTER DIFFERENCE EQ: y(n) = b0*x(n)+b1*x(n-1) - a1*y(n-1) %


uf(n) = lf_Gain0*(b0*pd_out(n) + b1*pd_out(n-1) - a1*uf(n-1));
uf(n) = uf(n) * lf_Gain1;
% INTEGRATOR. This keeps a running summation of the ouput of the LPF.
lfsum = lfsum + uf(n);
lfvect(n) = lfsum;
end;

% !!! FOR TESTING !!!

%
%

[Y,Fs,NBITS,OPTS] = mp3read('jem.mp3');
snd=Y(1:200000);
t = 0:1/Fs:(length(snd)-1)/Fs;
plot(t,snd);
%Modultaion
Ac=1;
fc=68000;
wc=2*pi*fc;
kf=1000;
spc=8;
R = (fc*spc)/Fs;
outfm = Ac * cos(wc.*t + 2 * pi * kf * cumsum(snd));
%noise
%demodulation
z = ademod(FMmodcarrier,fc,fc*spc,'fm'); % PLL -based FM demodulation
dd=decimate(z,round(R));

15. PLL AS FM DEMODULATOR


AIM
To implement PLL as FM Demodulator

EQUIPMENT REQUIRED
Power Supply
Dual-Trace Oscilloscope
Digital Multimeter
Function Generator
Frequency Counter
Bread Board
CIRCUIT DIAGRAMS
FM Modulator:

FM Demodulator:

PROCEDURE:
Part A: FM Modulator using PLL

1. Set the function generator to supply a 3VP-P square wave at 3kHz with 7V dc offset.
2. Disable the ac o/p from the function generator to get 7V dc only.
3. Build the FM modulator circuit in the figure, and connect the function generator to pin 5 of the
IC.
4. Measure the frequency of the generated carrier o/p at pin 3.
Fcarrier(kHz) =
5. Enable the ac o/p of the function generator.
6. Connect ch1 to the i/p at pin 5 and use it for trigger and record both the i/p and the modulator
o/p.
Note: ch2 may not be stable, try adjusting the hold off control on the oscilloscope for best
display.
7. From the results of experiment 3, calculate the frequency of the o/p for both levels of the
square signal. Note: The o/p is actually an FSK signal.
fLOW (KHz) =

fLOW (KHz) =

8. Switch the function generator to a sine wave; draw a sketch of the modulator o/p.

f c
fm

9. Calculate the modulation index () for this signal using the formula:
10. Assuming the output of the VCO to be sinusoidal (not square), use Carsons rule to determine
the bandwidth of the FM output.
BW 2f c 2 f m 2( 1) f m
11. Do not disassemble the circuit.
Part B: FM Demodulator using PLL

1. Build the FM demodulator circuit in figure, on another area of the breadboard.


2. Connect the o/p of the modulator circuit to the i/p of the demodulator circuit.
3. Connect ch1 to the o/p of the demodulator, and ch2 to the modulating signal from the function
generator, and use it as the trigger source.

4. Adjust the 2k pot until the o/p signal best matches the modulating signal. Measure the voltage
at pin 8 of the LM565.
V (volts) =
5. Plot both the original message and demodulated signal.
6. Remove the 1nF capacitor from the circuit; describe what happens to the o/p.
8. Change the message signal to a square wave and observe the o/p.
9. Reconnect the 1nF capacitor, what is its effect?
10. What is the purpose of the 1nF capacitor?

OBSERVATIONS:

MODEL WAVEFORMS:

RESULT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy