0% found this document useful (0 votes)
19 views29 pages

Software Lab II

Uploaded by

bhargavaanita91
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views29 pages

Software Lab II

Uploaded by

bhargavaanita91
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 29

DEPARTMENT OF ELECTRONICS AND COMMUNICATION

ENGINEERING

UIT – RGPV BHOPAL

NAME OF COURSE: Software Lab -II


SEMESTER: V
COURSE CODE: EC 506
LIST OF EXPERIMENTS
S CO
NO.

1 To study and write a MATLAB program to plot ASK modulation. 1

2 To study and write a MATLAB program to plot FSK modulation. 1

3 To study and write a MATLAB program to plot PSK modulation. 1

4 To study and write a program to plot charge distribution of point charge and dipole 2
Using MATLAB.

5 To Generate Electromagnetic Wave using MATLAB software. 2

6 To study impedance match using MATLAB software. 3

7 To Generate CRC Code Using MATLAB 1

8 To calculate phase and group velocity using MATLAB 3


Experiment No.1

GENERATION OF ASK SIGNAL

AIM: To write a program to plot ASK modulation.

Theory- Each symbol in the message signal gives a unique amplitude to the carrier wave. There
are two types of ASK, Binary and M-ary. In Binary ASK, logic 1 is associated with certain amplitude of
carrier wave e.g. 12V and logic 0 is associated with different amplitude other than 12V e.g. 0V. In M-ary
ASK, a group of log2M bits are considered together rather than 1 bit at a time and the amplitude level is
associated with this group of bits.

Software required: MATLAB.


MATLAB code :
clc;
clear all;
close all;
x=[ 1 0 0 1 1 0 1]; % Binary Information
bp=.000001; % bit period
disp(' Binary information at Trans mitter :');
disp(x);
%XX representation of transmitting binary information as digital signal XXX
bit=[];
for n=1:1:length(x)
if x(n)==1;
se=ones(1,100);
else x(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t1=bp/100:bp/100:100*length(x)*(bp/100);
subplot(3,1,1);
plot(t1,bit,'lineWidth',2.5);grid on;
axis([ 0 bp*length(x) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('transmitting information as digital signal');
%XXXXXXXXXXXXXXXXXXXXXXX Binary-ASK modulation
XXXXXXXXXXXXXXXXXXXXXXXXXXX%
A1=10; % Amplitude of carrier signal for information 1
A2=5; % Amplitude of carrier signal for information 0
br=1/bp; % bit rate
f=br*10; % carrier frequency
t2=bp/99:bp/99:bp;
ss=length(t2);
m=[];
for (i=1:1:length(x))
if (x(i)==1)
y=A1*cos(2*pi*f*t2);
else
y=A2*cos(2*pi*f*t2);
end
m=[m y];
end
t3=bp/99:bp/99:bp*length(x);
subplot(3,1,2);
plot(t3,m);
xlabel('time(sec)');
ylabel('amplitude(volt)');
title('waveform for binary ASK modulation coresponding binary information');
%XXXXXXXXXXXXXXXXXXXX Binary ASK demodulation
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y=cos(2*pi*f*t); % carrier siignal
mm=y.*m((n-(ss-1)):n);
t4=bp/99:bp/99:bp;
z=trapz(t4,mm) % intregation
zz=round((2*z/bp))
if(zz>7.5) % logic level = (A1+A2)/2=7.5
a=1;
else
a=0;
end
mn=[mn a];
end
disp(' Binary information at Reciver :');
disp(mn);
%XXXXX Representation of binary information as digital signal which achived
%after ASK demodulation
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXX
bit=[];
for n=1:length(mn);
if mn(n)==1;
se=ones(1,100);
else mn(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t4=bp/100:bp/100:100*length(mn)*(bp/100);
subplot(3,1,3)
plot(t4,bit,'LineWidth',2.5);grid on;
axis([ 0 bp*length(mn) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('recived information as digital signal after binary ASK demodulation’);
Experiment No 2
GENERATION OF FSK SIGNAL

AIM: To write a program to plot FSK modulation.


Theory -In Frequency Shift Keying (FSK), each symbol in the message signal gives a unique
frequency to the carrier wave. There are two types of FSK, Binary and M-ary. In Binary FSK, logic 1 is
associated with certain frequency of carrier wave e.g. 50MHz and logic 0 is associated with different
frequency other than 50MHz e.g. 25MHz. In M-ary FSK, a group of log 2M bits are considered together
rather than 1 bit at a time and the frequency is associated with this group of bits.

Software required: MATLAB.


MATLAB code:
%>>>>>>>>> MATLAB code for binary FSK modulation and de-modulation >>>>>>>%
clc;
clear all;
close all;
x=[ 1 0 0 1 1 0 1]; % Binary Information
bp=.000001; % bit period
disp(' Binary information at Trans mitter :');
disp(x);
%XX representation of transmitting binary information as digital signal XXX
bit=[];
for n=1:1:length(x)
if x(n)==1;
se=ones(1,100);
else x(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t1=bp/100:bp/100:100*length(x)*(bp/100);
subplot(3,1,1);
plot(t1,bit,'lineWidth',2.5);grid on;
axis([ 0 bp*length(x) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('transmitting information as digital signal');
%XXXXXXXXXXXXXXXXXXXXXXX Binary-FSK modulation
XXXXXXXXXXXXXXXXXXXXXXXXXXX%
A=5; % Amplitude of carrier signal
br=1/bp; % bit rate
f1=br*8; % carrier frequency for information as 1
f2=br*2; % carrier frequency for information as 0
t2=bp/99:bp/99:bp;
ss=length(t2);
m=[];
for (i=1:1:length(x))
if (x(i)==1)
y=A*cos(2*pi*f1*t2);
else
y=A*cos(2*pi*f2*t2);
end
m=[m y];
end
t3=bp/99:bp/99:bp*length(x);
subplot(3,1,2);
plot(t3,m);
xlabel('time(sec)');
ylabel('amplitude(volt)');
title('waveform for binary FSK modulation coresponding binary information');
%XXXXXXXXXXXXXXXXXXXX Binary FSK demodulation
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y1=cos(2*pi*f1*t); % carrier siignal for information 1
y2=cos(2*pi*f2*t); % carrier siignal for information 0
mm=y1.*m((n-(ss-1)):n);
mmm=y2.*m((n-(ss-1)):n);
t4=bp/99:bp/99:bp;
z1=trapz(t4,mm) % intregation
z2=trapz(t4,mmm) % intregation
zz1=round(2*z1/bp)
zz2= round(2*z2/bp)
if(zz1>A/2) % logic lavel= (0+A)/2 or (A+0)/2 or 2.5 ( in this case)
a=1;
else(zz2>A/2)
a=0;
end
mn=[mn a];
end
disp(' Binary information at Reciver :');
disp(mn);
%XXXXX Representation of binary information as digital signal which achived
%after demodulation
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX
bit=[];
for n=1:length(mn);
if mn(n)==1;
se=ones(1,100);
else mn(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t4=bp/100:bp/100:100*length(mn)*(bp/100);
subplot(3,1,3)
plot(t4,bit,'LineWidth',2.5);grid on;
axis([ 0 bp*length(mn) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('recived information as digital signal after binary FSK demodulation');
%>>>>>>>>>>>>>>>>>>>>>>>>>> end of program
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>%
Experiment-3
GENERATION OF PSK SIGNAL

AIM: To study and write a program to plot PSK modulation.

Theory -In Phase Shift Keying (PSK), each symbol in the message signal gives a unique phase shift to
the carrier wave. There are two types of PSK, Binary and M-ary. In Binary PSK, logic 1 is associated
with certain phase shift of carrier wave e.g. 90 ° and logic 0 is associated with different phase shift other
than 90° e.g. 0°. In M-ary PSK, a group of log 2M bits are considered together rather than 1 bit at a time
and the phase shift is associated with this group of bits.

Software required: MATLAB.

MATLAB code:
%>>>>>>>>> MATLAB code for binary PSK modulation and de-modulation >>>>>>>%
clc;
clear all;
close all;
x=[ 1 0 0 1 1 0 1]; % Binary Information
bp=.000001; % bit period
disp(' Binary information at Trans mitter :');
disp(x);
%XX representation of transmitting binary information as digital signal XXX
bit=[];
for n=1:1:length(x)
if x(n)==1;
se=ones(1,100);
else x(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t1=bp/100:bp/100:100*length(x)*(bp/100);
subplot(3,1,1);
plot(t1,bit,'lineWidth',2.5);grid on;
axis([ 0 bp*length(x) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('transmitting information as digital signal');
%XXXXXXXXXXXXXXXXXXXXXXX Binary-PSK modulation
XXXXXXXXXXXXXXXXXXXXXXXXXXX%
A=5; % Amplitude of carrier signal
br=1/bp; % bit rate
f=br*2; % carrier frequency
t2=bp/99:bp/99:bp;
ss=length(t2);
m=[];
for (i=1:1:length(x))
if (x(i)==1)
y=A*cos(2*pi*f*t2);
else
y=A*cos(2*pi*f*t2+pi); %A*cos(2*pi*f*t+pi) means -A*cos(2*pi*f*t)
end
m=[m y];
end
t3=bp/99:bp/99:bp*length(x);
subplot(3,1,2);
plot(t3,m);
xlabel('time(sec)');
ylabel('amplitude(volt)');
title('waveform for binary PSK modulation coresponding binary information');
%XXXXXXXXXXXXXXXXXXXX Binary PSK demodulation
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y=cos(2*pi*f*t); % carrier siignal
mm=y.*m((n-(ss-1)):n);
t4=bp/99:bp/99:bp;
z=trapz(t4,mm) % intregation
zz=round((2*z/bp))
if(zz>0) % logic level = (A+A)/2=0
%becouse A*cos(2*pi*f*t+pi) means -A*cos(2*pi*f*t)
a=1;
else
a=0;
end
mn=[mn a];
end
disp(' Binary information at Reciver :');
disp(mn);
%XXXXX Representation of binary information as digital signal which achived
%after PSK demodulation
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
bit=[];
for n=1:length(mn);
if mn(n)==1;
se=ones(1,100);
else mn(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t4=bp/100:bp/100:100*length(mn)*(bp/100);
subplot(3,1,3)
plot(t4,bit,'LineWidth',2.5);grid on;
axis([ 0 bp*length(mn) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('recived information as digital signal after binary PSK demodulation');
%>>>>>>>>>>>>>>>>>>>>>>>>>> end of program
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>%
Experiment-4
GENERATION OF CHARGE DISTRIBUTION OF POINT
CHARGE AND ELECTRIC DIPOLE

AIM- To study and write a program to plot charge distribution of point charge and dipole

Theory -A dipole is a separation of opposite electrical charges and it is quantified by an electric dipole
moment. The electric dipole moment associated with two equal charges of opposite polarity separated by a
distance, d is defined as the vector quantity having a magnitude equal to the product of the charge and the
distance between the charges and having a direction from the negative to the positive charge along the line
between the charges.It is a useful concept in dielectrics and other applications in solid and liquid materials.
These applications involve the energy of a dipole and the electric field of a dipole.
% Electric Field Plots for Different Charge Distributions
clc;
clear;
close all;

% Define constants
k = 8.99e9; % Coulomb's constant (N·m²/C²)
epsilon_0 = 8.854e-12; % Permittivity of free space (C²/N·m²)

% Define grid for plotting


x = linspace(-10, 10, 20); % X-axis range
y = linspace(-10, 10, 20); % Y-axis range
[X, Y] = meshgrid(x, y);

% ---- 1. Point Charge ----


Q = 1e-9; % Charge (C)
r = sqrt(X.^2 + Y.^2); % Distance from the charge at origin

% Electric field for point charge


Ex_point = k * Q * X ./ (r.^3);
Ey_point = k * Q * Y ./ (r.^3);

% Plot Electric Field for Point Charge


figure;
subplot(2,2,1);
quiver(X, Y, Ex_point, Ey_point, 'r');
title('Electric Field of a Point Charge');
axis equal;
xlabel('x');
ylabel('y');
xlim([-10 10]);
ylim([-10 10]);
hold on;
plot(0, 0, 'bo', 'MarkerFaceColor','b'); % Mark the charge at the origin

% ---- 2. Dipole ----


% Positive and negative charges
Q1 = 1e-9; % Positive charge (C)
Q2 = -1e-9; % Negative charge (C)
d = 2; % Distance between charges
r1 = sqrt((X + d/2).^2 + Y.^2); % Distance from positive charge
r2 = sqrt((X - d/2).^2 + Y.^2); % Distance from negative charge
% Electric field for dipole (superposition of fields from both charges)
Ex_dipole = k * Q1 * (X + d/2) ./ (r1.^3) - k * Q2 * (X - d/2) ./ (r2.^3);
Ey_dipole = k * Q1 * Y ./ (r1.^3) - k * Q2 * Y ./ (r2.^3);

% Plot Electric Field for Dipole


subplot(2,2,2);
quiver(X, Y, Ex_dipole, Ey_dipole, 'b');
title('Electric Field of a Dipole');
axis equal;
xlabel('x');
ylabel('y');
xlim([-10 10]);
ylim([-10 10]);
hold on;
plot(d/2, 0, 'ro', 'MarkerFaceColor','r'); % Positive charge
plot(-d/2, 0, 'go', 'MarkerFaceColor','g'); % Negative charge
Experiment No.5
GENERATION OF ELECTROMAGNETIC WAVE

AIM: Generate Electromagnetic Wave using MATLAB software.


Software Required: MATLAB software
Theory:
The electromagnetic radiation refers to the waves of the electromagnetic field,
propagating through space, carrying electromagnetic radiant energy. It includes
radio waves, microwaves, infrared, light, ultraviolet, X-rays, and gamma rays. All
of these waves form part of the electromagnetic spectrum. Electromagnetic waves
are typically described by any of the following three physical properties:
frequency (f), wavelength (λ), or intensity (I). Light quanta are typically
described by frequency (f), wavelength (λ).

Program:
function [] = EB_field_propagation_animation()
% EB_dynamic_fields_animation : function to create
% an animation of a dynamic electromagnetic field.
%
% Author & support nicolas.douillet (at)
free.fr, 2007-2021.step = 0.05*pi; % the signal
step / resolution
phase = 2*pi:-step:0; % phase vector
nperiod = 1.5; % the number of periods for the
signalstime_lapse = 0.1; % the
animation time lapse
title_text = 'Electromagnetic field propagation (planar
waves)';filename =
'EB_dynamic_fields_animation.gif';
title_on = true;
% Display
settingsh =
figure;
set(h,'Position',get(0,'ScreenSize'));
set(gcf,'Color',[0 0
0]);axis tight
manual;
az = 21; %
azimut el = 40;
% elevation
for k = 1:length(phase)
signal = EB_field(nperiod,step,phase(k));

pE = plot3(signal(1,:,1)',signal(2,:,1)',signal(3,:,1)','Color',[1 0 1],'Linewidth',2); hold


on;
pH = plot3(signal(1,:,2)',signal(2,:,2)',signal(3,:,2)','Color',[0 1 1],'Linewidth',2); hold
on;

stem3(signal(1,1:2:end,1)',signal(2,1:2:end,1)',signal(3,1:2:end,1)','.','Color',[1 0
1],'Linewidth',2);
stem(signal(1,1:2:end,2)',signal(2,1:2:end,2)','.','Color',[0 1 1],'Linewidth',2);
line([signal(1,1,1),signal(1,end,1)],[0,0],[0,0],'Color',[0 1 0]), hold on;
line([signal(1,1,1),signal(1,1,1)],[0,1],[0,0],'Color',[0 1 0]), hold on;

line([signal(1,1,1),signal(1,1,1)],[0,0],[0,1],'Color',[0 1 0]), hold on;

legend([pE, pH],{'Electric field','Magnetic field'},'Location',


'NorthEast','Color',[0 00],'TextColor',[1 1
1],'FontSize',14,'EdgeColor',[1 1 1]);

set(gca,'Color',[0 0
0]);view([az,el]);
grid off, axis off;

if title_on
title(title_text,'Color',[1 1
1],'FontSize',16);end

drawnow;

frame =
getframe(h); im =
frame2im(frame);
[imind,cm] = rgb2ind(im,256);
% Write to the .gif
fileif k == 1
imwrite(imind,cm,filename,'gif',
'Loopcount',Inf,'DelayTime',time_lapse);else
imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',tim
e_lapse); end

clf

;end
end % EB_dynamic_fields_animation
function [signal] = EB_field(nperiod, step, phase)
%
% Author & support nicolas.douillet (at) free.fr,
2007-2021.t = -nperiod*2*pi:step:nperiod*2*pi;
s = sin(t+phase);
signal =
[t;zeros(1,length(t));s];R =
@(r)[1,0,0
0,cos(r),-sin(r)
0,sin(r),cos(r)];

signal(:,:,2) = R(-
pi/2)*signal(:,:,1);end
Experiment No.6
IMPEDANCE MATCHING
Aim: To study impedance match using MATLAB software.
Software Required: MATLAB software

Theory: Impedance matching is the process of designing the antenna's input


impedance (ZL) or matching it to the corresponding RF circuitry's output
impedance (ZO), which would be 50 Ω in most cases. A perfect match is obtained
when ZL = ZO in eq 2 which gives Γ a value of zero, andthe SWR becomes unity
in eq 1.

Program:
clc;close all;clear all;format
long;
Z0=100;sm1=smithchart;ho
l d all;ZL=200-1j*100;
f0=5e8; % Hz
gamma_L=(ZL-
Z0)/(ZL+Z0);
% show ZL on Smith chart adding text
showing valuesif imag(ZL)<0
sign1='
-';else
sign1='
+';end
hold all;plot(real(gamma_L),imag(gamma_L),'ro','LineWidth',1.5);
str1=['ZL =' num2str(real(ZL)) sign1 'j' num2str(abs(imag(ZL))) '
\rightarrow']; text(real(gamma_L),imag(gamma_L)
+.01,str1,'Color','blue',
'FontSize',20,'HorizontalAlignment','right','VerticalAlignment','mid
dle'); RL=real(ZL);XL=imag(ZL);
if abs(real(ZL/Z0))>=1 % ZL
inside 1+jxdisp(' ZL inside 1+jx');
B1=1/(RL^2+XL^2)*(XL+(RL/Z0)^.5*(RL^2+XL^2-
Z0*RL)^.5) B2=1/(RL^2+XL^2)*(XL-
(RL/Z0)^.5*(RL^2+XL^2-Z0*RL)^.5)
X1=1/B1+XL*Z0/RL-Z0/(B1*RL) ;
X2=1/B2+XL*Z0/RL-
Z0/(B2*RL)
elseif abs(real(ZL/Z0))<=1 % ZL
outside 1+jxdisp(' ZL outside 1+jx');
X1=(RL*(Z0-RL))^.5-XL; X2=-(RL*(Z0-
RL))^.5-XL
B1=1/Z0*((Z0-RL)/RL)^.5;
B2=-1/Z0*((Z0-RL)/RL)^.5
end

% the 1st match solution


[C1
ctype]=B2LC(B1,f0) [L1
ltype]=X2LC(X1,f0)
% and the 2nd
solution [L2
ctype]=B2LC(B2,f
0) [C2
ltype]=X2LC(X2,f
0)

OUTPUT:
Experiment-7
CRC MATLAB CODING

AIM to plot the CRC code on MATLAB

CRC8 MATLAB Code

Following code is CRC matlab code for CRC8 polynomials used widely in ethernet and wireless
standards(wimax,wlan etc).

Input = [0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0, ...


0,1,1,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,0,1,1,0,0,1,0,0,0,0,0,0, ...
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; % Input values.
M1=Input; G1 = [1,0,0,0,0,0,1,1,1];
mL = length(M1);
gL = length(G1);
count = 0;
while((mL-count) >= gL)
msg9 = M1(1:gL);
rem = mod((msg9 + G1),2)
M1(1:gL) = rem;
j=1;
shft = 0;
while(j<=gL)
if(rem(j)~=0)
break;
else shft =
j; j = j + 1;
end
end
count = count + shft;
M1(1:shft) = [];
end
j = 0;
value = 0;
chksuml = length(M1);
for j = 1:chksuml % convert binary to decimal
if(M1(j) == 1)
value = value + (2^(chksuml-j));
end
end
dec2hex(value)
% decimal to hex CRC8 output
OUTPUT in MATLAB Command Window

CRC MATLAB Code for CRC32

Following code is CRC matlab code for CRC32 polynomials.

function Output = CRC_gen(Input) GenPoly = [1 1 1 0 1 1 0 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0];


%G(x)=x32+x26+x23+x22+x16+x12+ x11+ x10+ x8+ x7+ x5+ x4+ x2+x+1
BufferInit = ones(1,32);
Input = [ Input
zeros(1,32)]; for i =
1:length(Input) temp1 =
BufferInit(end); temp2 =
temp1*GenPoly;
for j = length(BufferInit):-1:2
BufferInit(j) = xor(temp2(j), BufferInit(j-1));
end
BufferInit(1) = xor(Input(i), temp2(1));
end
Output = fliplr(BufferInit)
Experiment-8
PHASE AND GROUP VELOCITY CALCULATION AT 9GHz

Aim: To calculate phase & group velocity using MATLAB software.


Software Required: MATLAB software

Theory: Waves can be in the group and such groups are called wave packets, so
the velocity with a wave packet travels is called group velocity. The velocity with
which the phase of a wave travels is called phase velocity. The relation between
group velocity and phase velocity are proportionate. The phase velocity of a wave
is the rate at which the wave propagates in some medium. This is the velocity at
which the phase of any one frequency component of the wave travels. The group
velocity of a wave is the velocity with which the overall envelope shape of the
wave's amplitudes—known as the modulation or envelope of the wave—
propagates through space.

Program:

% phase velocity, group velocity X band .9inx.4in WR90


waveguide at 9GHzclear all;close all;clc
e0=8.854e-12
% [F/m] free space permittivity mu0=4*pi*1e-7
[H/m] free space permeabilityf0=9e9; %
choose operating frequency [Hz] b_in=.9

% in, X band WR-90


a_in=0.4
% in
er=2.54;mur=1;
% Rexolite filler
er(3GHz)=er(9GHz)=2.54
a=a_in*25.40001e-3
b=b_in*25.40001e-3
c0=299792458;
% m/s
v_propagation=c0/er^.5
% propagation velocity k_wave=2*pi*f0*er^.5/c0
% waev number constant N=2;M_range=[0:1:N];N_range=[0:1:N];
% finding all possible modes below N Mfor k=[1:1:numel(M_range)]
for s=[1:1:numel(N_range)]
fc(k,s)=c0/(2*pi*er^.5)*((M_range(k)*pi/a)^2+(N_range(s)*pi/b)
^2).^.5;
end
fc
% cut-offs, NxM format fMN=zeros(max(M_range)
+1,max(N_range)+1,3); fMN(:,:,3)=fc;
fMN(:,:,2)=meshgrid(M_range,N_r
ange);
fMN(:,:,1)=meshgrid(M_range,N_r
ange)';L=[0 0 0];
for
k=1:1:(M_range(end)+
1)
for
s=1:1:(N_range(end)+1
)

L=[L;fMN(k,s,1) fMN(k,s,2) fMN(k,s,3)];


end
L=uint64(L)
k_all_nulls=[];
% TEM doesn't propagate inside rectangular waveguides, removingall null lines
off L
for k=1:1:size(L,1)
if L(k,1)==0 && L(k,2)==0 &&L(k,3)==0
k_all_nulls=[k_all_nu
lls k]end
end
L(k_all_nulls,:
)=[]
fc=L(:,3);
% sorting cut-offs in frequency ascending order
[n,v]=sort(fc);
L=L(v,:)
fc_sorted=L(:,3)
% Since the solution manual has 2 errors, one being the actual carrierfrequency
to use,
% let's calculate the propagation constants for all considered propagation
modes:kc=[];
for
k=1:1:numel(f
c)
L2=double(L(k
,:));
kc=[kc;
((L2(1)*pi/a)^2+(L2(2)*pi/b)^2)^.5];
end
beta=(k_wave^2-kc.^2).^.5
% modes that get through, for a given input frequency f0
% f0=f_cutoff doesn't get through, it has to be f0>f_cutoff
% safety_factor=1 % safety_factor=1 no safety band, 1.5 at least
% half carrier above
cutoff ..k=1;
while L(k,3)<=f0 &&
k<size(L,1)k=k+1;
en
dk
L_through=L([k:end],:)
fc_through=fc_sorted([k:end],:)
[n3,v3]=find(imag(beta)==0)
beta=beta(n3,:) % take only the modes that propagate
% instead of
% beta=beta([1 2],:)
% let's build a beta variable for each
propagating modefor k=1:1:numel(n3)
str1=['beta_' num2str(L(n3(k),1)) num2str(L(n3(k),2)) '='
num2str(beta(n3(k)))];evalin('base',str1)
end
% phase velocities or propagation velocities of each propagating mode

%vp=2*pi*f0/be
ta
for
k=1:1:numel(n3)
str1=['vp_' num2str(L(n3(k),1)) num2str(L(n3(k),2)) '='
num2str(2*pi*f0/beta(n3(k)))];evalin('base',str1)
end
% group velocities of each propagating
modefor k=1:1:numel(n3)
str1=['vg_' num2str(L(n3(k),1)) num2str(L(n3(k),2)) '='...
num2str(beta(n3(k))/(k_wave*(mu0*e0*mur*er)^.5))];
evalin('base',str
1)end
RESULT:

You might also like