How Do You Convolve and Plot Functions in MATLAB?

  • Thread starter Thread starter wiz0r
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
SUMMARY

The discussion focuses on convolving and plotting functions in MATLAB, specifically using the functions x1(t) = tu(t) - tu(t-1) and x2(t) = 10e^-4tu(t). The user seeks assistance in defining the unit step function u(t) and correctly implementing convolution using MATLAB's conv function. Key steps include plotting both functions, performing convolution, and comparing results from MATLAB with hand calculations using Laplace transforms. The user is advised to define vectors for function evaluation rather than using function definitions.

PREREQUISITES
  • Understanding of unit step functions (u(t) and u(t-1))
  • Basic knowledge of MATLAB syntax and operations
  • Familiarity with convolution operations in signal processing
  • Knowledge of Laplace transforms for analytical calculations
NEXT STEPS
  • Learn how to define and manipulate vectors in MATLAB
  • Explore the MATLAB conv function documentation for detailed usage
  • Study MATLAB plotting functions to visualize data effectively
  • Review Laplace transform techniques for signal analysis
USEFUL FOR

Students and professionals in engineering, signal processing, or applied mathematics who are learning to use MATLAB for function manipulation and convolution analysis.

wiz0r
Messages
56
Reaction score
0
Ok, so what I need to do is;


Given the functions;

x1(t)= tu(t)-tu(t-1) and x2(t)=10e^-4tu(t), do the following:

1. Plot x1(t) and x2(t) using MATLAB.
2. Use MATLAB to find and plot x(t)=x1(t)* x2(t), where * denotes convolution.
3. Find x(t)=x1(t)* x2(t) by hand using Laplace transforms.
4. Plot the result of part 3 in MATLAB and compare it to that found in part 2.

Okay, what I had trouble was defing u(t). Since, according to my book it says that u(t) = 0 if t<0, and u(t) = 1 if t>0. Also that; u(t-1) = 1 if 1<t<infinite, and u(t-1) = 0 if t<1. So,
what I tried to do was to define the two functions, one would be u(t) and the other u(t-1). So, I had two functions(m.files) named, u, and v. v being u(t-1). So, I would use them on my original program. the two function would look like;

u(t) =

Code:
function u = u(t)

if t > 0
    u = 1;
else
    u = 0;
end

v(t) = u(t-1)

Code:
function v = v(t)
if t > 1
    v = 1;
else
    v = 0;
end

my original program would look like;

Code:
t = 0:0.1:10;
x1 = t*u - t*v;
x2 = 10*exp(-4*t)*u;
plot(t,x1)
plot(t,x2)
y = conv(x1,x2);
plot(t,y)
return;

I really thought that would work, but bleh, it doesn't. Can anyone help me telling me what's wrong?

PS: I have no experience programming with MATLAB. I only know very basic C. So, yeah, please bare with me.

Edwin
 
Physics news on Phys.org
You can't define a function as you've done (well, it can be used to return values, but all it'll do is return values, you can't do operations on these, or on symbolic functions in general). What you need to do is define a vector (a.k.a. 1-D array) with x (or, in this case, t) values, and then evaluate the function at each of these points, producing a second vector with your function values.

If you do this for u and v, you'll then be able to convolve them.

As you're just starting out, here's probably the most helpful MATLAB command: help

help conv would bring up the documentation (including the expected inputs, and examples of use) for the conv function.

Also, if you've got nothing in the way of MATLAB orientation / intro from your class, here's the MATLAB documentation website / online help (link goes to the "Getting Started in MATLAB" document):
http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/bqr_2pl.html

If you know absolutely nothing about MATLAB, the http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/f2-8955.html" chapter will intro the basics of MATLAB entry.

Good luck!
 
Last edited by a moderator:

Similar threads

  • · Replies 6 ·
Replies
6
Views
5K
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K