MASK 瞬时幅度&相位&频率参数仿真
另 瞬时幅度谱仿真
clc;
close all;
clear;
% 生成信号
t = 0 : 1/1e3 : 1-1/1e3;
a_2 = [0,1,1,0,1,1,0,0,1,0]; % randi([0, 1], 1, 10); % 10个0、1随机数;
a_4 = [2,0,1,3,2,3,0,1,0,1, 2, 3];
f_s2 = a_2(ceil(10*t+0.01)); % 索引;
f_s4 = a_4(ceil(12*t+0.01)); % 索引;
s_2ASK = f_s2 .* exp(1j*2*pi*100*t); % s_2ASK = f_s .* cos(2*pi*100*t);
s_4ASK = f_s4 .* exp(1j*2*pi*100*t);
% 计算瞬时值
%a_t_s = zeros(2, 1000);
a_t_s = [];
fai_t_s = [];
f_t_s = [];
Gama_s = [];
C = zeros(1, 1000);
fai = zeros(1, 1000);
fai_t = zeros(1, 1000);
Gama_max_s = [];
C_s2 = [];
for i = 1:2
s_mASK_s = [s_2ASK; s_4ASK];
s_mASK = s_mASK_s(i, :) .* exp(-1j*2*pi*100*t); % 去載波
% 瞬时幅度
a_t = abs(s_mASK);
a_t_s = [a_t_s; a_t];
% 瞬时相位
I = real(s_mASK);
Q = imag(s_mASK);
fai = atan2(Q, I); % 瞬时相位 % 同angle();
for j = 2:length(t)
if fai(j) - fai(j-1) > pi
C(j) = C(j-1) - 2*pi;
elseif fai(j-1) - fai(j) > pi
C(j) = C(j-1) + 2*pi;
else
C(j) = C(j-1);
end
end
fai_t = fai + C; % 去卷叠瞬时相位 % 同unwrap();
fai_t_s = [fai_t_s; fai_t];
% 瞬时频率(相位的变化率)
% %对相位求时间的导数(差分),即为频率(dfai/dt=f)。类比ds/dt=v
f_t = [fai_t(2:1:end) - fai_t(1:1:end-1), 0];
f_t_s = [f_t_s; f_t];
% 希尔伯特变换
s_mASK_h = (hilbert(s_mASK).');
%s_ASK_h =(s_ASKh.'); % 转置
a_t = abs(s_mASK_h); % 包络的绝对值
% 归一化零中心瞬时幅度之谱密度的最大值γmax
a_cn = ((a_t/mean(a_t) - 1).');
Gama=(abs(fft(a_cn))).^2/length(t);
Gama_s = [Gama_s; Gama];
Gama_max = max(Gama);
Gama_max_s = [Gama_max_s; Gama_max];
end
绘图
figure(1);
subplot(521); plot(t, s_2ASK); title('2ASK'); axis([0, 1-1/1e3, -1.5, 1.5]);
subplot(522); plot(t, s_4ASK); title('4ASK'); axis([0, 1-1/1e3, -3.5, 3.5]);
subplot(523); plot(t, a_t_s(1, :)); title('2ASK瞬时幅度'); axis([0, 1, -0.5, 1.5]);
subplot(524); plot(t, a_t_s(2, :)); title('4ASK瞬时幅度'); axis([0, 1, -0.5, 3.5]);
subplot(525); plot(t, fai_t_s(1, :)); title('2ASK瞬时相位'); axis([0, 1-1/1e3, min(fai_t_s(1, :))-0.5, max(fai_t_s(1, :))+0.5]);
subplot(526); plot(t, fai_t_s(2, :)); title('4ASK瞬时相位'); axis([0, 1-1/1e3, min(fai_t_s(2, :))-0.5, max(fai_t_s(2, :))+0.5]);
subplot(527); plot(t, f_t_s(1, :)); title('2ASK瞬时频率'); axis([0, 1-1/1e3, min(f_t_s(1, :))-0.5, max(f_t_s(1, :))+0.5]);
subplot(528); plot(t, f_t_s(2, :)); title('4ASK瞬时频率'); axis([0, 1-1/1e3, min(f_t_s(1, :))-0.5, max(f_t_s(1, :))+0.5]);
subplot(325); plot(a_t); title('2ASK包络绝对值');
subplot(529); plot(Gama_s(1, :)); title('2ASK瞬时幅度谱'); axis([0-50, length(t)+50, min(Gama_s(1, :)), max(Gama_s(1, :))+20]);
subplot(5,2,10); plot(Gama_s(2, :)); title('4ASK瞬时幅度谱'); axis([0-50, length(t)+50, min(Gama_s(2, :)), max(Gama_s(2, :))+20]);
MPSK
clc;
close all;
clear;
t = 0 : 1/1e3 : 1-1/1e3;
a_2 = [0,1,1,0,0,1,1,0,1,0]; % randi([0, 1], 1, 10); % 10个0、1随机数;
a_4 = [2,0,1,3,2,3,0,1,0,1, 2, 3];
f_s2 = a_2(ceil(10*t+0.01)); % 基带信号 % 0&1
f_s4 = a_4(ceil(12*t+0.01)); % 基带信号 % 0&1&2&3
%s_2PSK = cos(2*pi*50*t + 2*pi*(1/2)*f_s2);
%s_4PSK = cos(2*pi*50*t + 2*pi*(1/4)*f_s4);
s_2PSK= exp(1j*(2*pi*50.*t + 2*pi*(1/2)*f_s2));
s_4PSK= exp(1j*(2*pi*50.*t + 2*pi*(1/4)*f_s4));
a_t_s = [];
fai_t_s = [];
f_t_s = [];
Gama_s = [];
Gama_max_s = [];
C_s2 = [];
for i = 1:2
s_mPSK_s = [s_2PSK; s_4PSK];
s_mPSK = s_mPSK_s(i, :).*exp(-1j*2*pi*50.*t);
% 瞬时幅度
a_t = abs(s_mPSK);
a_t_s = [a_t_s; a_t];
% 瞬时相位
C = zeros(1, 1000);
fai = zeros(1, 1000); % 瞬时相位;
fai_t = zeros(1, 1000); % 去卷叠瞬时相位;
I = real(s_mPSK);
Q = imag(s_mPSK);
fai = atan2(Q, I);
for i = 2:length(t)
if fai(i) - fai(i-1) > pi
C(i) = C(i-1) - 2*pi;
elseif fai(i-1) - fai(i) > pi
C(i) = C(i-1) + 2*pi;
else
C(i) = C(i-1);
end
end
fai_t = mod(fai + C, 2*pi);
fai_t_s = [fai_t_s; fai_t];
% 瞬时频率
f_t = fai_t(2:1:end) - fai_t(1:1:end-1);
f_t = [f_t, f_t(end)];
f_t_s = [f_t_s; f_t];
% 希尔伯特变换
s_mPSK_h = (hilbert(s_mPSK));
a_t = abs(s_mPSK_h); % 包络的绝对值
% 归一化零中心瞬时幅度之谱密度的最大值γmax
a_cn = ((a_t/mean(a_t) - 1));
Gama=(abs(fft(a_cn))).^2/length(t);
Gama_s = [Gama_s; Gama];
Gama_max = max(Gama);
Gama_max_s = [Gama_max_s; Gama_max];
end
figure(1);
subplot(421); plot(t, s_2PSK); title('2PSK'); axis([0, 1-1/1e3, -1.5, 1.5]);
subplot(422); plot(t, s_4PSK); title('4PSK'); axis([0, 1-1/1e3, -1.5, 1.5]);
subplot(423); plot(t, a_t_s(1, :)); title('2PSK瞬时幅度'); axis([0, 1, -0.5, 1.5]);
subplot(424); plot(t, a_t_s(2, :)); title('4PSK瞬时幅度'); axis([0, 1, -0.5, 1.5]);
subplot(425); plot(t, mod(fai_t_s(1, :), 2*pi)); title('2PSK瞬时相位'); axis([0, 1-1/1e3, min(fai_t_s(1, :))-0.5, max(mod(fai_t_s(1, :), 2*pi))+0.5]);
subplot(426); plot(t, mod(fai_t_s(2, :), 2*pi)); title('4PSK瞬时相位'); axis([0, 1-1/1e3, min(fai_t_s(2, :))-0.5, max(fai_t_s(2, :))+0.5]);
subplot(427); plot(t, f_t_s(1, :)); title('2PSK瞬时频率'); axis([0, 1-1/1e3, min(f_t_s(1, :))-0.5, max(f_t_s(1, :))+0.5]);
subplot(428); plot(t, f_t_s(2, :)); title('4PSK瞬时频率'); axis([0, 1-1/1e3, min(f_t_s(1, :))-0.5, max(f_t_s(1, :))+0.5]);
MFSK
clc;
close all;
clear;
t = 0 : 1/1e3 : 1-1/1e3;
df = 100; % 频偏
a_2 = [0,1,1,0,0,1,1,0,1,0]; % randi([0, 1], 1, 10); % 10个0、1随机数;
a_4 = [2,0,1,3,2,3,0,1,0,1];
f_s2 = a_2(ceil(10*t+0.01)); % 基带信号 % 0&1
f_s4 = a_4(ceil(10*t+0.01)); % 基带信号 % 0&1
s_2FSK= exp(1j*2*pi*(50+f_s2*df).*t);
s_4FSK= exp(1j*2*pi*(50+f_s4*df).*t);
%s_2FSK = cos(2*pi*(50 + f_s2*df).*t); % f0=50Hz
%s_4FSK = cos(2*pi*(50 + f_s4*df).*t); % f0=50Hz
a_t_s = [];
fai_t_s = [];
f_t_s = [];
Gama_s = [];
C = zeros(1, 1000);
fai = zeros(1, 1000); % 瞬时相位;
fai_t = zeros(1, 1000); % 去卷叠瞬时相位;
Gama_max_s = [];
C_s2 = [];
for i = 1:2
s_mFSK_s = [s_2FSK; s_4FSK];
s_mFSK = s_mFSK_s(i, :) .* exp(-1j*2*pi*50.*t);
% 瞬时幅度
a_t = abs(s_mFSK);
a_t_s = [a_t_s; a_t];
% 瞬时相位
I = real(s_mFSK);
Q = imag(s_mFSK);
fai = atan2(Q, I);
for j = 2:length(t)
if fai(j) - fai(j-1) > pi
C(j) = C(j-1) - 2*pi;
elseif fai(j-1) - fai(j) > pi
C(j) = C(j-1) + 2*pi;
else
C(j) = C(j-1);
end
end
fai_t = fai + C;
fai_t_s = [fai_t_s; fai_t];
% 瞬时频率
%f_t = fai_t(2:1:end) - fai_t(1:1:end-1);
f_t = diff(fai_t);
f_t = [f_t, f_t(end)];
f_t_s = [f_t_s; f_t];
% 希尔伯特变换
s_mFSK_h = (hilbert(s_mFSK).');
a_t = abs(s_mFSK_h); % 包络的绝对值
% 归一化零中心瞬时幅度之谱密度的最大值γmax
a_cn = ((a_t/mean(a_t) - 1).');
Gama=(abs(fft(a_cn))).^2/length(t);
Gama_s = [Gama_s; Gama];
Gama_max = max(Gama);
Gama_max_s = [Gama_max_s; Gama_max];
%{
% 一阶累积量 = 一阶矩 = E(x)
% Mpq = mean(X.^(p-q) .* X.^q); p+q阶混合矩;
s_mASK = s_mFSK - mean(s_mFSK); % 去直流
Ex = mean(s_mFSK);
M1 = Ex;
M20 = mean(s_mASK.^2 .* s_mASK.^0);
M21 = mean(s_mASK.^1 .* s_mASK.^1);
M40 = mean(s_mASK.^4 .* s_mASK.^0);
M41 = mean(s_mASK.^3 .* s_mASK.^1);
M42 = mean(s_mASK.^2 .* s_mASK.^2);
M60 = mean(s_mASK.^6 .* s_mASK.^0);
M61 = mean(s_mASK.^5 .* s_mASK.^1);
M62 = mean(s_mASK.^4 .* s_mASK.^2);
M63 = mean(s_mASK.^3 .* s_mASK.^3);
M80 = mean(s_mASK.^8 .* s_mASK.^0);
Cum20 = M20;
Cum21 = M21; % 三阶以上不等
Cum40 = M40 - 3*(M20)^2;
Cum41 = M41 - 3*M21*M20;
Cum42 = M42 - abs(M20)^2 - 2*M21^2;
Cum60 = M60 - 15*M40*M20 + 30*M20^3;
Cum63 = M63 - 9*Cum42*Cum21 - 6*Cum21^3;
Cum80 = M80 - 28*M60*Cum20 - 35*M40^2 + 420*M40*M20^2 - 630;
E_pow = Cum21; % 平均功率
C20_E_pow_2 = Cum20/E_pow;
C21_E_pow_2 = Cum21/E_pow;
C40_E_pow_2 = Cum40/E_pow^2;
C41_E_pow_2 = Cum41/E_pow^2;
C42_E_pow_2 = Cum42/E_pow^2;
C60_E_pow_3 = Cum60/E_pow^3;
C63_E_pow_3 = Cum63/E_pow^3;
C80_E_pow_4 = Cum80/E_pow^4;
C_s = [C20_E_pow_2, C21_E_pow_2, C40_E_pow_2, C41_E_pow_2,...
C42_E_pow_2, C60_E_pow_3, C63_E_pow_3, C80_E_pow_4];
C_s2 = [C_s2; real(C_s)];
%}
end
% 绘图
figure(1);
subplot(421); plot(t, s_2FSK); title('2FSK'); axis([0, 1-1/1e3, -1.5, 1.5]);
subplot(422); plot(t, s_4FSK); title('4FSK'); axis([0, 1-1/1e3, -1.5, 1.5]);
subplot(423); plot(t, a_t_s(1, :)); title('2FSK瞬时幅度'); axis([0, 1, min(a_t_s(1, :))-0.5, max(a_t_s(1, :))+0.5]);
subplot(424); plot(t, a_t_s(2, :)); title('4FSK瞬时幅度'); axis([0, 1, min(a_t_s(2, :))-0.5, max(a_t_s(2, :))+0.5]);
subplot(425); plot(t, fai_t_s(1, :)); title('2FSK瞬时相位'); axis([0, 1-1/1e3, min(fai_t)-0.5, max(fai_t)+0.5]);
subplot(426); plot(t, fai_t_s(2, :)); title('4FSK瞬时相位'); axis([0, 1-1/1e3, min(fai_t)-0.5, max(fai_t)+0.5]);
min(f_t_s(1, :))
subplot(427); plot(t, f_t_s(1, :)); title('2FSK瞬时频率'); axis([0, 1-1/1e3, min(f_t_s(1, :))-0.5, max(f_t_s(1, :))+0.5]);
subplot(428); plot(t, f_t_s(2, :)); title('4FSK瞬时频率'); axis([0, 1-1/1e3, min(f_t_s(2, :))-0.5, max(f_t_s(2, :))+0.5]);
%saveas(1, 'BFSK_para.jpg');
figure(2);
subplot(121); plot(Gama_s(1, :)); title('2FSK瞬时幅度谱'); axis([0-50, length(t)+50, min(Gama_s(1, :)), max(Gama_s(1, :))]);
subplot(122); plot(Gama_s(2, :)); title('4FSK瞬时幅度谱'); axis([0-50, length(t)+50, min(Gama_s(2, :)), max(Gama_s(2, :))]);
%disp(Gama_max_s)