Simple AWGN digital transmission
Creat digital modulation.
First creat an object containing all the caracteristics of your modulation: use commande modem.xxx
The xxx can be (pskmod, qammod, pammod, oqpskmod, genqammod, dpskmod, mskmod)
To this function, we may add more parameters:
examples:
modulator = modem.pskmod('M',4, 'PhaseOffset',pi/4, 'SymbolOrder','gray','InputType','integer', etc);
modulator = modem.qammod('M', 64, 'SymbolOrder', 'Gray', 'InputType', 'Bit')
Modulate data
Use the function modulate: modulated = modulate(modulator, data)
data can be created using randi function: data = randi([0 3],100,1); which creats a vector of length 100 of 0..3
Add CRC
For example, add the IEC870-5-1 CRC bits for which the generator polynomial is:
x^13 + x^12 + x^11 + x^10 + x^8 + x^6 + x^5 + x^2 + 1
and suppose that all the bits are invrted befoir transmission (KNX standard). First we genberate the class crc:
encoder = crc.generator('Polynomial','0x3d65','initialstate','0x0000','finalxor','0xffff');
To generate and add the CRC at the end of a block of size 100 bits:
block = randsrc(100,1,[0 1]); % it must be a column vector
new_block = generate(encoder, block);
To detect if the CRC are corect at the receiver:
decoder = crc.generator('Polynomial','0x3d65','initialstate','0x0000','finalxor','0xffff');
[block_hat err]=detect(decoder,new_block);
block_hat will be the first 100 bit of new_block and err will be 0 if CRC is ok and 1 if CRC is not ok.
Add noise
Suppose we'd like to add a complex noise of variance sigma^2.
noise = sigma * ( randn(100,1) + 1i * randn(100,1) ) / sqrt(2)
received = modulated + noise ;
How to calculate sigma : begining with EbN0_dB
PSK modulation : sigma^2 = 10^(-EbN0_dB / 10)
QPSK modulation : sigma^2 = 0.5 * 10^(-EbN0_dB / 10)
whatever M-arry modulation with expectation(symbols)=1 : sigma^2 = (1 / log2(M) ) * 10^(-EbN0_dB / 10)
If a coding with rate r (r = 1/2 for convolutional code) is used with a QPSK modulation:
sigma^2 = (1/r) * 0.5 * 10^(-EbN0_dB / 10)
It is possible to create a BSC channel with
[ndata err ] = bsc(data,p);
Demodulation
First you should creat the object containing the same caracteristics as the modulator. For that we re-use the class modem.
modem.xxx where xxx can be one of :
pskdemod, qamdemod, pamdemod, oqpskdemod, genqamdemod, dpskdemod, mskdemod)
Then you add more parameters. Examples:
modulator = modem.pskdemod('M',4, 'PhaseOffset',pi/4, 'SymbolOrder','gray','OutputType','integer',);
modulator = modem.qamdemod('M', 64, 'SymbolOrder', 'OutputType','integer', 'DecisionType', 'Hard Decision' or 'LLR')
Example:
M=4;
phase_offset=pi/4;
input_type='integer';
mapping='GRAY';
Packet_length = 10000;
modulator = modem.pskmod('M',M,'PHASEOFFSET',phase_offset,'SYMBOLORDER',mapping,'INPUTTYPE','integer');
data = randi([0 M-1], Packet_length,1);
modulated = modulate(modulator, data);
EbN0_dB=6;
sigma2=(1/3) * 10^((-EbN0_dB/10));
noise = sqrt (0.5 * sigma2) * ( randn(Packet_length,1) + 1i * randn(Packet_length,1) );
r=modulated + noise;
demodulator =
modem.pskdemod('M',M,'PHASEOFFSET',phase_offset,'SYMBOLORDER',mapping,'OUTPUTTYPE','integer',
'DecisionType','Hard Decision');
data_hat = demodulate(demodulator,r);
[num_err , per] = biterr(data, data_hat)
-------------------------------------------------------------------------------