0% found this document useful (0 votes)
7 views6 pages

ECNG1006 - Matlab Exercise 2A - Jan 19 2025

The document outlines MATLAB Exercise 2A for students in the B. Sc. in Electrical & Computer Engineering program at The University of the West Indies. It covers the use of linear interpolation to find zero-crossings and how to plot vectors between two known coordinate points using MATLAB. The lab aims to enhance students' practical skills in MATLAB over a 3-hour online session, with specific learning outcomes and exercises provided for practice.

Uploaded by

kaitlynmohammed9
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)
7 views6 pages

ECNG1006 - Matlab Exercise 2A - Jan 19 2025

The document outlines MATLAB Exercise 2A for students in the B. Sc. in Electrical & Computer Engineering program at The University of the West Indies. It covers the use of linear interpolation to find zero-crossings and how to plot vectors between two known coordinate points using MATLAB. The lab aims to enhance students' practical skills in MATLAB over a 3-hour online session, with specific learning outcomes and exercises provided for practice.

Uploaded by

kaitlynmohammed9
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/ 6

THE UNIVERSITY OF THE WEST INDIES

ST. AUGUSTINE, TRINIDAD & TOBAGO, WEST INDIES


FACULTY OF ENGINEERING
Department of Electrical & Computer Engineering
B. Sc. in Electrical & Computer Engineering

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

Name of the Lab: MATLAB EXERCISE 2A

Lab Weighting: 0% Estimated total 3 hours


study hours:
Delivery mode: Lecture: Yes
Lab: Yes
Venue for the Lab: ONLINE

Recommended To undertake this lab, students should be able to perform basic


prior knowledge mathematical operations. The use of debugging, breakpoints and step
and skills: throughs are recommended.

Course Staff Position/Role E-mail

Jeevan Persad Course Lecturer jeevan.persad@uwi.edu

Juliet Romeo-Joseph Engineering Practice Coordinator juliet.romeo-joseph@uwi.edu

Mark Jennings Coordinator – Matlab Exercises mark.jennings@uwi.edu

2. LAB LEARNING OUTCOMES

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.

2. Linear Interpolation Method

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:

Start with x and y-values of graph


Find where the y-values change from positive to negative
Record the x and y-values before and after this change
Find the interpolation y value, r <- (0 – y1) / (y2 – y1)
Find the estimated x-value <- x1 + (r*(x2-x1))
Repeat for entire graph until all zero-crossings are found
End

The example code below produces a visual representation of how the algorithm works:

% commented find zero crossings


%% set up arbitrary signal (sum of 2 sines for demo)
x = 0:0.01:4;
sin1 = 10*sin(10*x); sin2 = 42*sin(6*x);
signal = sin1+sin2;
% plot to show signal
figure;
plot(x, signal, 'bo-');
hold on;
plot(x, zeros(1,length(x)), 'k:');

Page 3 of 6
MATLAB EXERCISE 2A

%% find next point after zero crossing


sigPos = logical(signal>0); % find all positive points
cross = sigPos - circshift(sigPos,1); % find changeover points
% add to plot
plot(x(logical(cross)), signal(logical(cross)), 'ko');
%% assume straight line approximation between adjacent points
crossInd = find(cross); % x indices of cross points
nCross = length(crossInd); % number of cross points found
x0 = NaN(1,nCross); % vector of x-values for cross points
for aa = 1:nCross
thisCross = crossInd(aa);

% interpolate to get x coordinate of approx 0


x1 = thisCross-1; % before-crossing x-value
x2 = thisCross; % after-crossing x-value
y1 = signal(thisCross-1); % before-crossing y-value
y2 = signal(thisCross); % after-crossing y-value

ratio = (0-y1) / (y2-y1); % interpolate between to find 0


x0(aa) = x(x1) + (ratio*(x(x2)-x(x1))); % estimate of x-value

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

3. Line Plotting Between Two Known Coordinate Points

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:

p1 = [2 3]; % First Point


p2 = [9 8]; % Second Point
dp = p2-p1; % Difference
figure(1)
quiver(p1(1),p1(2),dp(1),dp(2),0)
grid
axis([0 10 0 10])
text(p1(1),p1(2), sprintf('(%.0f,%.0f)',p1))
text(p2(1),p2(2), sprintf('(%.0f,%.0f)',p2))

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.

End of MATLAB EXERCISE 2A

Page 6 of 6

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy