Thursday, October 8, 2020

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 0.5 -1];

sys = tf(b,a);

p = pole(sys);

z = zero(sys);

fprintf("Poles are = %d\n",p);

if(p<=1)

    fprintf("System is stable\n");

else

    fprintf("System is unstable\n");

end

fprintf("Zeros are = %d\n",z);

subplot(2,1,1)

impz(b,a)

subplot(2,1,2)

zplane(b,a)



Comparing Single and Multiple KNife Edge Diffraction with Epstein-Peterson Method

 







%======= SURAJ BASTOLA ========================%


%========== Assuming two obstacles with one obstacle loss equal to 1/3 of another Obstacle Loss ==========

clc;

u=-4:0.001:4;

for (i=1:length(u))

if (u(i)<=-1)

    f1(i) = 0;   

elseif(u(i)<=0)

    f1(i) = 0.5-0.62*u(i);  

elseif(u(i)<=1)

    f1(i) = 0.5*exp(-0.95*u(i));   

elseif(u(i)<=2.4)

    f1(i) = 0.4-(sqrt(0.1184-(0.38-0.1*u(i))^2));       

else

    f1(i) = (0.225079)./u(i);     

end

end

% =========== Single Knife-edge Diffraction Loss==============

L1 = 20*log10(abs(f1)); 

disp(L1);

subplot(2,1,1)

plot(u,L1,'g')

grid on

title('Single Knife-Edge Diffraction')

% ================= Multiple Knife Edge Diffraction with Epstein-Peterson Method======================

nobstac = 2;

Lsum = L1+(L1/3);

L2 = (Lsum)+(nobstac*3.9); 

disp(L2);

subplot(2,1,2)

plot(u,L2,'r')

grid on

title('Multiple Knife Edge Diffraction')

xlabel('Fresnel Diffraction Parameter')

ylabel('Diffraction Loss (dB)')



Wednesday, October 7, 2020

ESTIMATING MULTIPLE DIFFRACTION LOSS WITH EPSTEIN-PETERSON AND FOOSE CORECTION

 % =================== SURAJ BASTOLA% ===========

% ============== Calculating Diffraction Loss ==============

clc;

clear all;

close all;

d1 = 1000;

d2 = 3480;

d3 = 1830;

d4 = 2650;

d5 = 3280;

d6 = 1200;

c = 3E8;

f = 8E8;

l = c/f;

fprintf('Wavelength = %d\n',l);

h1 = sqrt(l*d1*d2/(d1+d2));

h2 = sqrt(l*d3*d4/(d3+d4));

h3 = sqrt(l*d5*d6/(d5+d6));

fprintf('Height of knife edge above LOS of knife edge = %d %d %d \n',h1,h2,h3);

% =========== Obstacle 1 ==================

v1 = h1*(sqrt(2*(d1+d2)/(l*d1*d2)));

fprintf('First Fresnel-Kirchoff value = %d\n',v1);

if (v1<=-1)

    f1 = 0;   

elseif(v1<=0)

    f1 = 0.5-0.62*v1;  

elseif(v1<=1)

    f1 = 0.5*exp(-0.95*v1);   

elseif(v1<=2.4)

    f1 = 0.4-(sqrt(0.1184-(0.38-0.1*v1)^2));   % It is our desired equation as v = 1.414214   

else

    f1 = (0.225079)./v1;        

end

fprintf('Diffraction Loss =%d/n',f1); % Diffraction Loss

y1 = (abs(f1))^2;

G1 = 10* log10(y1); % Diffraction Loss in dB

fprintf('Total Diffraction Loss for X = %d\n',G1);

%======================Obstacle 2 =====================================

v2 = h2*(sqrt(2*(d3+d4)/(l*d3*d4)));

fprintf('First Fresnel-Kirchoff value = %d\n',v2);

%%%%%% Calculating Diffraction LOss in dB %%%%%%%%%%

if (v2<=-1)

    f2 = 0;   

elseif(v2<=0)

    f2 = 0.5-0.62*v2;  

elseif(v2<=1)

    f2 = 0.5*exp(-0.95*v2);   

elseif(v2<=2.4)

    f2 = 0.4-(sqrt(0.1184-(0.38-0.1*v2)^2));   % It is our desired equation as v = 1.414214   

else

    f2 = (0.225079)./v2;        

end

fprintf('Diffraction Loss =%d/n',f1); % Diffraction Loss

y2 = (abs(f2))^2;

G2 = 10* log10(y2); % Diffraction Loss in dB

fprintf('Total Diffraction Loss for X = %d\n',G2);

%======================Obstacle 3 =====================================

v3 = h3*(sqrt(2*(d5+d6)/(l*d5*d6)));

fprintf('First Fresnel-Kirchoff value = %d\n',v3);

%%%%%% Calculating Diffraction LOss in dB %%%%%%%%%%

if (v3<=-1)

    f3 = 0;   

elseif(v3<=0)

    f3 = 0.5-0.62*v3;  

elseif(v3<=1)

    f3 = 0.5*exp(-0.95*v3);   

elseif(v3<=2.4)

    f3 = 0.4-(sqrt(0.1184-(0.38-0.1*v3)^2));   % It is our desired equation as v = 1.414214   

else

    f3 = (0.225079)./v3;        

end

fprintf('Diffraction Loss =%d/n',f3); % Diffraction Loss

y3 = (abs(f3))^2;

G3 = 10* log10(y3); % Diffraction Loss in dB

fprintf('Total Diffraction Loss for X = %d\n',G3);

%======================Epstein Peterson Method with Foose Correction=====================================

nobst = 3;

L = G1+G2+G3+(nobst*3.91);

fprintf("Total diffraction Loss is %d\n", L);

Tuesday, October 6, 2020

RECORDING AND RETRIEVING AUDIO SIGNAL




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

%%%  RECORDING AND SAVING RECORDED AUDIO %%%%%%


% =======================Recording Audio and Saving it to some location================

audio = audiorecorder(8000,8,1); % y = audiorecorder(Fs,nbits,channels) 

fprintf('start speaking\n')


%%%% Stopping record after 10 seconds %%%%%%%%

recordblocking(audio,10); % recordblocking(recorderObj, length)

fprintf('End of recording\n')


%%%%% Getting data from audiorecorder Object and saving it to specified folder location %%%%%%%%%%%

myrec= getaudiodata(audio); % y = getaudiodata(recorder)

audiowrite('C:\Users\suraj\OneDrive\Documents\MIT COLLEGE\Software Defined Radio Communication\MATLAB COding\audioRecorded.wav', myrec, 8000);

fprintf('successfully saved the recorded audio');


% ========================Loading recorded audio by retrieving from saved location ===================

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

sound(y,8000); % Playing retrieved audio

fprintf('successfully played the retrieved recorded audio\n')


% ===== Plotting the audio %%%%%%%%%%%

plot(y)

title('Recorded Audio of 10 seconds')



Checking orthogonality

 


% %%%%% Orthogonality %%%%%%%%%%

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

N = 4;

df = 2;

f = 100:df:20+(N-1)*df;

T = 1/df; % different values of symbol duration

t = linspace(0,T,1000);

x = zeros(N, length(t));

for i = 1:length(f)

    x(i,:) = sin(2*pi*f(i)*t);

    subplot(N*2,1,i);

    plot(t,x(i,:));

end

for i = 1:N

    for j = i+1:N

        if i==1

            subplot(N*2,1,N+j);

            plot(t,x(i,:).*x(j,:));            

        end

        fprintf("Correlation(f%d,f%d) = %f \n",i,j,mean(x(i,:)),x(j,:));

    end

end




RICEAN AND RAYLEIGH CHANNEL FADING

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

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

%%%%%%%%% RICEAN AND RAYLEIGH SIGNAL FADING %%%%%%%%%


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');

subplot(2,2,1)

plot(y)

title('Original Audio Signal')

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');

subplot(2,2,2)

plot(raw_signal)

title('Raw BPSK Signal')

%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;

subplot(2,2,3)

plot(Sig_fad_ray)

title('Faded Rayleigh Signal')

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

% 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));

subplot(2,2,4)

plot(Sig_fad_ric1)

title('Faded Ricean Signal')


% 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);


CYCLIC PREFIX FOR ERROR CONTROLLING


 %%%%%%%%%% Cyclic Prefix %%%%%%%%%%

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

M = 8; % for 8 BPSK

N = 64;% this means we are using 64 point FFT/IFFT

data = randi(M,1,N)-1;

subplot(411);

myplot(stem(data),'Data',3);

X = pskmod(data,M);

figure(2);

subplot(111);

myplot(plot(X,'o'),'8PSK',2);

% IFFT with real result for Baseband 

% for broad band go directly to line 17 from 10 with code x = ifft(X, N);

X1 = X;

X2 = conj(X(N:-1:2));

X1(1) = real(X(1));

X = [X1, imag(X(1)), X2];

x = ifft(X, N*2);

figure(1)

subplot(412);

myplot(plot(1:128,x),'IFFT', 1);

% add circular prefix

delay = 10;

xt = [x(2*N-delay+1:2*N),x];

subplot(413);

myplot(plot(1:(2*N+delay),xt),'CP',2);

hold on

myplot(plot(1+delay:(2*N+delay),x),'OFDM',1);


% remove Cyclic Prefix

r = xt((1+delay):(2*N+delay));

%fft

r2 = fft(r,N*2);

% undo complex number modification

r3 = r2(1:N);

r3(1) = r2(1)+1i*r2(N+1);

data2 = pskdemod(r3,M);

subplot(414);

myplot(stem(data2),'Received',4);

disp([data;data2]);




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...