Software Lab II
Software Lab II
ENGINEERING
4 To study and write a program to plot charge distribution of point charge and dipole 2
Using MATLAB.
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.
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.
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²)
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));
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;
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
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
OUTPUT:
Experiment-7
CRC MATLAB CODING
Following code is CRC matlab code for CRC8 polynomials used widely in ethernet and wireless
standards(wimax,wlan etc).
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:
%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: