%                             Report (1)
%                       Eng. Samy Elsakhawy


% This program solves problem (9) sheet (1) communication systems ,
% BY: Sherif Rofael , 3rd year comm. and electronics , sec :3

% Note : you can change any of the problem inputs (givens).

% please download this program from the link:
% http://vbsherif.members.easyspace.com/comm/comm.zip
clc
clear
si=10^-8 ;
k=1.38*10^-23;
kb=1.288*10^-12;
snro=50;
Ta=77.7;
G=100;
stages=3;

choice1=input('Si= -50 dbm , would u like to change it? (y/n)','s');
if choice1=='y'
    choice=menu('In "nano Watts" or "Dbm" ?' ,'Nano Watts','Dbm');
        if choice==1 
            si=input('Input "Si" in "nano watts = watt *10^-9" ? Si=');
            si=si*10^-9;
        end
        if choice==2 
            si=input('Input "Si" in "dbm" ? Si=');
            si=(10^(si/10))*10^-3;
        end
end

choice2=input('SNRo= 17 db = 50 (ratio), would u like to change it? (y/n)','s');
if choice2=='y'
    choice=menu('In "ratio" or "Db" ?' ,'ratio','Db');
        if choice==1 
            snro=input('Input "SNRo" as ratio ? SNRo=');
        end
        if choice==2 
            snro=input('Input "SNRo" in "db" ? SNRo=');
            snro=(10^(snro/10));
        end
end

choice3=input('KB=1.288*10^-12 W/K , would u like to change it? (y/n)','s');
if choice3=='y'
    choice=menu('What will be your input ?' ,'KB','B');
        if choice==1 
            kb=input('Input "KB" in W/K ? KB=');
        end
        if choice==2 
            b=input('Input "B" in "HZ" ? B=');
            kb=b*k;
        end
end

choice4=input('Ta=77.7 K , would u like to change it? (y/n)','s');
if choice4=='y'
    Ta=input('Input "Ta" in "Kelvins" ? Ta=');
end

choice5=input('No. of stages= 3  , would u like to change it? (y/n)','s');
if choice5=='y'
    stages=input('Input "No. of stages" ? No. of stages=');
end

choice6=input('G=100 (ratio) = 20 db , would u like to change it? (y/n)','s');
if choice6=='y'
    choice=menu('I want to input G in ......' ,'Ratio','db');
        if choice==1 
            G=input('Input "G" in Ratio ? G=');
        end
        if choice==2 
            G=input('Input "G" in "db" ? G=');
            G=10^(G/10);
        end
end
si
snro;
Ta;
kb
Teq=(si/(snro*kb))-Ta;
Teq;
Feq=1+(Teq/300);
stages;
G;
co=1;

for i=1:stages
    m=G^-i;
    co=co+(m);
    con=m;
end
f=(Feq-con)/co;
if f<1 
    msgbox ('error occured , Si < (Si)min for the given SNRo !!! , which leads to F<1 ' , 'Error in o/p Noise Figure' ,'error')
end
    
F_noise_figure_of_each_stage=f
op= '  Ta       Teq          G      stages      Feq     F_noise_figure_of_each_stage '
x=[Ta Teq G stages Feq F_noise_figure_of_each_stage]
