一、设置调制参数
M = 4; % Modulation order
freqsep = 8; % Frequency separation (Hz)
nsamp = 8; % Number of samples per symbol
Fs = 32; % Sample rate (Hz)
Generate random M-ary symbols.
x = randi([0 M-1],1000,1);
二、全流程仿真
%Apply FSK modulation.
y = fskmod(x,M,freqsep,nsamp,Fs);
Create a spectrum analyzer System object™ and use its step method to display a plot of the signal spectrum.
h = dsp.SpectrumAnalyzer('SampleRate',Fs);
step(h,y) % 信号频谱显示
三、关键点解析
samptime = 1/Fs; % 采样时间
maxFreq = ((M-1)/2) * freq_sep; %最大频率
maxFreq <= Fs/2; % 需要满足的条件(采样定理)
相位调制分为非连续相位调制和连续相位调制
- 非连续相位调制
初始化参数
% Obtain the total number of channels
[nRows, nChan] = size(x);
% Initialize the phase increments and the oscillator phase for modulator with discontinuous phase.
phaseIncr = (0:nSamp-1)' * (-(M-1):2:(M-1)) * 2*pi * freq_sep/2 * samptime; %每个符号的随采样点数增加,相位的增加值
% phIncrSym is the incremental phase over one symbol, across all M tones. 每个符号的相位增加值
phIncrSym = phaseIncr(end,:);
% phIncrSamp is the incremental phase over one sample, across all M tones.每个采样点相位的增加值
phIncrSamp = phaseIncr(2,:); % recall that phaseIncr(1,:) = 0
OscPhase = zeros(nChan, M);
% phase = nSamp*# of symbols x # of channels
Phase = zeros(nSamp*nRows, nChan);
exp_phaseIncr = exp(1i*phaseIncr);
y = reshape(exp_phaseIncr(:,x+1),nRows*nSamp,nChan);
- 相位连续
for iChan = 1:nChan
prevPhase = 0; % 初始化相位值为0
for iSym = 1:nRows
% Get the initial phase for the current symbol
if (phase_cont)
ph1 = prevPhase; %当前相位值
else
ph1 = OscPhase(iChan, x(iSym,iChan)+1);
end
% Compute the phase of the current symbol by summing the initial phase
% with the per-symbol phase trajectory associated with the given M-ary data element. 当前相位值加上增加相位值
Phase(nSamp*(iSym-1)+1:nSamp*iSym,iChan) = ...
ph1*ones(nSamp,1) + phaseIncr(:,x(iSym,iChan)+1);
% Update the oscillator for a modulator with discontinuous phase.
% Calculate the phase modulo 2*pi so that the phase doesn't grow too
% large.
if (~phase_cont)
OscPhase(iChan,:) = ...
rem(OscPhase(iChan,:) + phIncrSym + phIncrSamp, 2*pi); % 取模2*pi
end
% If in continuous mode, the starting phase for the next symbol is the
% ending phase of the current symbol plus the phase increment over one sample. 最后相位值在加一个采样点的相位值
prevPhase = Phase(nSamp*iSym,iChan) + phIncrSamp(x(iSym,iChan)+1);
end
end
y = exp(1i*Phase);
后记:
主要思路是分为非连续相位和连续相位.
当前相位为原来相位加上增长相位;
原来相位为上一次相位值多加一次采样值的相位;
增加相位每次都一样.每个符号的采样点数对应的相位值.
很好地运用了不同矩阵的运算.