Communication Principles and MATLAB (12): Modulation and Demodulation of MSK

1. MSK modulation principle

The principle of MSK modulation is shown in the figure below. The baseband symbols are differentially coded first, and then divided into I and Q channels through serial-to-parallel conversion, and then multiplied by the corresponding carrier, and then added to complete the MSK modulation.
Wherein note: I, Q two road code elements are respectively the odd number and the code element on the even position of the relative code after differential encoding, and I road is corresponding to odd number, and Q road is corresponding to even number. And pk is I road symbol, but its symbol width Tb is twice of the symbol width Ts of relative code, and delays a Ts; And qk is Q road symbol, and its symbol width Tb is also relative code symbol Twice the width Ts.
For example, the absolute symbol is 10001, if the reference level is 1, then the relative symbol is 100001, then the unipolar code becomes bipolar code, 1 is converted into 1, 0 is converted into -1, then the I-way code The element is 1 -1 -1, and the code element of the Q path is -1 -1 1. pk is also 1 -1 -1, but the symbol width Tb of pk is twice the symbol width Ts of the relative code, and the delay is Ts. And qk is -1 -1 1, but the symbol width Tb of qk is twice the symbol width Ts of the relative code.
insert image description here
insert image description here

2. MSK demodulation principle

The principle of MSK demodulation is shown in the figure below. The MSK signal is further divided into I and Q channels and multiplied by the corresponding carrier, and then passed through a low-pass filter for sampling judgment. After the judgment, the symbols of I and Q channels are combined. The I path is the odd-numbered position symbol of the final symbol sequence, and the Q path is the even-numbered position symbol of the final symbol sequence, and then differential coding is performed to restore the original symbol sequence.
insert image description here

3. MSK code

clear all;                  % 清除所有变量
close all;                  % 关闭所有窗口
clc;                        % 清屏
%% 基本参数
M=11;                       % 产生码元数    
L=100;                      % 每码元复制L次,每个码元采样次数
Ts=0.001;                   % 每个码元的宽度,即码元的持续时间
Rb=1/Ts;                    % 码元速率1K
dt=Ts/L;                    % 采样间隔
TotalT=M*Ts;                % 绝对码总时间
t=0:dt:TotalT-dt;           % 时间1
TotalT2=(M+1)*Ts;           % 相对码总时间
t2=0:dt:TotalT2-dt;         % 时间2
Fs=1/dt;                    % 采样间隔的倒数即采样频率

%% 产生单极性波形
wave=randi([0,1],1,M);      % 产生二进制随机码,M为码元个数

%% 绝对码变相对码
wave2=ones(1,M+1);          % 产生1*(M+1)的全1行向量
%% 相对码第一个参考值为1,相对码b(n+1)=绝对码a(n)和相对码b(n)做异或
for  k = 2:M+1
    wave2(k) = xor(wave(k-1),wave2(k-1));%生成相对码
end
fz=ones(1,L);               % 定义复制的次数L,L为每码元的采样点数
x1=wave(fz,:);              % 将原来wave的第一行复制L次,称为L*M的矩阵
juedui=reshape(x1,1,L*M);   % 将刚得到的L*M矩阵,按列重新排列形成1*(L*M)的矩阵
x2=wave2(fz,:);             % 将原来wave2的第一行复制L次,称为L*(M+1)的矩阵
jidai=reshape(x2,1,L*(M+1));% 将刚得到的L*(M+1)矩阵,按列重新排列形成1*(L*(M+1))的矩阵

%% 单极性变为双极性
% 基带信号变为双极性即jidai为1的时候,jidai为1;jidai为0的时候,jidai为-1
for n=1:length(jidai)
    if jidai(n)==1
        jidai(n)=1;
    else
        jidai(n)=-1;
    end
end

%% 产生I、Q两路码元
I_lu=wave2(1:2:end);        % 相对码的奇数位置为I路码元
Q_lu=wave2(2:2:end);        % 相对码的偶数位置为Q路码元

%% I、Q两路单极性码元变为双极性码元
I_lu=2*I_lu-1;
Q_lu=2*Q_lu-1;

%%I、Q两路码元的单个码元的持续时间是原始码元中单个码元的两倍,Tb=2Ts,并且I路码元延时Ts
fz2=ones(1,2*L);            % 定义复制的次数2L
x3=I_lu(fz2,:);             % 将原来I_lu的第一行复制2L次,称为2L*((M+1)/2)的矩阵
I=reshape(x3,1,(2*L)*((M+1)/2));% 将刚得到的2L*((M+1)/2)矩阵,按列重新排列形成1*(2L*((M+1)/2))的矩阵
x4=Q_lu(fz2,:);             % 将原来Q_lu的第一行复制2L次,称为2L*((M+1)/2)的矩阵
Q=reshape(x4,1,(2*L)*((M+1)/2));% 将刚得到的2L*((M+1)/2)矩阵,按列重新排列形成1*(2L*((M+1)/2))的矩阵
I_yanshi=zeros(1,length(I));% 产生1*length(I)的零向量
% I路延时Ts,即I路1至L置零,原来1(2*L)*((M+1)/2)-L的数移动到L+1至最后
I_yanshi(L+1:end)=I(1:(2*L)*((M+1)/2)-L);

%% 绘制码元波形
figure(1);                  % 绘制第1幅图
subplot(411);               % 窗口分割成4*1的,当前是第1个子图 
plot(t,juedui,'LineWidth',2);% 绘制绝对码元波形,线宽为2
title('绝对码信号波形');    % 标题
xlabel('时间/s');           % x轴标签
ylabel('幅度');             % y轴标签
axis([0,TotalT,-1.1,1.1])   % 坐标范围限制

subplot(412);               % 窗口分割成4*1的,当前是第2个子图 
plot(t2,jidai,'LineWidth',2);% 绘制相对码元波形,线宽为2
title('相对码信号波形');    % 标题
xlabel('时间/s');           % x轴标签
ylabel('幅度');             % y轴标签
axis([0,TotalT2,-1.1,1.1])  % 坐标范围限制

subplot(413);               % 窗口分割成4*1的,当前是第3个子图 
plot(t2,I,'LineWidth',2);   % 绘制I路码元波形,线宽为2
title('I路信号波形');       % 标题
xlabel('时间/s');           % x轴标签
ylabel('幅度');             % y轴标签
axis([0,TotalT2,-1.1,1.1])  % 坐标范围限制

subplot(414);               % 窗口分割成4*1的,当前是第4个子图 
plot(t2,Q,'LineWidth',2);   % 绘制Q路码元波形,线宽为2
title('Q路信号波形');       % 标题
xlabel('时间/s');           % x轴标签
ylabel('幅度');             % y轴标签
axis([0,TotalT2,-1.1,1.1])  % 坐标范围限制
%% MSK调制
fc1=4000;                   % 载波1频率4kHz   
fc2=1/(4*Ts);               % 载波2频率1/(4*Ts)  
zb1=cos(2*pi*fc1*t2);       % 同相载波1
zb2=-sin(2*pi*fc1*t2);      % 正交载波1
zb3=cos(2*pi*fc2*t2);       % 同相载波2
zb4=sin(2*pi*fc2*t2);       % 正交载波2
I_wave=I_yanshi.*zb1;             
I_wave=I_wave.*zb3;         % I路波形
Q_wave=Q.*zb2;       
Q_wave=Q_wave.*zb4;         % Q路波形
msk=I_wave+Q_wave;          % MSK的调制 
figure(2);                  % 绘制第2幅图
subplot(411)                % 窗口分割成4*1的,当前是第1个子图 
plot(t2,I_wave,'LineWidth',2);% 绘制I路信号的波形 
title('I路信号波形')        % 标题
axis([0,TotalT2,-1.1,1.1]); % 坐标范围限制
xlabel('时间/s');           % x轴标签
ylabel('幅度');             % y轴标签

subplot(412)                % 窗口分割成4*1的,当前是第2个子图 
plot(t2,Q_wave,'LineWidth',2);% 绘制Q路信号的波形 
title('Q路信号波形')        % 标题
axis([0,TotalT2,-1.1,1.1]); % 坐标范围限制
xlabel('时间/s');           % x轴标签
ylabel('幅度');             % y轴标签

subplot(413)                % 窗口分割成4*1的,当前是第3个子图 
plot(t2,msk,'LineWidth',2); % 绘制MSK的波形 
title('MSK信号波形')        % 标题
axis([0,TotalT2,-1.1,1.1]); % 坐标范围限制
xlabel('时间/s');           % x轴标签
ylabel('幅度');             % y轴标签
%% 信号经过高斯白噪声信道
tz=awgn(msk,20);            % 信号msk中加入白噪声,信噪比为SNR=20dB
subplot(414);               % 窗口分割成4*1的,当前是第4个子图 
plot(t2,tz,'LineWidth',2);  % 绘制MSK信号加入白噪声的波形
axis([0,TotalT2,-1.5,1.5]); % 坐标范围设置
title('通过高斯白噪声信道后的信号');% 标题
xlabel('时间/s');           % x轴标签
ylabel('幅度');             % y轴标签
%% 解调部分
jt1=tz.*zb1.*zb3;           % 相干解调,I路乘以相干载波
jt2=tz.*zb2.*zb4;           % 相干解调,Q路乘以相干载波
figure(3);                  % 绘制第3幅图
subplot(511)                % 窗口分割成5*1的,当前是第1个子图 
plot(t2,jt1,'LineWidth',2)  % 绘制I路乘以相干载波后的信号
axis([0,TotalT2,-1.5,1.5]); % 设置坐标范围
title("I路乘以相干载波后的信号")% 标题
xlabel('时间/s');           % x轴标签
ylabel('幅度');             % y轴标签

subplot(512)                % 窗口分割成5*1的,当前是第2个子图 
plot(t2,jt2,'LineWidth',2)  % 绘制Q路乘以相干载波后的信号
axis([0,TotalT2,-1.5,1.5]); % 设置坐标范围
title("Q路乘以相干载波后的信号")% 标题
xlabel('时间/s');           % x轴标签
ylabel('幅度');             % y轴标签
%% 加噪信号经过滤波器
% 低通滤波器设计
fp=2*Rb;                    % 低通滤波器截止频率,乘以2是因为下面要将模拟频率转换成数字频率wp=Rb/(Fs/2)
b=fir1(30, fp/Fs, boxcar(31));% 生成fir滤波器系统函数中分子多项式的系数
% fir1函数三个参数分别是阶数,数字截止频率,滤波器类型
% 这里是生成了30(31个抽头系数)的矩形窗滤波器
[h,w]=freqz(b, 1,512);      % 生成fir滤波器的频率响应
% freqz函数的三个参数分别是滤波器系统函数的分子多项式的系数,分母多项式的系数(fir滤波器分母系数为1)和采样点数(默认)512
lvbo1=fftfilt(b,jt1);       % 对信号进行滤波,jt是等待滤波的信号,b是fir滤波器的系统函数的分子多项式系数
lvbo2=fftfilt(b,jt2);       % 对信号进行滤波,jt是等待滤波的信号,b是fir滤波器的系统函数的分子多项式系数

subplot(513);               % 窗口分割成5*1的,当前是第5个子图 
plot(w/pi*Fs/2,20*log(abs(h)),'LineWidth',2); % 绘制滤波器的幅频响应
title('低通滤波器的频谱');  % 标题
xlabel('频率/Hz');          % x轴标签
ylabel('幅度/dB');          % y轴标签

subplot(514)                % 窗口分割成5*1的,当前是第4个子图 
plot(t2,lvbo1,'LineWidth',2);% 绘制I路经过低通滤波器后的信号
axis([0,TotalT2,-1.1,1.1]); % 设置坐标范围
title("I路经过低通滤波器后的信号");% 标题
xlabel('时间/s');           % x轴标签
ylabel('幅度');             % y轴标签

subplot(515)                % 窗口分割成5*1的,当前是第5个子图 
plot(t2,lvbo2,'LineWidth',2);% 绘制Q路经过低通滤波器后的信号
axis([0,TotalT2,-1.1,1.1]); % 设置坐标范围
title("Q路经过低通滤波器后的信号");% 标题
xlabel('时间/s');           % x轴标签
ylabel('幅度');             % y轴标签

%% 抽样判决
% 滤波后的信号大于0,判决为1,小于0,判决为-1
for i=1:length(lvbo1)
    if lvbo1(i)>0
        pdst1(i)=1;
    else
        pdst1(i)=-1;
    end
end

for i=1:length(lvbo2)
    if lvbo2(i)>0
        pdst2(i)=1;
    else
        pdst2(i)=-1;
    end
end

% 取码元的中间位置上的值进行判决,由于I路延时了Ts,因此第一个抽样值为2L,间隔为2L
% Q路第一个抽样值为L,间隔为2L
I_panjue=[];
Q_panjue=[];
for j=(2*L):(2*L):((2*L)*((M+1)/2))
    if pdst1(j)>0
        I_panjue=[I_panjue,1];
    else
        I_panjue=[I_panjue,-1];
    end
end

for j=L:(2*L):((2*L)*((M+1)/2))
    if pdst2(j)>0
        Q_panjue=[Q_panjue,1];
    else
        Q_panjue=[Q_panjue,-1];
    end
end

x5=I_panjue(fz2,:);         % 将原来I_panjue的第一行复制2L次,称为2L*((M+1)/2)的矩阵
I_zong=reshape(x5,1,(2*L)*((M+1)/2));% 将刚得到的2L*((M+1)/2)矩阵,按列重新排列形成1*(2L*((M+1)/2))的矩阵
x6=Q_panjue(fz2,:);         % 将原来Q_panjue的第一行复制2L次,称为2L*((M+1)/2)的矩阵
Q_zong=reshape(x6,1,(2*L)*((M+1)/2));% 将刚得到的2L*((M+1)/2)矩阵,按列重新排列形成1*(2L*((M+1)/2))的矩阵

figure(4)                   % 绘制第4幅图
subplot(411)                % 窗口分割成4*1的,当前是第1个子图 
plot(t2,I_zong,'LineWidth',2)% 画出经过抽样判决后的信号
axis([0,TotalT2,-1.1,1.1]); % 设置坐标范用
title("I路经过抽样判决后的信号")% 标题
xlabel('时间/s');           % x轴标签
ylabel('幅度');             % y轴标签

subplot(412)                % 窗口分割成4*1的,当前是第2个子图 
plot(t2,Q_zong,'LineWidth',2)% 画出经过抽样判决后的信号
axis([0,TotalT2,-1.1,1.1]); % 设置坐标范用
title("Q路经过抽样判决后的信号")% 标题
xlabel('时间/s');           % x轴标签
ylabel('幅度');             % y轴标签

% 将I路码元为最终输出的奇数位置码元,将Q路码元为最终输出的偶数位置码元
code=[];

for n=1:(M+1)
    if mod(n, 2)~=0
        code = [code, I_panjue((n+1)/2)];
    else
        code = [code, Q_panjue(n/2)];
    end
end
x7=code(fz,:);              % 将原来code的第一行复制L次,称为L*(M+1)的矩阵
dout=reshape(x7,1,L*(M+1)); % 将刚得到的L*(M+1)矩阵,按列重新排列形成1*(L*(M+1))的矩阵

subplot(413)                % 窗口分割成4*1的,当前是第3个子图 
plot(t2,dout,'LineWidth',2) % 画出经过抽样判决后的信号
axis([0,TotalT2,-1.1,1.1]); % 设置坐标范用
title("恢复的相对码波形")   % 标题
xlabel('时间/s');           % x轴标签
ylabel('幅度');             % y轴标签

%% 相对码变绝对码
yuanma=ones(1,M);
for i=1:(M+1)
   if code(i)==1
       code(i)=1;
   else 
       code(i)=0;
   end
end

for k=1:M
   yuanma(k)=xor(code(k),code(k+1)); 
end

x8=yuanma(fz,:);            % 将原来yuanma的第一行复制L次,称为L*M的矩阵
yuanma_wave=reshape(x8,1,L*M);% 将刚得到的L*M+矩阵,按列重新排列形成1*(L*M)的矩阵

subplot(414)                % 窗口分割成4*1的,当前是第3个子图 
plot(t,yuanma_wave,'LineWidth',2) % 画出经过抽样判决后的信号
axis([0,TotalT,-1.1,1.1]);  % 设置坐标范用
title("恢复的绝对码波形")   % 标题
xlabel('时间/s');           % x轴标签
ylabel('幅度');             % y轴标签
%% 绘制频谱
%% 信源频谱
T=t2(end);                  % 时间
df=1/T;                     % 频谱分辨率
N=length(jidai);            % 采样长度
f=(-N/2:N/2-1)*df;          % 频率范围
mf=fftshift(abs(fft(jidai)));%对信源信号采用快速傅里叶变换并移到矩阵中心
figure(5)                   % 绘制第5幅图
subplot(211);               % 窗口分割成2*1的,当前是第1个子图 
plot(f,mf,'LineWidth',2);   % 绘制信源频谱波形
title("基带信号频谱");      % 标题
xlabel('频率/Hz');          % x轴标签
ylabel('幅度');             % y轴标签

%% MSK信号频谱
sf=fftshift(abs(fft(msk)));% 对MSK信号采用快速傅里叶变换并将0-fs频谱移动到-fs/2-fs/2
subplot(212)                % 窗口分割成2*1的,当前是第2个子图 
plot(f,sf,'LineWidth',2)    % 绘制MSK调制信号频谱
title("MSK信号频谱")        % 标题
xlabel('频率/Hz');          % x轴标签
ylabel('幅度');             % y轴标签
 
%% 乘以相干载波后的频谱
mmf=fftshift(abs(fft(jt1)));% 对I路相干载波信号采用快速傅里叶变换并移到矩阵中心
mmf2=fftshift(abs(fft(jt2)));% 对Q路相干载波信号采用快速傅里叶变换并移到矩阵中心
figure(6)                   % 绘制第6幅图
subplot(211);               % 窗口分割成2*1的,当前是第1个子图 
plot(f,mmf,'LineWidth',2)   % 画出I路乘以相干载波后的频谱
title("I路乘以相干载波后的频谱")% 标题
xlabel('频率/Hz');          % x轴标签
ylabel('幅度');             % y轴标签

subplot(212);               % 窗口分割成2*1的,当前是第2个子图 
plot(f,mmf2,'LineWidth',2)  % 画出Q路乘以相干载波后的频谱
title("Q路乘以相干载波后的频谱")% 标题
xlabel('频率/Hz');          % x轴标签
ylabel('幅度');             % y轴标签

%% 经过低通滤波后的频谱
dmf=fftshift(abs(fft(lvbo1)));%对I路低通滤波信号采用快速傅里叶变换并移到矩阵中心
dmf2=fftshift(abs(fft(lvbo2)));%对Q路低通滤波信号采用快速傅里叶变换并移到矩阵中心
figure(7);                  % 绘制第7幅图
subplot(211);               % 窗口分割成2*1的,当前是第1个子图 
plot(f,dmf,'LineWidth',2)   % 画出I路经过低通滤波后的频谱
title("I路经过低通滤波后的频谱");% 标题
xlabel('频率/Hz');          % x轴标签
ylabel('幅度');             % y轴标签

subplot(212);               % 窗口分割成2*1的,当前是第2个子图 
plot(f,dmf2,'LineWidth',2)  % 画出Q路经过低通滤波后的频谱
title("Q路经过低通滤波后的频谱");% 标题
xlabel('频率/Hz');          % x轴标签
ylabel('幅度');             % y轴标签

4. Result graph

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

5. Features


Minimum frequency shift keying (MSK) signal is a 2FSK signal with constant envelope, continuous phase, minimum bandwidth, and strict orthogonality, which has strong anti-interference ability.

Guess you like

Origin blog.csdn.net/qq_47598782/article/details/128630392