QPSK simulation with AWGN and BER
    47 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    daniel cohen
 il 17 Dic 2021
  
    
    
    
    
    Commentato: roland
 il 11 Gen 2024
            Hey,
I have a matlab code of QPSK simulation over baseband with AWGN noise, I'm calculating BER over each SNR value and plotting it along with 
Theoretical BER.
When I'm generating SNR values in dB from 1 to 20 the code only computes simulated BER values from 0 to 10, why is this happening?
% QPSK MODULATION AND BER ESTIMATION IN AWGN CHANNEL
clc; clear all; close all;
N=1e6; % Number of bits transmited
SNRdB= 0:1:20; % SNR for simulation
SNRlin=10.^(SNRdB/10);
BER = zeros(1,length(SNRlin));% simulated BER
SER = zeros(1,length(SNRlin));% simulated SER
b1 = rand(1,N) > 0.5;
b2 = rand(1,N) > 0.5;
% QPSK symbol mapping
I = (2*b1) - 1;
Q = (2*b2) - 1;
S = I + 1j*Q; 
N0 = 1./SNRlin; % Variance
for k = 1:length(SNRdB)
    noise = sqrt(N0(k)/2)*(randn(1,N) + 1j*randn(1,N)); % AWGN noise
    sig_Rx = S + noise; % Recived signal
    % For BER calculation
    sig_I = real(sig_Rx); % I component
    sig_Q = imag(sig_Rx); % Q component
    bld_I = sig_I > 0; % I decision 
    bld_Q = sig_Q > 0; % Q decision
    b1_error = (bld_I ~= b1); % Inphase bit error
    b2_error = (bld_Q ~= b2); % Quadrature bit error
    Error_bit = sum(b1_error) + sum(b2_error); % Total bit error
    BER(k) = sum(Error_bit)/(2*N); % Simulated BER
    % For SER calculation
    error_symbol = or(b1_error, b2_error); % if bit in I or bit in Q either wrong than error
    SER(k) = sum(error_symbol)/N;
end
BER_theo = 2*qfunc(sqrt(2*SNRlin)); % Theoretical BER 
SER_theo = 2*qfunc(sqrt(2*SNRlin)) - (qfunc(sqrt(2*SNRlin))).^2; % Theoretical SER
figure(1);
semilogy(SNRdB, BER_theo,'r-')  
hold on
semilogy(SNRdB, BER,'k*')                                 
xlabel('SNR[dB]')                                    
ylabel('Bit Error Rate');                                         
legend('Theoretical', 'Simulated');
title(['Probability of Bit Error for QPSK Modulation']);
grid on;
hold off;
figure(2);
semilogy(SNRdB, SER_theo,'r-')  
hold on
semilogy(SNRdB, SER,'k*')                                 
xlabel('SNR[dB]')                                    
ylabel('Symbol Error Rate');                                         
legend('Theoretical', 'Simulated');
title(['Probability of symbol Error for QPSK Modulation']);
grid on;
hold off;
Here is my output plot:

3 Commenti
  Jerry Malone
 il 20 Ott 2022
				Here is the problem:
BER_theo = 2*qfunc(sqrt(2*SNRlin));    % Theoretical BER
The 2 coefficient should not be there in for the BER case. It should be:
BER_theo = qfunc(sqrt(2*SNRlin));      % Theoretical BER
Risposta accettata
  Ashutosh Singh Baghel
    
 il 20 Dic 2021
        
      Modificato: Ashutosh Singh Baghel
    
 il 20 Dic 2021
  
      Hi Daniel,
I understand you wish to plot BER vs. SNR on a semilog scale. If you see the value of 'BER,' it has a '0' value for 'SNR'>10. And only data points with non-zero entries are plotted because a logarithmic scale has no suitable value for a zero. For example - 
x = 1:24;
y = [2 0 0 0 2 6 11 0 22 25 27 0 25 20 14 9 4 1 0 0 0 0 0 0];
figure;
semilogy(x, y,'r*--');
figure;
semilogy(x, max(eps, y));
In the second figure, the EPS values appear as 2e-16 (of course). To get a real zero, the scale must be infinitely large.
0 Commenti
Più risposte (1)
  KAGANA SARATH
 il 1 Ago 2023
        BER versus SNR for QPSK modulation,     I have written following code.
But BER not reducing with increasing SNR in case of simulation. Plesse check the above code and rectify the error if possible.
My MATLAB code is given as follows:
% Simulate the BER versus SNR curve for QPSK under AWGN communication channel.
% Assignment 3: Problem 1
% Empty workspace and close figures
clc; clearvars; close all;
% SNR in dB: snr_db = 10*log10(snr)
snr_db = -5 : 2 : 25;
% dB to linear scale conversion: snr = 10.^(snr_db/10)
snr = 10.^(snr_db/10);
% Define parameters and different numBits values for simulation
numBits = 1000 ;
numSimulations = 100;
    %% Theoretical BER calculation for BPSK
    qpsk_ber_theoretical = 2 * erfc(sqrt(snr/2)) - ( erfc(sqrt(snr/2))).^2;
    qpsk_ber_simulations = zeros(size(snr_db));
   %% Calculate BER for each SNR value
    for j = 1:length(snr_db)
        % Repeat simulations (as random quantities are involved) for numSimulations times
        for sim = 1:numSimulations
            % Generate Random Bits (0's and 1's) of size 1XnumBits, and it is a row vector
            binaryBits_transmitted = randi([0, 1], 1, numBits);
            % Make the binary sequence length a multiple of 2 (pad with zeros if needed)
              numPaddingBits = mod(length(binaryBits_transmitted), 2);
              if numPaddingBits > 0
                binaryBits_transmitted = [binaryBits_transmitted, zeros(1, 2 - numPaddingBits)];
              end
            % Divide the binary sequence into groups of 2 bits each
            qpsk_transmitted = reshape(binaryBits_transmitted,2,[])';
            % Map each group of 2 bits to the corresponding QPSK symbol
            % Initialize QPSK symbols (complex numbers)
             qpsk_symbols = [exp(1i*0), exp(1i*pi/2), exp(1i*pi), exp(1i*3*pi/2)];
             % Define the mapping from QPSK symbols to their corresponding 2-bit binary representation
              qpsk_mapping = [0 0; 0 1; 1 0; 1 1];
             % Map binary groups to the corresponding QPSK symbol
             qpsk_modulated = qpsk_symbols (bin2dec(num2str(qpsk_transmitted)) + 1) ;
           % Energy per bit = Symbol energy / 2
           symbolEnergy = mean(abs(qpsk_modulated).^2);
           Energy_bit = symbolEnergy / 2;
           % Generate complex Gaussian noise samples 
           % Relate snr to the noise power (This is very important in this entire code)
           Noise_Power = 1 / snr(j); % This holds true as Symbol energy is always 1
           gaussian_noise = sqrt(Noise_Power) * (randn(1, numBits/2) + 1i * randn(1, numBits/2));
           % Add noise to the QPSK modulated symbols to get noisy received signal
           received_symbol = qpsk_modulated + gaussian_noise;
           %% QPSK Demodulation with threshold as pi/4 in case of QPSK modulation scheme
           % Initialize the decision regions (thresholds) for each quadrant
             threshold = pi / 4; % ±45 degrees (±π/4 radians)
           % Initialize a variable to store the demodulated symbols
            qpsk_demodulated = zeros(1, length(received_symbol));
            % Perform QPSK demodulation
           for i = 1:length(received_symbol)
              % Calculate the phase of the received signal
               phase = angle(received_symbol(i));
              % Perform threshold-based demodulation
               if phase >= -3*threshold && phase < -threshold
                qpsk_demodulated(i) = qpsk_symbols(1); % QPSK symbol at 0 degrees
               elseif phase >= -threshold && phase < threshold
                qpsk_demodulated(i) = qpsk_symbols(2); % QPSK symbol at 90 degrees
               elseif phase >= threshold && phase < 3*threshold
                qpsk_demodulated(i) = qpsk_symbols(3); % QPSK symbol at 180 degrees
               else
                qpsk_demodulated(i) = qpsk_symbols(4); % QPSK symbol at 270 degrees
              end
          end
         %% QPSK received symbols using inverse process
         qpsk_received = zeros(size(qpsk_demodulated));
         % Find the closest QPSK symbol for each demodulated symbol
         for i = 1: length(qpsk_demodulated)
             % Calculate the distance b/w the demodulated symbol and each QPSK symbol
             distances = abs(qpsk_demodulated(i) - qpsk_symbols) ;
             % Find the index of the closest QPSK symbol
             [~, index] = min(distances);
             % Convert the index to its corresponding binary representation
             binaryRepresentation = qpsk_mapping(index,:);
             % Store the binary representation in the 'originalBinarySymbols' array
              qpsk_received(2*i-1 : 2*i) = binaryRepresentation;
        end
        %% Number of bit errors
        ErrorBits = xor( binaryBits_transmitted, qpsk_received);
        Number_errorBits = sum(ErrorBits == 1); % bitErrors = sum(binaryBits ~= decodedBits)
        Bit_Error_Rate = Number_errorBits / (numBits * 2) ;
            % Store the calculated BER for this simulation
            qpsk_ber_simulations(j) = qpsk_ber_simulations(j) + Bit_Error_Rate;
        end
        % Calculate Average Bit error rate for all the simulations for this SNR value and numBits
        qpsk_simulation(j) = qpsk_ber_simulations (j) / numSimulations ;
    end
%end
disp('binaryBits_transmitted');
disp(binaryBits_transmitted);
disp('qpsk_received');
disp(qpsk_received);
disp('qpsk_ber_simulations');
disp(qpsk_ber_simulations);
disp('qpsk_ber_theoretical');
disp(qpsk_ber_theoretical);
% Plot BER versus SNR curve for different numBits values
figure;
    semilogy(snr_db, qpsk_simulation, '*-');
    hold on;
   semilogy(snr_db, qpsk_ber_theoretical, '*-');
    hold on;
xlabel('Signal-to-Noise Ratio (SNR) [dB]');
ylabel('Bit Error Rate (BER)');
title('BER vs. SNR for QPSK Modulation');
legend('Simulation', 'Theoretical'); % Add more legends if needed
grid on;
hold off;
Graph is shown below:
 Please help me in this regard
Please help me in this regard0 Commenti
Vedere anche
Categorie
				Scopri di più su QPSK in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






