改写代码% 生成窄带信号并计算包络、相位和包络平方的样本值分布直方图function [At,Ph,A2] = EnvelopPhaseDemo(N,f0,deltf,fs,M)% 生成窄带信号N1 = N - M;xt = randn(1,N1);fl = f0*2/fs;dfl = deltf/fs;ht = fir1(M,[fl-dfl fl+dfl]);X = conv(xt,ht);% 归一化X = X/sqrt(var(X));% 计算包络和相位HX = imag(hilbert(X));t = linspace(0,(N-1)/fs,N);Ac = X.*cos(2*pi*f0*t) + HX.*sin(2*pi*f0*t);As = HX.*cos(2*pi*f0*t) - X.*sin(2*pi*f0*t);Ph = atan2(As, Ac);At = abs(Ac + 1i*As);% 计算包络平方A2 = Ac.^2 + As.^2;% 绘制样本值分布直方图figure;LA = 0:0.05:4.5;histogram(At, LA);title('包络A(t)样本值的分布直方图');figure;LP = -pi/2:0.05:pi/2;histogram(Ph, LP);title('相位Φ(t)样本值的分布直方图');figure;LA2 = 0:0.2:16;histogram(A2, LA2);title('包络平方A2(t)样本值的分布直方图');end
时间: 2024-04-01 21:38:15 浏览: 193
平方包络信号仿真
以下是不使用function的代码:
N = 1000; % 信号长度
f0 = 100; % 信号频率
deltf = 10; % 频率偏移量
fs = 1000; % 采样率
M = 50; % FIR滤波器阶数
% 生成窄带信号
N1 = N - M;
xt = randn(1,N1);
fl = f0*2/fs;
dfl = deltf/fs;
ht = fir1(M,[fl-dfl fl+dfl]);
X = conv(xt,ht);
% 归一化
X = X/sqrt(var(X));
% 计算包络和相位
HX = imag(hilbert(X));
t = linspace(0,(N-1)/fs,N);
Ac = X.*cos(2*pi*f0*t) + HX.*sin(2*pi*f0*t);
As = HX.*cos(2*pi*f0*t) - X.*sin(2*pi*f0*t);
Ph = atan2(As, Ac);
At = abs(Ac + 1i*As);
% 计算包络平方
A2 = Ac.^2 + As.^2;
% 绘制样本值分布直方图
LA = 0:0.05:4.5;
LP = -pi/2:0.05:pi/2;
LA2 = 0:0.2:16;
figure;
histogram(At, LA);
title('包络A(t)样本值的分布直方图');
figure;
histogram(Ph, LP);
title('相位Φ(t)样本值的分布直方图');
figure;
histogram(A2, LA2);
title('包络平方A2(t)样本值的分布直方图');
阅读全文