Octave Programming
Course Code BECL456C
CIE Marks 50
Teaching Hours/Week (L:T:P:S) 0:0:2
SEE Marks 50
Total Hours of Pedagogy 12 Sessions
Total 100
Credits 01
Exam Hours 02
Course Syllabus :
Basic data structures in Octave – Vectors, Matrices, Cell Arrays. Special vecors. Linear sampling and
logarithmic sampling. Accessing elements of vectors, matrices, and matrices. Mathematical operations on
vectors and matrices. Addition, Multiplication, Subtraction, Division, Power, Square-Root, trigonometric
operations. Dot Products and Cross Products of Vectors. Matrix multiplication, matrix inverse and matrix
transpose operations. Finding eigen values and vectors of a square matrix. Finding the solution of a system
of linear equations. Linear programming and integer linear programming using glpk. Plotting in Octave.
Subplots, Stem Plots, Semilog and Log-log plots. Packages in Matlab – symbolic, signal processing,
control. Applications of Octave to solve problems in Electrical engineering, Electronics engineering,
Control Systems, Signals and Systems/Signal Processing.
Experiments
1(a)Define the following matrices using Octave
i. A 4x4 identity matrix
ii. A 4x4 matrix of zeros
iii. A 4x4 matrix of ones
iv. The matrix U4 defined below.
v. Matrix D4 defined below. It is also called the Hadamard matrix of dimension 4.
vi. Matrix H4 defined below
vii. A 4x4 magic square G4
viii. A 4x4 matrix of random numbers selected from the range {-1,0,1}.
ix. A 4x4 matrix of random numbers in the range 0 to 1.
(b)
(i) How can you generate a 4x4 matrix of all 2’s?
(ii) Find the transpose of U4.
(iii) Multiply D4 by its transpose and obtain the resulting matrix. How is
related to the identify matrix?
(iv) Find the inverse of H4 and verify that it is the inverse.
(v) What is the determinant of D4?
(vi) Extract the diagonal elements of H4.
(vii) How can you reshape the elements of D4 into a 2x8 matrix?
(viii) What is the magic sum of a 4x4 matrix? How can you verify that G4 is
indeed a magic square?
(ix) The matrix D4 mentioned above is a 4x4 matrix. We wish to extract
the sub- matrix consisting of rows 1 and 4 and columns 1 and 4. [In
other words, the four corners of D4.) Show Octave code for generating
the submatrix SM.
(x) Check if the H4 and D4 are orthogonal matrices.
2 You will have learnt Kirchhoff’s current and voltage laws to solve the voltages and
currents in a DC circuit. Given a circuit with n loops, we can write down n equations in n
unknowns (loop currents). Alternately, given a circuit with n nodes, we can write down
n equations in n unknowns (node voltages). These linear equations can be solved using
Octave.
(a) Write down the KCL and KVL for the following circuit and solve the node
voltages and currents. Assume that Vs is 100V.
(b) Find the total power dissipated in the circuit.
(c) Find the total power supplied by the voltage source.
(d) Challenge – Instead of hardcoding the values of the resistors and the voltage
source, can you allow the user to input R1, R2, R3, R4, R5, and Vs? Develop a
complete Octave script which reads in the values of circuit parameters and prints
the node voltages, node currents, and power dissipation.
(e) Variations of the above exercises can be given to the students. For example, a
resistor can be included in series with Vs. Alternately, a different circuit from a
text book can be given. You can also change the problem by specifying the current
through one of the resistors and asking the user to solve for Vs.
3(a) Consider the RC circuit shown in the figure below. Plot the voltage across C and the
charging current through C when the switch is turned on.
(b) What is the rise time of the capacitor voltage?
4
(a) The figure shows a diode-based rectifier. The diode conducts only when the input
voltage is positive. Assume that it is an ideal diode. Plot the half-wave rectified
waveform if the input to the rectifier is a 50- Hz sine wave of 200V RMS. Plot the
output waveform for four cycles of the input.
(b) Find the average of the Halfwave-rectified output in Octave and verify your answer
using the formula for the average output.
(c) Plot the output of a full-wave rectifier.
(d) Find the RMS value of the Fullwave-rectified output in Octave and verify your
answer using the formula for the RMS value.
(e) Assume that the input voltage is 2sin(500t) V and that the diode has a cut-in voltage
of 0.6V. Plot the half-wave and full-wave rectified waveforms and find their average
and RMS values.
5You have studied that any periodic signal of frequency f can be decomposed into a sum of sine
and cosine waveforms whose frequencies ae integral multiples of f. The resulting series is called
the Fourier series. Consider the following equation.
𝒙(𝒕) = 𝟒/𝝅 × ∑_(𝒌 = 𝟏)^𝒏▒〖𝒔𝒊𝒏 (𝟐 𝝅𝒇 (𝟐𝒌 − 𝟏)𝒕) 〗
(a) Write an Octave program to read f and n and plot x(t). What does x(t) resemble?
(b) How can you modify x(t) to generate a square waveform of frequency f, but whose
amplitude goes from 0 to 2?
(c) Generate x(t) assuming that the square wave goes from -1 to 1 and has a frequency of 1
kHz. Take 100 samples in each period. Perform an FFT analysis of x(t).
6 (a) Given Z parameters, obtain the Y parameters using a function
called Z2Y() Given Y parameters, obtain the Z parameters using a
function called Y2Z()
(b) Find the Z and Y parameters for the T-network
(c) Find the Z and Y parameters for the Delta. Assume that all resistors are 15 Ohms.
( d) Find the T-equivalent of the Delta network above.
( e) Find the T-equivalent of the Delta network above. Let the T network have the resistors
Zb, Zc, Za.
7(a) Represent the number 65 as an unsigned integer using fewest number of bits
(b) Represent the number -65 as a signed magnitude integer using the fewest number of bits
(c) Represent the number -65 as a one’s complement number using fewest number of bits
(d) Represent the number -65 as a two’s complement number using the fewest number of bits
(e) Represent the number 1965 in hexadecimal
(f) Find the decimal equivalent of the hexadecimal number ABCDh
(g) Assume that "10010101" is a binary number. Interpret it as an unsigned number and
convert it to decimal.
(h) Memory is organized in terms of bytes. When a 32-bit number is read from a memory, 4
bytes have to be read. Suppose the bytes are stored as follows at location A in the memory.
In the little-endian representation, the bytes will be organized into a 32-bit register as
shown. Write a function which converts a 32-bit number from big-endian to little-endian
format.
8A series circuit consists of resistance R, inductance L and capacitance C. A sinusoidal voltage of
V sin(wt) is applied to the series circuit. Assume V=100. Plot the current in the circuit and the
input voltage for the following cases.
(a) w=1000, R = 5 ohm, L = 1mH, C = 200uF; is the current leading or lagging? What
is the power dissipation in the circuit?
(b) w=10000, R=5 ohm, L = 1mH, C = 200 uF; is the current leading or lagging? What
is the power dissipation in the circuit?
(c) The resonant frequency w0, R = 5 ohm, L = 1mH, C = 200uF. What is the phase
difference between the voltage and current? What is the value of w? What is the power
dissipation?
Write a function to plot the voltage and current. Take the inputs R, L, and C from the user.
9(a) Consider the circuit shown below and determine the inductance L and capacitance C.
(b) Plot the impedance of the RLC circuit shown in the figure as the frequency is varied
from 0 to 10 kHz.
(c) Find the resonant frequency from the plot
10 Find the value of capacitor C to maximize the power transferred to the load. (The load includes
the inductance.)
Suggested Learning Resources:
Textbooks:
Dr. P.J.G. Long, Department of Engineering University of Cambridge, "Introduction to Octave,"
can be downloaded from octavetut.pdf (cam.ac.uk)
0 Comments