Using conv() function
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have wrote the function as follows
u = @(t) 1.0*(t>=0);
t = -0.25:0.1:4;
x = @(t) 1.5.*sin(pi*t).*(u(t)-u(t-1));
h = @(t) 1.5.*(u(t)-u(t-1.5))-(u(t-2)-u(t-2.5));
y = conv(h,x,'same');
Im also looking to plot y(t) afterwards, I keep getting an error at the line where the convolution actually takes place
0 Commenti
Risposte (1)
Paul
il 6 Ott 2022
h, x, and u are actually functions that are evaluated at the values of their input arguments. So need to evaluate h and x at the values in the variable t (which has nothing to do with the t in the definitions of u, x, and h.
u = @(t) 1.0*(t>=0);
t = -0.25:0.1:4;
x = @(t) 1.5.*sin(pi*t).*(u(t)-u(t-1));
h = @(t) 1.5.*(u(t)-u(t-1.5))-(u(t-2)-u(t-2.5));
y = conv(h(t),x(t),'same');
2 Commenti
Paul
il 7 Ott 2022
Modificato: Paul
il 7 Ott 2022
That's because y is an array, not a function.
u = @(t) 1.0*(t>=0);
t = -0.25:0.1:4;
x = @(t) 1.5.*sin(pi*t).*(u(t)-u(t-1));
h = @(t) 1.5.*(u(t)-u(t-1.5))-(u(t-2)-u(t-2.5));
y = conv(h(t),x(t),'same');
plot(t,y)
Whether or not that's the correct answer for the problem at hand is a different question.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
