0% found this document useful (0 votes)
42 views56 pages

Delete DP Manual

The document provides Python scripts for designing and analyzing various digital communication systems including: 1) Low pass and band pass filters using Butterworth filters and plotting the frequency response. 2) AM and FM modulation to generate modulated signals and plot the carrier, modulating and modulated waves. 3) A fiber optic link to calculate the numerical aperture, acceptance angle, and relative index difference from user input refractive indices. 4) BPSK modulation over a Rayleigh fading channel to simulate the bit error rate and compare it to theoretical calculations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views56 pages

Delete DP Manual

The document provides Python scripts for designing and analyzing various digital communication systems including: 1) Low pass and band pass filters using Butterworth filters and plotting the frequency response. 2) AM and FM modulation to generate modulated signals and plot the carrier, modulating and modulated waves. 3) A fiber optic link to calculate the numerical aperture, acceptance angle, and relative index difference from user input refractive indices. 4) BPSK modulation over a Rayleigh fading channel to simulate the bit error rate and compare it to theoretical calculations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

Design Practice Lab Manual ( AY 2021-22 )

Problem Solving Techniques in Electrical


Circuits
Design Practice Lab Manual ( AY 2021-22 )

Design, simulate and implement an


Active lowpass and bandpass filter
Design Practice Lab Manual ( AY 2021-22 )

#################################################################################

# Python Script for designing low pass filter and plotting the frequency response

---------------------------------------------------------------------------------

import numpy as np

from scipy.signal import butter, lfilter, freqz

from matplotlib import pyplot as plt

def butter_lowpass(cutoff, fs, order=5):

nyq = 0.5 * fs

normal_cutoff = cutoff / nyq

b, a = butter(order, normal_cutoff, btype='low', analog=False)

return b, a

def butter_lowpass_filter(data, cutoff, fs, order=5):

b, a = butter_lowpass(cutoff, fs, order=order)

y = lfilter(b, a, data)

return y

# Filter requirements.

order = 6

fs = 30.0 # sample rate, Hz

cutoff = 3.667 # desired cutoff frequency of the filter, Hz

# Get the filter coefficients so we can check its frequency response.

b, a = butter_lowpass(cutoff, fs, order)

# Plot the frequency response.

w, h = freqz(b, a, worN=8000)

plt.subplot(2, 1, 1)

plt.plot(0.5*fs*w/np.pi, np.abs(h), 'b')

plt.plot(cutoff, 0.5*np.sqrt(2), 'ko')

plt.axvline(cutoff, color='k')

plt.xlim(0, 0.5*fs)

plt.title("Lowpass Filter Frequency Response")

plt.xlabel('Frequency [Hz]')
Design Practice Lab Manual ( AY 2021-22 )

plt.grid()

# Demonstrate the use of the filter.

# First make some data to be filtered.

T = 5.0 # seconds

n = int(T * fs) # total number of samples

t = np.linspace(0, T, n, endpoint=False)

# "Noisy" data. We want to recover the 1.2 Hz signal from this.

data = np.sin(1.2*2*np.pi*t) + 1.5*np.cos(9*2*np.pi*t) \

+ 0.5*np.sin(12.0*2*np.pi*t)

# Filter the data, and plot both the original and filtered signals.

y = butter_lowpass_filter(data, cutoff, fs, order)

plt.subplot(2, 1, 2)

plt.plot(t, data, 'b-', label='data')

plt.plot(t, y, 'g-', linewidth=2, label='filtered data')

plt.xlabel('Time [sec]')

plt.grid()

plt.legend()

plt.subplots_adjust(hspace=0.35)

plt.show()
Design Practice Lab Manual ( AY 2021-22 )

##################################################################################

# Python Script for designing bandpass filter and plotting the frequency response

----------------------------------------------------------------------------------

from scipy.signal import butter, lfilter

def butter_bandpass(lowcut, highcut, fs, order=5):

nyq = 0.5 * fs

low = lowcut / nyq

high = highcut / nyq

b, a = butter(order, [low, high], btype='band')

return b, a

def butter_bandpass_filter(data, lowcut, highcut, fs, order=5):

b, a = butter_bandpass(lowcut, highcut, fs, order=order)

y = lfilter(b, a, data)

return y

if __name__ == "__main__":

import numpy as np

import matplotlib.pyplot as plt

from scipy.signal import freqz

# Sample rate and desired cutoff frequencies (in Hz).

fs = 5000.0

lowcut = 500.0

highcut = 1250.0

# Plot the frequency response for a few different orders.

plt.figure(1)

plt.clf()

for order in [3, 6, 9]:

b, a = butter_bandpass(lowcut, highcut, fs, order=order)

w, h = freqz(b, a, worN=2000)
Design Practice Lab Manual ( AY 2021-22 )

plt.plot((fs * 0.5 / np.pi) * w, abs(h), label="order = %d" % order)

plt.plot([0, 0.5 * fs], [np.sqrt(0.5), np.sqrt(0.5)],

'--', label='sqrt(0.5)')

plt.xlabel('Frequency (Hz)')

plt.ylabel('Gain')

plt.grid(True)

plt.legend(loc='best')

# Filter a noisy signal.

T = 0.05

nsamples = T * fs

t = np.linspace(0, T, nsamples, endpoint=False)

a = 0.02

f0 = 600.0

x = 0.1 * np.sin(2 * np.pi * 1.2 * np.sqrt(t))

x += 0.01 * np.cos(2 * np.pi * 312 * t + 0.1)

x += a * np.cos(2 * np.pi * f0 * t + .11)

x += 0.03 * np.cos(2 * np.pi * 2000 * t)

plt.figure(2)

plt.clf()

plt.plot(t, x, label='Noisy signal')

y = butter_bandpass_filter(x, lowcut, highcut, fs, order=6)

plt.plot(t, y, label='Filtered signal (%g Hz)' % f0)

plt.xlabel('time (seconds)')

plt.hlines([-a, a], 0, T, linestyles='--')

plt.grid(True)

plt.axis
Design Practice Lab Manual ( AY 2021-22 )
Design Practice Lab Manual ( AY 2021-22 )

Problem Solving Techniques in


Communication Electronics
Design Practice Lab Manual ( AY 2021-22 )

Design, simulate and implement


(a) AM modulator/demodulator
(b) FM modulator/demodulator
(c) Fiber optic communication link.
Design Practice Lab Manual ( AY 2021-22 )

#################################################################################

# Python Script for plotting AM Wave

---------------------------------------------------------------------------------

import numpy as np

import matplotlib.pyplot as plt

#Carrier wave c(t)=A_c*cos(2*pi*f_c*t)

#Modulating wave m(t)=A_m*cos(2*pi*f_m*t)

#Modulated wave s(t)=A_c[1+mu*cos(2*pi*f_m*t)]cos(2*pi*f_c*t)

A_c = float(input('Enter carrier amplitude: '))

f_c = float(input('Enter carrier frquency: '))

A_m = float(input('Enter message amplitude: '))

f_m = float(input('Enter message frquency: '))

modulation_index = float(input('Enter modulation index: '))

t = np.linspace(0, 1, 1000)

carrier = A_c*np.cos(2*np.pi*f_c*t)

modulator = A_m*np.cos(2*np.pi*f_m*t)

product = A_c*(1+modulation_index*np.cos(2*np.pi*f_m*t))*np.cos(2*np.pi*f_c*t)

plt.subplot(3,1,1)

plt.title('Amplitude Modulation')

plt.plot(modulator,'g')

plt.ylabel('Amplitude')

plt.xlabel('Message signal')

plt.subplot(3,1,2)

plt.plot(carrier, 'r')

plt.ylabel('Amplitude')

plt.xlabel('Carrier signal')

plt.subplot(3,1,3)

plt.plot(product, color="purple")
Design Practice Lab Manual ( AY 2021-22 )

plt.ylabel('Amplitude')

plt.xlabel('AM signal')

plt.subplots_adjust(hspace=1)

plt.rc('font', size=15)

fig = plt.gcf()

fig.set_size_inches(16, 9)

fig.savefig('Amplitude Modulation.png', dpi=100)

##################################################################################

# Python Script for plotting FM Wave

----------------------------------------------------------------------------------
Design Practice Lab Manual ( AY 2021-22 )

import numpy as np

import matplotlib.pyplot as plt

modulator_frequency = 4.0

carrier_frequency = 40.0

modulation_index = 1.0

time = np.arange(44100.0) / 44100.0

modulator = np.sin(2.0 * np.pi * modulator_frequency * time) * modulation_index

carrier = np.sin(2.0 * np.pi * carrier_frequency * time)

product = np.zeros_like(modulator)

for i, t in enumerate(time):

product[i] = np.sin(2. * np.pi * (carrier_frequency * t + modulator[i]))

plt.subplot(3, 1, 1)

plt.title('Frequency Modulation')

plt.plot(modulator)

plt.ylabel('Amplitude')

plt.xlabel('Modulator signal')

plt.subplot(3, 1, 2)

plt.plot(carrier)

plt.ylabel('Amplitude')

plt.xlabel('Carrier signal')

plt.subplot(3, 1, 3)

plt.plot(product)

plt.ylabel('Amplitude')

plt.xlabel('Output signal')

plt.show()
Design Practice Lab Manual ( AY 2021-22 )
Design Practice Lab Manual ( AY 2021-22 )

##################################################################################

# Python Script for Fibre Optic Link

Take the input from the user and display the following output

● The Numerical Aperture


● The acceptance angle
● The relative index difference

----------------------------------------------------------------------------------

import math

# Input data

n1=float(input('Refractive Index of core n1:'))

n2=float(input('Refractive index of cladding n2:'))

# a)The numerical aperture

NA=(n1**2-n2**2)**(1/2.0); # Numerical aperture

# Displaying the result in command window

print ("\n The numerical aperture = ",round(NA,4))

# b)The acceptanca angle

imax=math.asin(NA); # The acceptanca angle

# Displaying the result in command window

print ("\n The acceptance angle = ",round(imax,4)," Radian")

# c)The relative index defference

delta=(n1-n2)/n1; # Relative index defference

# Displaying the result in command window

print ("\n The relative index difference = ",round(delta,4))


Design Practice Lab Manual ( AY 2021-22 )
Design Practice Lab Manual ( AY 2021-22 )

Problem Solving Techniques in


Communication Systems and Networks
Design Practice Lab Manual ( AY 2021-22 )

PERFORMANCE ANALYSIS OF BPSK IN


RAYLEIGH FADING CHANNEL
Design Practice Lab Manual ( AY 2021-22 )

##############################################################################

% MATLAB Script for computing the BER for BPSK modulation in a

% Rayleigh fading channel

##############################################################################

clear

N = 10^6 % number of bits or symbols

% Transmitter

ip = rand(1,N)>0.5; % generating 0,1 with equal probability

s = 2*ip-1; % BPSK modulation 0 -> -1; 1 -> 0

Eb_N0_dB = [-3:35]; % multiple Eb/N0 values

for ii = 1:length(Eb_N0_dB)

n = 1/sqrt(2)*[randn(1,N) + j*randn(1,N)]; % white gaussian noise, 0dB variance

h = 1/sqrt(2)*[randn(1,N) + j*randn(1,N)]; % Rayleigh channel

% Channel and noise Noise addition

y = h.*s + 10^(-Eb_N0_dB(ii)/20)*n;

% equalization

yHat = y./h;

% receiver - hard decision decoding

ipHat = real(yHat)>0;

% counting the errors

nErr(ii) = size(find([ip- ipHat]),2);

end

simBer = nErr/N; % simulated ber


Design Practice Lab Manual ( AY 2021-22 )

theoryBerAWGN = 0.5*erfc(sqrt(10.^(Eb_N0_dB/10))); % theoretical ber

EbN0Lin = 10.^(Eb_N0_dB/10);

theoryBer = 0.5.*(1-sqrt(EbN0Lin./(EbN0Lin+1)));

% plot

close all

figure

semilogy(Eb_N0_dB,theoryBerAWGN,'cd-','LineWidth',2);

hold on

semilogy(Eb_N0_dB,theoryBer,'bp-','LineWidth',2);

semilogy(Eb_N0_dB,simBer,'mx-','LineWidth',2);

axis([-3 35 10^-5 0.5])

grid on

legend('AWGN-Theory','Rayleigh-Theory', 'Rayleigh-Simulation');

xlabel('Eb/No, dB');

ylabel('Bit Error Rate');

title('BER for BPSK modulation in Rayleigh channel');


Design Practice Lab Manual ( AY 2021-22 )

BER for BPSK in ISI channel with Zero


Forcing equalization
Design Practice Lab Manual ( AY 2021-22 )

######################################################################

% Script for computing the BER for BPSK modulation in 3 tap ISI

% channel. Zero Forcing equalization with 3/5/7/9 tap is performed

% and the BER computed

#######################################################################

clear

N = 10^6; % number of bits or symbols

Eb_N0_dB = [0:10]; % multiple Eb/N0 values

K = 4;

for ii = 1:length(Eb_N0_dB)

% Transmitter

ip = rand(1,N)>0.5; % generating 0,1 with equal probability

s = 2*ip-1; % BPSK modulation 0 -> -1; 1 -> 0

% Channel model, multipath channel

nTap = 3;

ht = [0.2 0.9 0.3];

chanOut = conv(s,ht);

n = 1/sqrt(2)*[randn(1,N+length(ht)-1) + j*randn(1,N+length(ht)-1)]; % white gaussian


noise, 0dB variance

% Noise addition

y = chanOut + 10^(-Eb_N0_dB(ii)/20)*n; % additive white gaussian noise

for kk = 1:K

L = length(ht);
Design Practice Lab Manual ( AY 2021-22 )

hM = toeplitz([ht([2:end]) zeros(1,2*kk+1-L+1)], [ ht([2:-1:1]) zeros(1,2*kk+1-L+1)


]);

d = zeros(1,2*kk+1);

d(kk+1) = 1;

c = [inv(hM)*d.'].';

% mathched filter

yFilt = conv(y,c);

yFilt = yFilt(kk+2:end);

yFilt = conv(yFilt,ones(1,1)); % convolution

ySamp = yFilt(1:1:N); % sampling at time T

% receiver - hard decision decoding

ipHat = real(ySamp)>0;

% counting the errors

nErr(kk,ii) = size(find([ip- ipHat]),2);

end

end

simBer = nErr/N; % simulated ber

theoryBer = 0.5*erfc(sqrt(10.^(Eb_N0_dB/10))); % theoretical ber

% plot

close all

figure

semilogy(Eb_N0_dB,simBer(1,:),'bs-'),'Linewidth',2;

hold on

semilogy(Eb_N0_dB,simBer(2,:),'gd-'),'Linewidth',2;

semilogy(Eb_N0_dB,simBer(3,:),'ks-'),'Linewidth',2;
Design Practice Lab Manual ( AY 2021-22 )

semilogy(Eb_N0_dB,simBer(4,:),'mx-'),'Linewidth',2;

axis([0 10 10^-3 0.5])

grid on

legend('sim-3tap', 'sim-5tap','sim-7tap','sim-9tap');

xlabel('Eb/No, dB');

ylabel('Bit Error Rate');

title('Bit error probability curve for BPSK in ISI with ZF equalizer');


Design Practice Lab Manual ( AY 2021-22 )

Problem Solving Techniques in Antenna


Design and Simulation
Design Practice Lab Manual ( AY 2021-22 )

Monopole Antenna design


and Analysis using HFSS
Design Practice Lab Manual ( AY 2021-22 )

The Monopole Antenna – Introduction:


The monopole and dipole antennas are commonly used for broadcasting, cellular phones, and
wireless communications due to their omni directive property. Thus, in this tutorial, a dipole
antenna will be constructed and analyzed using the HFSS simulator. The example will
illustrate both the simplicity and power of HFSS through construction and simulation of this
antenna structure.
The following notes will provide a summary of goals.
1. General navigation of software menus, toolbars, and quick keys.
2. Variable assignment.
3. Overview of commands used to create structures.
4. Proper design and implementation of boundaries.
5. Analysis Setup. Report Creation and options.

1- Starting HFSS –
Select Programs, and select An soft, HFSS program group. Click HFSS –
Or double click on the HFSS icon on the Windows Desktop.

2- Creating the Project First launch the HFSS Simulator.


Design Practice Lab Manual ( AY 2021-22 )

From the Project Manager window. Right-Click the project file and select Save As from the
sub menu.

Name the file “monopole” and Click Save.

3- Working with geometries


To begin working with geometries. - you must insert an HFSS design. Right-Click the
project file and select Insert > Insert HFSS Design from the menu.
Design Practice Lab Manual ( AY 2021-22 )

Or click on from the tool bars

Due to the nature of this design, we will use Driven Modal as the solution type. From the
HFSS menu select Solution Type and Driven Modal

The units are chosen as mm by choosing the heading 3D modeler and Units from the menu
Design Practice Lab Manual ( AY 2021-22 )

HFSS relies on variables for any parameterization / optimization within the project.
Variables also hold many other benefits which will make them necessary for all projects.
• Fixed Ratios (length, width, height) are easily maintained using variables.
• Optimetrics use variables to optimize the design according to user-defined criteria.
• All dimensions can be quickly changed in one window as opposed to altering each object
individually.
Click the HFSS heading and select Design Properties at the bottom of the menu.
Design Practice Lab Manual ( AY 2021-22 )

This will open the variable table. Add all variables shown below by selecting Add. Be sure
to include units as needed.

The final variable table should look like


Design Practice Lab Manual ( AY 2021-22 )

4- Drawing the Monopole

We will start to by creating the dipole element using the Draw Cylinder button from the
toolbar.

By default, the proprieties dialog will appear after you have finished drawing an object.
The position and size of objects can be modified from the dialog.
Design Practice Lab Manual ( AY 2021-22 )
Design Practice Lab Manual ( AY 2021-22 )

Follow the format above for structure size. Give the name Monopole to this object. Assign the
material PEC and click OK. PEC (Perfect Electric Conductor) will create ideal conditions for
the element.
Create the circle with the dimensions shown in below figure and name it as infinite ground
and assign the material PEC and click OK.
Design Practice Lab Manual ( AY 2021-22 )

5- Creating the port

In the section you will create a Lumped Gap Source. This will provide an excitation to the
dipole structure. Begin by selecting the YZ plane from the toolbar. Using the 3D toolbar, click
Draw Rectangle and place two arbitrary points within the model area.

Enter the following information


Design Practice Lab Manual ( AY 2021-22 )

With the source geometry in place, the user must provide an excitation. A lumped port will
be used for the monopole model. This excitation is commonly used when the far field region
is of primary interest. In the project explorer, right-click Excitation -> Assign -> Lumped
Port
Design Practice Lab Manual ( AY 2021-22 )

Name the port source and leave the default values for impedance.

Click Next and enter the following:


Design Practice Lab Manual ( AY 2021-22 )

Using the mouse, position the cursor to the bottom-centre of the port. Ansoft's snap feature
should place the pointer when the user approaches the centre of any object. Left-click to define
the origin of the E-field vector. Move the cursor to the top-centre of the port. Left- click to
terminate the E-field vector. Click finish to complete the port excitation.

Note: In case you find some difficulties for drawing the lumped port, you can redraw the
rectangular plane, affect the lumped port, then resize the rectangular plane.
Design Practice Lab Manual ( AY 2021-22 )

6. Radiation Boundary:

In this section, a radiation boundary is created so that far field information may be extracted
from the structure. To obtain the best result, a cylindrical air boundary isdefined with
a distance of λ/4. From the toolbar, select Draw Cylinder.

Enter the following information:


Design Practice Lab Manual ( AY 2021-22 )
Design Practice Lab Manual ( AY 2021-22 )

With all faces selected, right-click the Boundary icon in the object explorer and select
Boundary -> Assign -> Radiation

Leave the default name Rad1 and click OK

7. Solutio Setup:

In this section a solution must be defined to display the desired data. We are primarily
interested in the frequency response of the structure. We will also explore HFSS's ability to
calculate general antenna parameters such as directivity, radiation resistance, radiation
efficiency, etc...,
From the project explorer, select Analysis -> Add Solution Setup.
Design Practice Lab Manual ( AY 2021-22 )

Enter the following. Click ok when complete.

To view the frequency response of the structure, a frequency sweep must be defined. From
the project explorer select Setup1 -> Add Sweep
Design Practice Lab Manual ( AY 2021-22 )
Design Practice Lab Manual ( AY 2021-22 )

8. Structure Analysis:

At this point, the user should be ready to analyse the structure. Before running the analysis,
always verify the project by selecting from the 3D toolbar. If everything is correct the
user should see:

Analyse the structure by clicking

9. Create Reports:

After completion of the analysis, we will create a report to display both the resonant frequency
and the radiation pattern. Click on the heading HFSS and select Results -> CreateReports
Design Practice Lab Manual ( AY 2021-22 )

Choose the following in the Create Report window:

Select the following highlighted parameters and click Add Trace to load the options into the
Trace window.
Design Practice Lab Manual ( AY 2021-22 )
Design Practice Lab Manual ( AY 2021-22 )

Click Done when complete. The graph is displayed below:

HFSS can compute antenna parameters automatically. To produce the calculations, the user
must define an infinite sphere for far field calculations. Right-click the Radiation icon in the
project manager window and select Insert Far Field Setup -> Infinite Sphere

Accept all default parameters and click Done. Right-click


Infinite Sphere1 -> Compute Antenna Parameters... from the
project explorer as shown:
Design Practice Lab Manual ( AY 2021-22 )

Select all defaults and results are displayed as follows:


Design Practice Lab Manual ( AY 2021-22 )

Next, the far field will be plotted. Create Reports as previously shown. Modify the following:
Design Practice Lab Manual ( AY 2021-22 )
Design Practice Lab Manual ( AY 2021-22 )
Design Practice Lab Manual ( AY 2021-22 )

To plot Co polarization chart in the E-


Plane Select>Results>create far field reports>radiation
pattern>Gain>Gain Theta>dB, go to families>select phi 90deg
Design Practice Lab Manual ( AY 2021-22 )

To plot Cross polarization chart in the


E-Plane Select>Results>create far field
reports>radiation pattern>Gain>Gain Theta>dB, go to
families>select phi 0deg
Design Practice Lab Manual ( AY 2021-22 )

To plot Co polarization chart in the H-


Plane Select>Results>create far field reports>radiation
pattern>Gain>Gain phi>dB, go to families>select phi 0deg
Design Practice Lab Manual ( AY 2021-22 )

To plot Cross polarization chart in the


H-Plane Select>Results>create far field
reports>radiation pattern>Gain>Gain phi>dB, go to
families>select phi 90deg
Design Practice Lab Manual ( AY 2021-22 )

You might also like