📄 wenti.m
字号:
clc;close all;clear all;Fc = 2100; % Input Reference signal frequencyF0 = 2000; % Center Frequency of NCOFs = 40000 ;% Sampling freqencyTs = 1/Fs; % Sampling durationt = 0:Ts:150/Fc; % Vector of time samplessigI = cos(2*pi*Fc*t+pi);sigQ = sin(2*pi*Fc*t+pi);% Calculation of PLL parameterszeta = 0.707; % Damping factor%Wl = 1*pi; % Lock range defined according to expectedWl = 800*pi; % Lock range defined according to expected% input characteristicsWn = Wl/2/zeta ;% Natural frequency calculated from lock range%Wn = 80*pi % Natural frequency calculated from lock rangeKd = 1; % Phase detector gainKo = 1; % Loop filter gain% Loop filter constants and lead-lag gain constants calculatedC1=((8*zeta*Wn*Ts)/(4+4*zeta*Wn*Ts+Wn*Wn*Ts*Ts))/(Ko*Kd);C2=((4*Wn*Wn*Ts*Ts)/(4+4*zeta*Wn*Ts+Wn*Wn*Ts*Ts))/(Ko*Kd);% Initialization for first cycle of feedback loopphi = 0; % Output phase of the NCOtheta = 0; % Phase error of the two signalsUf=0; % Output signal of the loop filterthetaI = 0; % Error of in-phase signalthetaQ = 0; % Error in quadrature-phase signalF1 = 2*pi*F0; % Output frequency of NCOspll(1)=0; % General case phase lock loopfor n = 2:1:length(sigI)phi(n) = phi(n-1)+F1(n-1)*Ts; % Phase error from current cycle thetaI(n) = sigI(n)*cos(phi(n))+sigQ(n)*sin(phi(n));thetaQ(n) = sigI(n)*sin(phi(n))-sigQ(n)*cos(phi(n));% theta(n) = atan(-thetaQ(n)/thetaI(n));%theta(n) = thetaQ(n);theta(n) = thetaQ(n)*sign(thetaI(n));spll(n)=spll(n-1)+C2*theta(n);Uf(n) = C1*theta(n)+spll(n);F1(n) = 2*pi*(F0+Uf(n));end figure;plot(theta);figure;plot(Uf);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -