Monday, October 5, 2020

Analyzing bit error rate of an audio signal through different channels

 %%%%%%%%%%% SURAJ BASTOLA %%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%% https://lnkd.in/gvdzPWX %%%%%%%%%%%%%

%%%%%%%%%% MIT183249 %%%%%%%%%%%%%%

clear all;

clc

close all;

%N = 10; % number of samples (bits) for transmission

k=1; %Ricean factor

SNR = 8; % SNR in dB

SNR1 = 10^(SNR./10); % or, SNR1 = 10^(SNR/10)

%disp(SNR1);

% Signal bit creation

[y,Fs] = audioread('C:\Users\suraj\OneDrive\Documents\MIT COLLEGE\Software Defined Radio Communication\MATLAB.wav');

Sig_Bit = dec2bin( typecast( single(y), 'uint8'), 8 ) - '0';

Sig_Bit = reshape(Sig_Bit,1,[]);

N = 512;

SignalX = Sig_Bit(20000:20000+N-1);

%Sig_Bit = num2bin(y);

%Sig_Bit = randn(1,N)>0.5;

fprintf('Signal Created');

%disp(Sig_Bit);

%BPSK symbol

raw_signal = 2*SignalX-1;

fprintf('BPSK SYMBOL');

%disp(raw_signal);

n = 1./sqrt(2)*(randn(1,N) + 1j*randn(1,N));%Noise creation(AWGN, 0dB variance )


%================== RAYLEIGH CHANNEL ================================

ch_ray = 1./sqrt(2)*(randn(1,N)+1i*randn(1,N));

% Faded signal with Rayleigh channel

Sig_fad_ray = ch_ray.* raw_signal + SNR1.*n;

%====================================================

% equalization (ideal)

Sig_fad_ray1 = Sig_fad_ray./ch_ray;

fprintf('Rayleigh Faded Signal Received at the receiver'); 

%disp(Sig_fad_ray1);

fprintf('Absolute value of Faded Signal Received at the receiver'); 

%disp(abs(Sig_fad_ray1));


%================== RICEAN CHANNEL ================================

% Ricean Channel

ch_ric = sqrt(k/(k+1))+sqrt(1/(k+1))*(1/sqrt(2))*(randn(1,N)+1j*randn(1,N));

Sign_fad_ric = ch_ric.*raw_signal+10^(-SNR/20)*n;

% equalization (ideal)

Sig_fad_ric1 = Sign_fad_ric./ch_ric;

fprintf('Faded Signal Received at the receiver'); 

%disp(Sig_fad_ric1);

fprintf('Absolute value of Faded Signal Received at the receiver'); 

%disp(abs(Sig_fad_ric1));


% receiver - hard decision decoding

 for i = 1: N

          if real(Sig_fad_ray1(i)) > 0

         Sig_ray_Rayleigh(i) = 1;

     else

         Sig_ray_Rayleigh(i) = 0;

          end          

 end

% receiver - hard decision decoding

 for i = 1: N

          if real(Sig_fad_ric1(i)) > 0

         Sig_ray_Rec(i) = 1;

     else

         Sig_ray_Rec(i) = 0;

          end

 end

% Measuring the errors: Compare original signal with

Err_num_ray1 = size(find([SignalX- Sig_ray_Rayleigh]),2);

BER_ray1 = Err_num_ray1 /N;

fprintf('Rayleigh BER = ');

disp(BER_ray1);

Recian = size(find([SignalX- Sig_ray_Rec]),2);

BER_Recian = Recian /N;

fprintf('Ricean BER= ');

disp(BER_Recian);


No comments:

Post a Comment

CHECKING WHETHER THE SYSTEM IS STABLE OR NOT

  % SURAJ BASTOLA % % ==========CHECKING WHETHER SYSTEM IS STABLE OR NOT ================== % H(z) = (2z+0.5)/(z^2+0.5z-1) b = [2 0.5]; a=[1...