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

📄 untitled1.m

📁 锁相环一阶环的设计的仿真。自动画出线性和非线性的仿真结果
💻 M
字号:
clear all
disp('')
disp('Accept the tentative values:')
disp('the first loop frequency is 5')
dtype = input('Enter y for yes or n for no > ','s');
if dtype == 'y' 
fdel = 5;
else
disp('')
fdel = input('Enter the loop frequency in Hertz > ');
end
G = input('Enter the loop gain >');
fs = input('Enter the sampling frequency in Hertz > '); %用户输入自定义采样频率
tstop = input('Enter tstop, the simulation runtime > ');%用户输入自定义模拟运行时间

npts = fs*tstop+1;               % number of simulation points仿真点数
t = (0:(npts-1))/fs;             % default time vector默认时间向量
nsettle = fix(npts/10);          % set nsettle time as 0.1*npts
tsettle = nsettle/fs;            % set tsettle
fin = [zeros(1,nsettle),fdel*ones(1,npts-nsettle)];
phin = [zeros(1,nsettle),2*pi*fdel*t(1:(npts-nsettle))];
w2c=0; w4c=0; phivco=0;
twopi=2*pi;						 % define 2*pi
twofs=2*fs;						 % define 2*fs
disp(' ')                        % insert blank line
phierror = zeros(1,npts);	  	 % initialize vector
fvco = zeros(1,npts);            % initialize vector
phierror1 = zeros(1,npts);	  	 % initialize vector
fvco1 = zeros(1,npts);           % initialize vector
for i = 1:npts
    s1=phin(i) - phivco;
    s2=sin(s1);
    s3=G*s2;
    s4 = G*s1;
    w1c = s3+w2c;
    w3c = s4+w4c;
    w2c = s3+w1c;
    sw4c = s4+w3c;
    phivco = w1c/twofs;
    phivco1 = w3c/twofs;
    phierror(i) = s1;
    sphierror1(i) = s1;
    fvco(i) = s3/twopi;
    fvco1(i) = s4/twopi;
end    
phierrn = phierror/pi;	
phierrn1 = phierror1/pi;
freqerror = fin-fvco;
linearfreqerror = fin-fvco1;
pp=0;
while pp == 0
    p = menu('Phase Lock Loop Postprocessor','Phase Plane Plot','Input Frequency and VCO Freqeuncy()','Exit Program');
    if p == 1
        plot(phierrn,freqerror,'r',phierrn,linearfreqerror,'k')         %红色为非线性模型,黑色为线性模型
        title('Phase Plane Plot')
        xlabel('Phase Error /Pi')
        ylabel('Frequency Error - Hertz')
        grid
        pause
    elseif p == 2
        plot(t,fin,'k',t,fvco,'r');grid
        title('Input Frequency and VCO Freqeuncy()')
        xlabel('Time - Seconds');ylabel('Frequency - Hertz');
        pause
    elseif p == 3
        pp = 1;
    end
end

⌨️ 快捷键说明

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