⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.m

📁 PLL in Matlab for FM Demodulation
💻 M
字号:
%*************************************************************************%
% Filename   TEST.M                                                       %
%            This file tests a phase-locked loop by creating an FM signal %
%            and demodulation the FM signal using an SPLL.                %
%*************************************************************************%
clc;
clear all;

N  = 4000;                         % total # of samples     %
Fs = 40000;                        % sampling rate          %
Ts = 1/Fs;                         % sampling interval      %
fc = 70000;                        % carrier frequency      %
t = [0:Ts:(N*Ts)- Ts];             % time index for samples %

% Initialize the variables.                                               %
PD_GAIN  = 2.0;                    % Phase detector gain    %
LF_GAIN0 = 1.0;                    % LPF gain               %
LF_GAIN1 = 1.0;                    % not really needed      %
VCO_FC   = fc;                     % VCO center frequency   %
VCO_GAIN = 50000;                  % (rad/sec)/volts        %
VCO_AMP  = 1.0;                    % amplitude of VCO freq  %
phase = 0;

% 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         %
msg = square(2*pi*TestFreq*t);

[fmmsg, phase] = fmod(msg, fc, Fs, 1.0, 0.05, 0);% 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(1);
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(2)
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(3)
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;



%figure(3)
%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);                 % elimninate any DC bias  %
yn = lf_out/max(lf_out);                        % normalize & return  
%soundsc(yn, Fs);

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


figure(5)
subplot(2,1,1);
plot(t(startplot:endplot), msg(startplot:endplot));
title('Original Message Signal');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid;

subplot(2,1,2);
plot(t(startplot:endplot), lf_out(startplot:endplot), 'r');
title('Loop Filter output');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid;



figure(6)
plot(t,phase);
pause

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -