Convolution with a time shifted box function
6 views (last 30 days)
Show older comments
Hello, I have the input:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1662491/image.png)
Its a box funciton x2(t-0.00225) with L = 0.0005 where it's 1 when 0.002 <= t<= 0.0025 and 0 elsewhere. I want to convolve this with the impulse funciton of a low pass filter:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1662496/image.png)
My hand calculation gives the result for when (-0.00225 + t ) > 0 is y(t) = 1 - e^ (0.00225-t)/RC):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1662501/image.png)
And my code is:
Ts=1e-6; % Set up time and frequency variables
t = 0:Ts:0.01-Ts; N = length(t);
fs=1/Ts; F=fs/N; f=(-fs/2):F:(fs/2)-F;
R = 2000; % Resistance
C = 1.5*10^(-8); % Capacitance (15 nF)
RC = R*C; % Time contant
h = (1/RC) .* exp(-t/RC) .* heaviside(t); % Impulse response of RC LPF
x2 = heaviside(t-0.002) - heaviside(t-0.0025); % box function
y2 = conv(h, x2)*Ts;
figure(3) % Plot result
subplot(2,1,2), plot(t, y2(1:N), 'Linewidth', 2.0)
axis([0 0.004 0 1.2])
xlabel('Time, sec', 'Fontsize', 14), ylabel('y_2(t)', 'Fontsize', 14)
grid on
Which has given the graph:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1662506/image.png)
The graph itself seems correct but when substituting random values of t, the graph is incorrect (it should be 1 from 2.5 and beyond, not reducing to 0 like here). Am I missing something here? Maybe in hand calculation it shouldn't be -tau but I have to take into account the -0.00225 shift for tau too? That would create a big e^(0.00225/RC) constant which I'm skeptical
Thank you
0 Comments
Accepted Answer
Paul
on 7 Apr 2024
Hi Nghi,
Why should the output of system remain at 1 for t > 2.5? For t > 2.5, the input is 0 and so we'd expect the output to decay to zero from that time because the system is stable.
heaviside(0)
which is not really what you want when using a discrete-time convolution sum with conv to approximate the continuous-time convolution integral. That can be changed with sympref, or write your own unit step function
u = @(t) double(t>=0);
0 Comments
More Answers (0)
See Also
Categories
Find more on Array and Matrix Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!