📄 pllmain.m
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Function: PLLmain.m
% Description: This simulation program is to genterate input parameters
% for PLL and process the results.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;close all; clc;
%********************** Parameters ***************************
Fs = 44.1*1e6; %Sampling rate
K_pd = 1; %Phase detector gain
K_vco = 2*pi*1e1; %VCO gain
tyofpd = 1; %Type of phase detector (1 = Multiplier; 2 = XOR)
f_vco = 1e3; %VCO center frequency
%f_in = f_vco + 10; %Frequency of input signal
f_in = 20000;
Am = 1;
Ac = 1;
Fc = f_in*1e9;
phase = 0;
M = 1;
N = 1;
%********************** Signal input *************************
%t = 0:1/Fs:2; %Simulation time
t = 0 : 0.01 : 2;
x = Am * sin(2*pi*f_in*t);
%sig_in = sin(2*pi*f_in*t); %Generate input signal
% sig_in = square(2*pi*f_in*t);
%fmod(msg, fc, Fs, Ac, kf)
y = FMOD(x, Fc, Fs, Ac, 0.5, 0); %FM Modulated signal with phase distortion
z = FMOD(x, Fc, Fs, Ac, 0.5, 1); %FM Modulated signal without phase distortion
figure(1)
plot(t, y);
xlabel('TIME IN SECONDS')
ylabel('AMPLITUDE')
title('FM MODULATED SIGNAL')
hold on
plot(t, z, 'r');
xlabel('TIME IN SECONDS')
ylabel('AMPLITUDE')
title('FM MODULATED SIGNAL')
sig_in = y;
%S = exp(j*2*pi*Fc/Fs*t); % complex sinusoid
%phase_noise_freq = [ 1e3, 10e3, 100e3, 1e6, 10e6 ]; % Offset From Carrier
%phase_noise_power = [ -84, -100, -96, -109, -122 ]; % Phase Noise power
%S1 = add_phase_noise( S, Fs, phase_noise_freq, phase_noise_power ); %S1 = add_phase_noise( S, Fs, phase_noise_freq, phase_noise_power );
%sig_in = y .* real(S1); % Adding Noise to FM Modulated signal
%figure(2)
%plot(t,sig_in);
%xlabel('TIME IN SECONDS')
%ylabel('AMPLITUDE')
%title('FM MODULATED SIGNAL WITH RANDOM PHASE NOISE')
%********************** Loop filter design *************************
%Parameter design
w_vco = 2*pi*f_vco;
w_3db = 0.05*w_vco;
w_T = w_3db/1.33;
w2 = w_T/sqrt(10);
w3 = w_T*sqrt(10);
T1 = (K_vco*K_pd/(sqrt(10)*w2^2));
T2 = 1/w2;
T3 = 1/w3;
num = [T2 1]; %Numerator of loop filter transfer function
den = [T1*T3 T1 0]; %Denominator of loop filter transfer function
%********************** PLL function part *************************
[vco_out,pd_out,lf_out,phi_vco] = PLL(sig_in,Fs,num,den,K_vco,K_pd,tyofpd,f_vco,M,N);
%[vco_out,pd_out,lf_out,phi_vco] = PLL(sig_in,Fs,num,den,K_vco,K_pd,tyofpd,f_vco,M,N);
%********************** Postprocesser part ***************************
figure(3);
plot(t,pd_out(1:length(t)));
xlabel('TIME IN SECONDS')
ylabel('AMPLITUDE')
title('SINE RESPONSE OF SECOND ORDER CLOSED LOOP TRANSMITTANCE OF PHASE DETECTOR OUTPUT')
figure(4);
plot(t,lf_out(1:length(t)));
xlabel('TIME IN SECONDS')
ylabel('AMPLITUDE')
title('SINE RESPONSE OF SECOND ORDER CLOSED LOOP TRANSMITTANCE OF LOOP FILTER OUTPUT')
figure(5);
plot(t,vco_out(1:length(t)));
xlabel('TIME IN SECONDS')
ylabel('AMPLITUDE')
title('SINE RESPONSE OF SECOND ORDER CLOSED LOOP TRANSMITTANCE OF VCO SIGNAL OUTPUT')
grid on
hold on;
%figure
%plot(t,sig_in,'r');
%hold off;
figure(6);
%plot(t,vco_out(1:length(t)) + sig_in);
plot(t, sig_in);
xlabel('TIME IN SECONDS')
ylabel('AMPLITUDE')
title('SINE RESPONSE OF SECOND ORDER CLOSED LOOP TRANSMITTANCE OF VCO OUTPUT & INPUT SIGNAL')
% subplot(1,2,1),plot(t,lf_out(1:length(t))),
% xlabel('t (s)'),ylabel('Output signal of loop filter')
% subplot(1,2,2),plot(t,vco_out(1:length(t)) + sig_in),
% xlabel('t (s)'),ylabel('Combination of input and output signal')
%%%%%%%%%%%%%%%%%%%%%% end of file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -