FM信号的锁相环解调matlab
时间: 2023-12-09 16:35:43 浏览: 60
以下是使用matlab进行FM信号的锁相环解调的代码和解释:
```matlab
% 设置采样频率
Fs=input('Enter the sampling frequency in Hertz > ');
% 生成调制信号
t=0:1/Fs:1-1/Fs;
fc=100; %载波频率
fm=10; %调制频率
m=2; %调制指数
x=cos(2*pi*fc*t+m*sin(2*pi*fm*t));
% 生成本振信号
f0=fc+10; %本振频率
y=cos(2*pi*f0*t);
% 设置锁相环参数
Kp=1; %比例增益
Ki=0.1; %积分增益
Kd=0.01; %微分增益
theta=0; %初始相位差
theta_hat=0; %初始估计相位差
theta_err=0; %初始相位误差
theta_err_int=0; %初始相位误差积分
theta_err_diff=0; %初始相位误差微分
theta_hat_vec=zeros(size(t)); %估计相位差向量
% 锁相环解调
for n=1:length(t)
% 相乘
z=x(n)*y(n);
% 相移
theta_hat_vec(n)=theta_hat;
y_hat=cos(2*pi*(f0+theta_hat)*t(n));
% 相减
theta_err=z*abs(y_hat);
% 积分
theta_err_int=theta_err_int+theta_err/Fs;
% 微分
theta_err_diff=(theta_err-theta_err_diff)*Fs;
% 计算估计相位差
theta_hat=theta_hat+Kp*theta_err+Ki*theta_err_int+Kd*theta_err_diff;
end
% 绘制结果
figure;
subplot(2,1,1);
plot(t,x);
xlabel('Time-Seconds');
ylabel('Amplitude');
title('Modulated Signal');
subplot(2,1,2);
plot(t,theta_hat_vec);
xlabel('Time-Seconds');
ylabel('Phase-Difference-Radians');
title('Phase-Locked Loop Output');
```
上述代码中,首先设置了采样频率Fs,并生成了一个调制信号x和一个本振信号y。然后设置了锁相环的参数Kp、Ki和Kd,以及初始相位差theta、估计相位差theta_hat、相位误差theta_err、相位误差积分theta_err_int和相位误差微分theta_err_diff。接着进行锁相环解调,计算估计相位差theta_hat,并将其存储在theta_hat_vec向量中。最后绘制了调制信号和相位差输出的图形。