Using Matlab to do basic convultions

  • Thread starter Thread starter thatguy14
  • Start date Start date
  • Tags Tags
    Matlab
AI Thread Summary
The discussion focuses on using MATLAB to perform convolutions for a physiological modeling problem involving absorption rates and impulse response functions. The user initially attempted to convolve the wrong functions, mistakenly using time instead of the impulse response function, which led to nonsensical plot outputs. After correcting the script to convolve the correct functions, the user achieved a more meaningful plot and sought guidance on plotting the convolution function against time and determining its maximum concentration. Additionally, the user inquired about how to handle multiple shifted convolutions for different dosages. The conversation emphasizes the importance of correctly specifying functions in MATLAB for accurate results in convolution analysis.
thatguy14
Messages
45
Reaction score
0

Homework Statement


This is more of a imaging/physiological course but it uses convolutions and i can understand the applications, i just need help writing the MATLAB script to give meaningful answers.

The problem asks that we use MATLAB to convolute 2 functions:

x(t) = a*tb*exp(-ct)
where a=0.1 b=1.5 c=0.01
and
h(t) = dexp(-t/r)
where d = 0.1ml-1 and r = 60 min

There are units for x = micrograms/min. (this means d has to = 0.0001) x(t) is the absorption rate and h(t) is the impulse response function. y(t) would equal the concentration.

The idea is to plot y(t) using the MATLAB conv function for x(t) and h(t).

Homework Equations


Im not sure what goes here I've given most of the information above.


The Attempt at a Solution


I am not very good with MATLAB but what i did was create a time vector using the linspace function. Heres the script

Code:
t = linspace(0,10,100);
a = 0.1;
b=1.5;
c=0.01;
alpha=0.1;
tao=60;
x=a.*t.^b.*exp(-c.*t);
h=alpha.*exp(-t./tao);
y=conv(x,t);
plot(y)

When i plot y, the y-axis and the x-axis give numbers that don't make sense in the terms of the question. atleast i don't think they make sense. Have i done this right?

Thanks for the help!
 
Physics news on Phys.org
Code:
y=conv(x,t);
is convolving x against t. You need to convolve x with h, which would be

Code:
y=conv(x,h);

Plot is just plotting the points in Y and connecting them with a line. Since you don't tell MATLAB what x is, it just plots the values against the array index... so the first point is 1, the second is 2, etc...

The Y vector is 200 elements big because of how the convolution works. Since it has to sweep one function completely over the other, and the two arrays are the same length, the output array is twice as long -1. Think about it starting with the two functions side by side (with one flipped backwards), stepping through until they are side by side again, but on opposite sides.
 
Last edited:
Ok i see, it was actually a typo the y=conv(x,t). I had it set in my script as x and h, don't really know how it got switched.

Anyways, that's a much better looking shape. The y-axis units are better too. How would i plot the convolution function againt time in this case? Also this convolution would in essence give me my maximum concentration (it is derived from the meaning of x and h). How do i determine its maximum?

Also the second part of this question requires that i take multiple conv functions that have been shifted by some time and add them together. I understand that i have to take my x function and h function and shift it by the dosage, but how do i add these functions together in the convolution for multiple shifts?
 
Back
Top