Using Matlab to do basic convultions

  • Thread starter thatguy14
  • Start date
  • Tags
    Matlab
In summary, the problem involves using MATLAB to convolve two functions, x(t) and h(t), in order to plot y(t), the concentration. The script provided uses the linspace function to create a time vector and then convolves x(t) with t, which is incorrect. The correct script should convolve x(t) with h(t) to get the desired result. The y-axis units are now in micrograms/min and the shape of the plot looks better. To plot the convolution function against time, the script should be modified to convolve x(t) with h(t) and then plot y against the time vector. The maximum concentration can be determined by finding the peak in the plot. For the second part of the question,
  • #1
thatguy14
45
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
  • #2
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:
  • #3
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?
 

1. What is Matlab and how is it used for basic convolutions?

Matlab is a high-level programming language and interactive environment that is commonly used in scientific and engineering applications. It provides a user-friendly interface for performing various mathematical operations, including convolutions. Convolution in Matlab involves multiplying two signals and integrating the product over a specific range.

2. How do I perform a basic convolution in Matlab?

To perform a basic convolution in Matlab, you can use the conv function. The syntax for this function is conv(x, h), where x and h are the two signals that you want to convolve. The output of this function will be the convolution of the two signals, which will have a length of (length of x + length of h - 1).

3. What are the applications of convolutions in Matlab?

Convolution in Matlab has various applications in signal processing, image processing, and filtering. It is commonly used for smoothing or blurring images, removing noise from signals, and detecting patterns in data. Convolution is also used in linear systems analysis and in solving differential equations.

4. Can I perform convolutions on matrices in Matlab?

Yes, Matlab allows you to perform convolutions on matrices. The conv function in Matlab can handle multi-dimensional arrays, which means you can convolve two or more matrices along a specific dimension. This is useful in applications such as image filtering and feature extraction.

5. Are there any other functions in Matlab that can be used for convolutions?

Yes, apart from the conv function, Matlab also has the filter function that can be used for convolutions. The filter function has more advanced features, such as the ability to specify the type of filter and the filter coefficients. Additionally, the fftconv function uses the fast Fourier transform (FFT) algorithm to perform convolutions, which can be more efficient for large datasets.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
826
  • Engineering and Comp Sci Homework Help
Replies
1
Views
881
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
954
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
996
  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
  • Calculus and Beyond Homework Help
Replies
10
Views
986
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
Back
Top