Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do I create a MATLAB function that convolves two signals? Suppose I have two

ID: 3348870 • Letter: H

Question

How do I create a MATLAB function that convolves two signals?

Suppose I have two singals x and h,

I want to create a function that convolves these two singals. Here is my attempt:

function y = getConvolution(x,h)

y = conv(x,hshift);

When I enter the command plot(y), I get an error stating undefined function or variable 'y'. What am I doing wrong, or more importantly how do I create a simple function that can convolve two singals. Please note that I must specifically create a function that can convolve two signals.

Please provide a simple code of a function that can convolve two given signals.

2t

Explanation / Answer

x(t) = e ?2tu(t)

h(t)= e -4tu(t)

c(t)= x(t) ? h(t)

Matlab code

dt=0.01;

x1=0;

x2=1;

h1=0;

h2=2;

tx=x1:dt:x2;

x=exp(-tx);

th=h1:dt:h2;

h=exp(-th);

tc=x1+x2:dt:h1+h2;

c=dt*conv(x,h);

subplot(311),plot(tx,x),xlabel(’t’),ylabel(’x(t)’),

subplot(312),plot(th,h),xlabel(’t’),ylabel(’h(t)’),

subplot(313),plot(tc,c),xlabel(’t’),ylabel(’conv(x(t),h(t)’),

The MATLAB script below will approximate and plot the signal c(t) that is the convolution of a signal x(t) with the signal h(t). The signal x(t) is non zero only for times in the interval from x1 to x2; the values of 'x(t)' in this interval every dt time units are first stored in the vector x.

Similarly, the signal h(t) is non zero only for times in the interval from h1 to h2; the values of h(t) in this interval every dt time units are first stored in the vector h.

The convolution is non zero only for times between x1 +h1 and x2 + h2; the values every dt time units are stored in the vector c.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote