ECNG1006 - Matlab Exercise 2A - Jan 19 2025
ECNG1006 - Matlab Exercise 2A - Jan 19 2025
ECNG 1006
MATLAB EXERCISE 2A
Page 1 of 6
ECNG 1006
Laboratory and Project Design I
http://myelearning.sta.uwi.edu/
Semester II; 2024/2025
1. GENERAL INFORMATION
Upon successful completion of the lab assignment, students will be able to: Cognitive
Level
1. Demonstrate competence with the use of MATLAB to: Application
a) Use the linear interpolation method to find zero-crossings.
b) Plot vectors between two known coordinate points.
Page 2 of 6
MATLAB EXERCISE 2A
3. IN-LAB
Allotted Completion 3 hours
Time:
Required lab 1 PC with MATLAB version 6.5 or higher
Equipment:
1. Introduction
The aim of this lab is to demonstrate how a linear interpolation method works, as well as how
you can arbitrarily plot lines on a graph, using any two given coordinate points. Both methods
presented here will assist with the assignment to be done.
The linear interpolation technique uses the y-values of the graph, along with its associated x-
values, to find the location at which the graph crosses the x-axis. This location is also referred to
as a zero-crossing. This method assumes a straight-line approximation between the adjacent
points for the zero-crossing. The general algorithm for this is seen below:
The example code below produces a visual representation of how the algorithm works:
Page 3 of 6
MATLAB EXERCISE 2A
end
% add to plot
plot(x0, zeros(1,nCross), 'ro');
You will notice that the zero-crossing points in the figure produced by the code are given by red
circles. If you click on these red circles in the figure, it will also give you the x and y-values for
each zero-crossing.
There are a few additional functions in the code that assist with implementing the algorithm. It
would be helpful if you check the documentation of these functions, to get a better understanding
on how the entire implementation works.
It would also be helpful if you debug, breakpoint and step through the code as well to understand
step-by-step on how the entire implementation works as well.
Page 4 of 6
MATLAB EXERCISE 2A
It is possible, using MATLAB, to plot a line with an vector between two known coordinate
points. The direction of the vector will indicate the start and end coordinates.
To obtain the magnitude of the vector, the difference between the coordinates is required.
Consider the example code given below:
The code produces a vector indicating the start and end points and the direction and magnitude of
the vector. This is accomplished by using the quiver function. It would be helpful if you check
the documentation of the quiver function, to get a better understanding of how it works.
Page 5 of 6
MATLAB EXERCISE 2A
4. Exercise
Now that you know how to do linear interpolation and line plotting between two known
coordinates, let us get some practice as to how these techniques can be used. Attempt the
following instructions:
1. Create a sine wave signal with magnitude 25, frequency 71 Hz and a phase shift of 31
degrees and assign the vector of its values to a variable. Choose an appropriate sampling
interval to reduce the straight-line approximation effect significantly.
2. Using ONLY the sine wave vector, determine the magnitude of the sine wave.
3. Using ONLY the sine wave vector, apply the linear interpolation technique in Section 2
and obtain the zero-crossing vector and the amount of zero-crossings obtained for the
sine wave. Store the vector and the amount as variables.
4. Using the zero-crossing vector, determine the relationship between this variable and the
frequency of the sine wave.
5. Using the first zero-crossing obtained, determine the relationship between this variable
and the phase shift of the sine wave.
6. Determine the start and end points of the phasor using the extracted magnitude and phase
values.
7. Use the code from Section 3 to plot the phasor.
Page 6 of 6