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

📄 agc.m

📁 《FPGA嵌入式应用系统开发典型实例》-书的光盘资料
💻 M
字号:
%本程序仿真AGC的工作过程;
clc;
clear;
framelength = 200;
datai=randsrc(1,framelength,[-1 1]);
dataq=randsrc(1,framelength,[-1 1]);
stuff=zeros(1,15);
for i=1:length(datai)
    x((i-1)*16+1)=datai(i);
    x=[x stuff];
end;
data_i=x;

for i=1:length(dataq)
    y((i-1)*16+1)=dataq(i);
    y=[y stuff];
end;
data_q=y;

%平方根升余弦滤波器的系数
R=1.0;
n_T=[-4 4];
rate=16;
T=1;
b = rcosfir(R,n_T,rate,T,'sqrt');
wave_i=filter2(b,data_i,'same');
wave_q=filter2(b,data_q,'same');
I=filter2(b,wave_i,'same');
Q=filter2(b,wave_q,'same');
idecision =[I(1:length(I)/2) I(length(I)/2+1:length(I))*5] + 0.1*randn(1,rate*framelength);
qdecision =[Q(1:length(Q)/2) Q(length(Q)/2+1:length(Q))*5] + 0.1*randn(1,rate*framelength);
threshold = 20;
upperlimit = 15;
lowerlimit = 0;
sum(1) = 1;
limited(1) = 1;
gain(1) = 1;
iscaled(1) = idecision(1);
qscaled(1) = idecision(1);
iabs(1) = abs(iscaled(1));
qabs(1) = abs(qscaled(1));
hi_lo(1) = 0;
error(1) = 0;

for i = 2:rate*framelength
    iscaled(i) = gain(i-1) * idecision(i);
    qscaled(i) = gain(i-1) * qdecision(i);
    iabs(i) = abs(iscaled(i));
    qabs(i) = abs(qscaled(i));
    
    if iabs(i) > qabs(i)
        amplitude(i) = iabs(i) + 0.5*qabs(i);
    else
        amplitude(i) = qabs(i) + 0.5*iabs(i);
    end;
    
    if amplitude(i) > threshold
        error(i) = -0.05;
    else
        error(i) = 0.05;
    end;

    sum(i) = limited(i-1) + error(i);
    if sum(i) > upperlimit
        limited(i) = upperlimit;
    elseif sum(i) < lowerlimit
        limited(i) = lowerlimit;
    else
        limited(i) = sum(i);
    end;
    gain(i) = limited(i-1);
end;

figure;
subplot(3,1,1);
plot(idecision);
title('原始信号');
subplot(3,1,2);
plot(iscaled);
title('增益控制后信号');
subplot(3,1,3);
plot(gain);
title('增益值');

⌨️ 快捷键说明

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