MATLAB Answers

how to plot the result of convolution? ; used conv()

조회 수: 15(최근 30일)
조현 김
조현 김 2021년 9월 19일
답변: Paul 2021년 9월 19일
dt=0.01;
t=0:dt:3;
t1=0:dt:2;
x=sin(pi*t1);
h=2*ceil(heaviside(t-1)-heaviside(t-3));
y=conv(h,x);
figure(1)
time=linspace(1,5,length(t));
subplot(311); plot(t1,x);
subplot(312);
so I have these two functions, x(t) = sin(pi*x) and h(t) = 2*(u(t-1)-u(t-3)).
For a different range of convolution x(t)*h(t), how can I plot this as a result? I want a result from t [0,10].
(ps. I tried conv(x,h,'same')) and I don't think the result graph looks the same answer as my hand-write answer.)
plot(t,h);

답변(1개)

Paul
Paul 2021년 9월 19일
I assume you meant x(t) = sin(pi*t) (not sin(pi*x)).
Let's rewrite: x(t) = sin(2 * pi / 2 * t). So x(t) has period T = 2 as shown on your plot But h(t) is a rectangular pulse of width 2. So for any value of t the integrand of the convolution integral
y(t) = int(x(tau)*h(t - tau),tau,-inf,inf)
is zero everwhere, except over one period of x(tau). But the integal of x(tau) over one period is zero, so the convolution integral is zero for any value of t.
For reasons I don't understand, Matlab doesn't like computing the integral symbolically:
syms h(t) x(t) tau
x(t) = sin(sym(pi)*t);
h(t) = 2*(heaviside(t-1) - heaviside(t-3));
y(t) = int(x(tau)*h(t-tau),tau,-inf,inf)
y(t) = 
NaN
But we can evaluate it numerically for some example cases
vpaintegral(x(tau)*h(0-tau),tau,-inf,inf) % t = 0
ans = 
vpaintegral(x(tau)*h(5-tau),tau,-inf,inf) % t = 5
ans = 
vpaintegral(x(tau)*h(-10-tau),tau,-inf,inf) % t = -10
ans = 
3.17512e-10
We can also go into the frequency domain to compute the Fourier tansform of the convolution and the take the inverse
y(t) = ifourier(fourier(h(t))*fourier(x(t)))
y(t) = 
0
Also, be careful using heaviside() in the discrete domain. The default is heaviside(0) = 1/2, which is, at least almost always, not what you want for the unit step function in the discrete domain. You can change the default using sympref.

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by