|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
clear;
numSamplesPerSymbol = 8;
BitStreamLength = 10000;
hTransmitFilter = ones(1,numSamplesPerSymbol);
BitStream = rand(1,BitStreamLength)>0.5;
[BitStreamOne,BitStreamTwo] = SerialToParallel(BitStream);
[I_SymbolsTx,Q_SymbolsTx] = DQPSKEncoder(BitStreamOne,BitStreamTwo);
[I_WaveformTx,Q_WaveformTx] = TransmitFilter(I_SymbolsTx,Q_SymbolsTx,
hTransmitFilter,numSamplesPerSymbol);
end
function [BitStreamOne,BitStreamTwo] = SerialToParallel(BitStream)
BitStreamOne = BitStream(1:2:length(BitStream));
BitStreamTwo = BitStream(2:2:length(BitStream));
% Converts a Symbol stream to a Waveform containing impulses.
function [Waveform] = SymbolToWaveform(SymbolStream,numSamplesPerSymbol)
lenWaveform = length(SymbolStream)*numSamplesPerSymbol;
Waveform = zeros(1,lenWaveform);
Waveform(1:numSamplesPerSymbol:lenWaveform) = SymbolStream;
function [I_TxWaveform, Q_TxWaveform] = TransmitFilter(I_Symbols,Q_Symbols,hTransmitFilter,numSamplesPerSymbol)
% The first step is to convert the symbol stream into a digital signal so that it can
% be filtered.
I_Waveform = SymbolToWaveform(I_Symbols,numSamplesPerSymbol);
Q_Waveform = SymbolToWaveform(Q_Symbols,numSamplesPerSymbol);
% The next step is to filter the signal to obtain the transmit waveforms.
I_TxWaveform = conv(I_Waveform,hTransmitFilter);
Q_TxWaveform = conv(Q_Waveform,hTransmitFilter);
function Phase = CalcPhase(BitVector)
switch BitVector(1)
case 0,
switch BitVector(2)
case 0, % [0,0] case
Phase = pi/4;
case 1, % [0,1] case
Phase = 3*pi/4;
end
case 1,
switch BitVector(2)
case 0, % [1,0] case
Phase = -pi/4;
case 1, %[1,1] case
Phase = -3*pi/4;
end
end
% pi/4 shifter DQPSK Encoder.
function [I_Symbols, Q_Symbols] = DQPSKEncoder(BitStreamOneTx, BitStreamTwoTx)
% This is supposed to be (I(-1) + jQ(-1)).
InitialSymbol = (1+0i);
I_StreamLength = length(BitStreamOneTx);
Q_StreamLength = I_StreamLength;
% -------------------> Differential Modulation <------------------------------- %
% Do the Differential Modulation and generate the baseband-complex signal.
% Calculate the phase-shift due to the first symbol.
PhaseShift(1) = CalcPhase([BitStreamOneTx(1),BitStreamTwoTx(1)]);
% The first modulated symbol.
ModulatedSymbol(1) = (InitialSymbol)*exp(i*PhaseShift(1));
% The other symbols calculated iteratively.
for index = 2:1:I_StreamLength
% The phase shift due to the ith modulated symbol.
PhaseShift(index) = CalcPhase([BitStreamOneTx(index),BitStreamTwoTx(index)]);
% Rotated the modulated symbol phasor to the new position.
ModulatedSymbol(index) = ModulatedSymbol(index-1)*exp(j*PhaseShift(index));
end
% Extract the I and Q parts of the Symbol.
I_Symbols = real(ModulatedSymbol);
Q_Symbols = imag(ModulatedSymbol); |
|