最小頻移鍵控MSK
基本原理
源代碼
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 最小頻移鍵控MSK
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
clear all;
close all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 參數設定
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N=10; % 碼元個數
count=100; % 一個碼元取100個點
n=N*count; % 總的采樣點數
fs=1e6; % 采樣頻率
TB=1/fs*count; % 碼元周期,一個碼元持續的時間
fc=3/(4*TB); % 載波頻率fc=n/(4*TB), n=1,2,3... f1=fc-1/(4TB) f2=fc+1/(4TB)
t=0:1/fs:(n-1)/fs;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 信源
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ak=2*randi([0,1],1,N)-1;%産生1,-1雙極性序列
ak=[1,1,-1,1,-1,-1,1,1,-1,1];
for p = 1:N % 内插
AK(( (p-1)*count+1):( p*count) ) = ak(p);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 差分編碼 同或運算
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bk(1)=1; % 初值
for p=2:N
if ak(p-1)==-1
bk(p)=-bk(p-1);
else
bk(p)=bk(p-1);
end
end
bk=[bk(2:end) bk(1)]; % 左移一位
for p = 1:N % 内插
BK(( (p-1)*count+1):( p*count) ) = bk(p);
end
figure(1)
subplot(211);
plot(t,AK);grid on
xlabel('時間/s');ylabel('幅度');
title('基帶信号ak波形');
subplot(212);
plot(t,BK);grid on
xlabel('時間/s');ylabel('幅度');
title('差分信号bk波形');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 相位finek
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
finek(1)=0; % 初始相位為0
for p = 2:N
finek(p)=finek(p-1)+(p-1)*pi/2*(ak(p-1)-ak(p)); %書上第一個元素是finek(0),但是計算機隻能從1開始,是以是(p-1)*pi/2
finek(p)=mod(finek(p),2*pi);
end
for p = 1:N % 内插
FINEK(( (p-1)*count+1):( p*count) ) = finek(p);
end
figure(2)
plot(t,FINEK,'r');grid on
xlabel('時間/s');ylabel('幅度');
title('finek');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% pk qk 兩路信号
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pk=cos(finek);
qk=ak.*(cos(finek));
for p = 1:N % 内插
PK(( (p-1)*count+1):( p*count) ) = pk(p);
QK(( (p-1)*count+1):( p*count) ) = qk(p);
end
figure(3)
subplot(211);
plot(t,PK,'r');grid on
xlabel('時間/s');ylabel('幅度/V');
title('pk');
subplot(212);
plot(t,QK,'b');grid on
xlabel('時間/s');ylabel('幅度/V');
title('qk');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% pk*cos(pi/(2*TB)*t) qk*sin(2*pi*fc*tQ)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
u=PK.*cos(pi/(2*TB)*t);
v=QK.*sin(pi/(2*TB)*t);
U=u.*cos(2*pi*fc*t); %與載波相乘
V=v.*sin(2*pi*fc*t);
figure(4)
subplot(211);
plot(t,U,'b');grid on
xlabel('時間/s');ylabel('幅度/V');
title('pk*cos(pi/(2*TB)*t)');grid on
subplot(212);
plot(t,V,'g');grid on
xlabel('時間/s');ylabel('幅度/V');
title('qk*sin(2*pi*fc*tQ)');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MSK信号
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
MSK=PK.*cos(pi/(2*TB)*t).*cos(2*pi*fc*t)-QK.*sin(pi/(2*TB)*t).*sin(2*pi*fc*t);
Y=fftshift(fft(MSK));
L=length(Y);
P=abs(Y)/L;
f=(0:L-1)*fs/L-fs/2;
figure(5)
subplot(211);
plot(t,MSK,'r');grid on
xlabel('時間/s');ylabel('幅度/V');
title('MSK信号時域波形');
subplot(212);
plot(f,P); grid on;
xlabel('頻率/HZ');ylabel('幅度/V');
title('MSK的信号頻譜圖');
仿真結果