You are on page 1of 3

Here's an example Matlab script that does Star-16-QAM mapping with Gray mapping, models an AWGN channel and

does the decision and demapping. The bit error rate (BER) is also calculated. I'll shortly explaing how it works. First, we create a random bit sequence with '0' and '1' occuring with equal probability. The radius of the inner and outer circle of the constellation diagram are also defined. % Random bit sequence numberOfBits = 1e5; x = rand(1, numberOfBits); x( x < 0.5 ) = 0; x( x >= 0.5 ) = 1; % Radius of inner and outer circle r1 = 1; r2 = 2; In the next step we define the mapping table that maps an integer index number to a complex symbol. This is done in such a way, that two neighbouring symbols only differ in one bit. This is called Gray mapping. % Define mapping table applying Gray mapping mappingTable(1) = r1 * exp(1i* 0); mappingTable(2) = r1 * exp(1i* pi/4); mappingTable(3) = r1 * exp(1i* 3*pi/4); mappingTable(4) = r1 * exp(1i* pi/2); mappingTable(5) = r1 * exp(1i* 7*pi/4); mappingTable(6) = r1 * exp(1i* 3*pi/2); mappingTable(7) = r1 * exp(1i* pi); mappingTable(8) = r1 * exp(1i* 5*pi/4); mappingTable(9:16) = mappingTable(1:8) ./ r1 .* r2; Now for each block of 4 bits we calculate the symbol index and look up the according complex symbol in our mapping table. if mod(numberOfBits, 4) ~= 0 error('numberOfBits must be a multiple of 4.'); end mappedSymbols = zeros(1, numberOfBits / 4); % Map bits to symbols for i = 1:4:length(x) symbolBits = x(i:i+3); symbolIndex = 2^3 * symbolBits(1) + 2^2 * symbolBits(2) + 2^1 * symbolBits(3) + 2^0 * symbolBits(4); % Mapping mappedSymbols((i - 1)/4 + 1) = mappingTable( symbolIndex + 1); end In a practical communication system the real and imaginary part of the complex symbols will now be converted to an analog signal (with an impulse shaper) and be modulated onto a radio frequency carrier. Here, we assume that D/A and A/D conversion as well as modulation and demodulation are ideal, so that we don't need to model it. Furthermore, the channel is assumed

to be ideal, i.e. flat in the frequency domain. However, we will consider noise by adding white Gaussian noise. Note that the noise power is equally distributed on the real and imaginary part of the signal. % Add white Gaussian noise snr = 20; % signal-to-noise ratio in dB meanSignalPower = (r1^2 + r2^2)/2; snr_lin = 10^(snr/10); % linear scale meanNoisePower = meanSignalPower ./ snr_lin; receivedSignal = mappedSymbols + randn(1, length(mappedSymbols)) * sqrt(meanNoisePower/2) +... 1i * randn(1, length(mappedSymbols)) * sqrt(meanNoisePower/2); Finally, for each received symbol, we determine the constellation point with the minimum distance and convert the symbol index back to a sequence of bits. % Decision and demapping receivedBits = zeros(1, numberOfBits / 4); for i = 1:length(receivedSignal) [mindiff minIndex] = min(receivedSignal(i) - mappingTable); symbolIndex = minIndex - 1; bitString = dec2bin(symbolIndex, 4); receivedBits((i-1)*4 + 1) = str2double(bitString(1)); receivedBits((i-1)*4 + 2) = str2double(bitString(2)); receivedBits((i-1)*4 + 3) = str2double(bitString(3)); receivedBits((i-1)*4 + 4) = str2double(bitString(4)); end Of course, we're interested in the number of bit errors: numberOfBitErrors = nnz( x - receivedBits ); ber = numberOfBitErrors / numberOfBits; % bit error rate disp(['SNR: ' num2str(snr) ' dB']); disp(['Bit error rate (BER): ' num2str(ber)]); And plotting transmitted and received signal yields the typical constellation diagram: figure; plot( real(receivedSignal), imag(receivedSignal), '.'); hold on; absLim = max( max(real(receivedSignal)), max(imag(receivedSignal))); xyLimits = [-absLim*1.1 absLim*1.1]; xlim( xyLimits ); ylim( xyLimits ); plot( real(mappedSymbols), imag(mappedSymbols), '.r'); hold off; xlim( xyLimits ); ylim( xyLimits ); xlabel('real part'); ylabel('imaginary part'); legend('received', 'transmitted');

I uploaded the complete source code in a whole: http://pastebin.com/MDcVLZhh

Easiest is to use a mapping table. First, generate a vector with the required constellation points. I.e., r1 = 1; % first radius r2 = 2; % second radius c = [ r1*exp(j*2*pi/8*[0..7]) r2*exp(j*2*pi/8*[0..7]) ]; The order of the constellation points in c determine the mapping from bits to symbols. Next, to modulate select a number i between 1 .. length(c) and take c(i) as the constellation point. To demodulate from received data back to symbol index, just select the closest constellation point. I.e., if the received noisy symbol is 'y': [dummy, estimated_sym] = min(y - c); WARNING: The code is untested and may require minor tweaks.

You might also like