# qamdemod

## Syntax

z = qamdemod(y,M)z = qamdemod(y,M,ini_phase)z = qamdemod(y,M,ini_phase,symbol_order)

## Description

z = qamdemod(y,M) demodulates the complex envelope y of a quadrature amplitude modulated signal. M is the alphabet size and must be an integer power of 2. The constellation is the same as in qammod. If y is a matrix with multiple rows, the function processes the columns independently.

z = qamdemod(y,M,ini_phase) specifies the initial phase of the modulated signal in radians.

z = qamdemod(y,M,ini_phase,symbol_order) specifies how the function assigns binary words to corresponding integers. If symbol_order is set to 'bin' (default), the function uses a natural binary-coded ordering. If symbol_order is set to 'gray', it uses a Gray-coded ordering.

## Examples

collapse all

### Demodulate an 8-QAM Signal

Demodulate an 8-QAM signal and plot the points corresponding to symbols 0 and 3.

Generate random 8-ary data symbols.

data = randi([0 7],1000,1); 

Apply 8-QAM with an initial phase of /8.

txSig = qammod(data,8,pi/8); 

Pass the modulated signal through an AWGN channel.

rxSig = awgn(txSig,18,'measured'); 

Demodulate the received signal using an initial phase of /8.

rxData = qamdemod(rxSig,8,pi/8); 

Generate the reference constellation points.

refpts = qammod((0:7)',8,pi/8); 

Plot the received signal points corresponding to symbols 0 and 3 and overlay the reference constellation. Only the received data corresponding to those symbols is displayed.

plot(rxSig(rxData==0),'g.'); hold on plot(rxSig(rxData==3),'c.'); plot(refpts,'r*') text(real(refpts)+0.1,imag(refpts),num2str((0:7)')) xlabel('In-Phase') ylabel('Quadrature') legend('Points corresponding to 0','Points corresponding to 3', ... 'Reference Constellation','location','nw'); 

### Estimate Bit Error Rate for 64-QAM in AWGN

Demodulate a noisy 64-QAM signal and estimate the bit error rate (BER) for a range of Eb/No values. Compare the BER estimate to theoretical values.

Set the simulation parameters.

M = 64; % Modulation order k = log2(M); % Bits per symbol EbNoVec = (5:15)'; % Eb/No values (dB) numSymPerFrame = 100; % Number of QAM symbols per frame 

Initialize the results vector.

berEst = zeros(size(EbNoVec)); 

The main processing loop executes the following steps:

• Generate binary data and convert to 64-ary symbols

• QAM modulate the data symbols

• Pass the modulated signal through an AWGN channel

• Convert the demoduated symbols into binary data

• Calculate the number of bit errors

The while loop continues to process data until either 200 errors are encountered or 1e7 bits are transmitted.

for n = 1:length(EbNoVec) % Convert Eb/No to SNR snrdB = EbNoVec(n) + 10*log10(k); % Reset the error and bit counters numErrs = 0; numBits = 0; while numErrs < 200 && numBits < 1e7 % Generate binary data and convert to symbols dataIn = randi([0 1],numSymPerFrame,k); dataSym = bi2de(dataIn); % QAM modulate using 'Gray' symbol mapping txSig = qammod(dataSym,M,0,'gray'); % Pass through AWGN channel rxSig = awgn(txSig,snrdB,'measured'); % Demodulate the noisy signal rxSym = qamdemod(rxSig,M,0,'gray'); % Convert received symbols to bits dataOut = de2bi(rxSym,k); % Calculate the number of bit errors nErrors = biterr(dataIn,dataOut); % Increment the error and bit counters numErrs = numErrs + nErrors; numBits = numBits + numSymPerFrame*k; end % Estimate the BER berEst(n) = numErrs/numBits; end 

Determine the theoretical BER curve using berawgn.

berTheory = berawgn(EbNoVec,'qam',M); 

Plot the estimated and theoretical BER data. The estimated BER data points are well aligned with the theoretical curve.

semilogy(EbNoVec,berEst,'*') hold on semilogy(EbNoVec,berTheory) grid legend('Estimated BER','Theoretical BER') xlabel('Eb/No (dB)') ylabel('Bit Error Rate')