📄 cp4fskmod.m
字号:
function [I_Symbol,Q_Symbol] = cp4fskmod(BitStream)
% ---------------------------------------------------------------
% Continue Phase Four level FSK modulation Program,used for DMR,ETSI
% This program describe the following routines:
% Bit Stream ---- Symbol ---- modulation symbol ---- RRC filter
% ---- FM modulator -----Output Signal
% Written by zhengliangde, HYT Co.,LTD. 2005.11.4
% Contact: zhld_308@163.com
% ---------------------------------------------------------------
nSamp = 8; % number of samples per symbol
Fd = 4800; % symbol rate
Fs = nSamp*Fd; % sample rate
freq_sep = 648; % frequency seperation
prevPhase = 0; % initial phase
pi_Def = 3.1416; % pi define
M = 4; % four level FSK
BitStream = randsrc(400,1,[0 1],12321);
% --------- Check error ----------
if Fs<freq_sep*(M-1)
error('The max Frequency must be less than or equal to Fs/2.');
end
% Increasing phase calculated formura:
% [1 3 -1 -3]*pi*freq_sep*1/Fs
%PhaseIncr = [0:nSamp-1]'*[0.4241 1.2723 -0.4241 -1.2723];
%PhaseIncr=[...
% 0 0 0 0
% 0.0530 0.1590 -0.0530 -0.1590
% 0.1060 0.3181 -0.1060 -0.3181
% 0.1590 0.4771 -0.1590 -0.4771
% 0.2121 0.6362 -0.2121 -0.6362
% 0.2651 0.7952 -0.2651 -0.7952
% 0.3181 0.9543 -0.3181 -0.9543
% 0.3711 1.1133 -0.3711 -1.1133];
%PhIncrSamp = [0.0530 0.1590 -0.0530 -0.1590];
PhaseIncr = [0:nSamp-1]'*[-3 -1 1 3]*pi_Def*freq_sep*1/Fs;
PhIncrSamp = [-3 -1 1 3]*pi_Def*freq_sep*1/Fs;
% ------------- Serial to Parallel -------------
I_BitStream = BitStream(1:2:length(BitStream));
Q_BitStream = BitStream(2:2:length(BitStream));
% ----------- Generate four level Symbol -----------
Symbol = I_BitStream*2 + Q_BitStream;
% ----------- Calculate the phase -----------
Phase = zeros(size(Symbol)); % preallocate phase
for iSym=1:length(Symbol)
Phase(nSamp*(iSym-1)+1:nSamp*iSym) = ...
prevPhase*ones(nSamp,1) + PhaseIncr(:,Symbol(iSym)+1);
prevPhase = Phase(nSamp*iSym) + PhIncrSamp(Symbol(iSym)+1);
end
% -------- convert Phase between [0:2*pi] --------
for indx=1:length(Phase)
while (abs(Phase(indx))>=2*pi_Def)
if Phase(indx)>0
Phase(indx) = Phase(indx) - 2*pi_Def;
elseif Phase(indx)<0
Phase(indx) = Phase(indx) + 2*pi_Def;
end
end
end
% -------- Generate I/Q signal ---------
I_Symbol = cos(Phase);
Q_Symbol = sin(Phase);
% ----------- End of modulation file -----------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -