My question is quite simple but I have some difficulties finding an answer to it. I was wondering what was the difference between the impulse and step response functions in MATLAB. The "help" section did not help me to understand the difference.
[Math] Difference between impulse and step response.
MATLAB
Related Solutions
An impulse response should be independent of the stimulus. For example, given input signal $f(x)$ and impulse response $h(x)$, the output signal $y(x)$ is generated as follows:
$$y(x) = f(x) {\Large *} h(x)$$
This relationship holds true for any input signal we choose to apply. Let's say you want an impulse response that makes $y(x) = f(x)$. The the solution is $h(x) = \delta(x)$ where $\delta$ signifies the Dirac Delta Function.
$$y(x) = f(x) {\Large *} \delta(x) = f(x)$$
Now let's say that I want my output to be a scaled version of my output.
$$y(x) = f(x) {\Large *} \left(\tfrac{1}{2}\delta(x)\right) = \tfrac{1}{2}f(x)$$
What if I want my output to be a delayed version of my output?
$$y(x) = f(x) {\Large *} \delta(x-\tau) = f(x-\tau)$$
For linear time-invariant systems, you are free to make any linear combination of impulse responses that you would like. That means that
$$y(x) = f(x) {\Large *} \left(\tfrac{1}{2}\delta(x) + \delta(x-\tau)\right) = \tfrac{1}{2}f(x) + f(x-\tau) \qquad (1)$$
So the output in this situation is A scaled copy with no delay added to a full-scale copy of the signal with a delay of $\tau$ seconds.
Finally, how do we use dirac delta function in Matlab? Let's say that I want to implement equation (1) in Matlab. This corresponds the following impulse response, which I break into two separate impulse responses:
$$h(x) = h_1(x) + h_2(x) = \tfrac{1}{2}\delta(x) + \delta(x-\tau)$$
Since we are working in discrete time, I need my $\tau$ to be in terms of samples. Let's say that I am looking for a delay of 1000 samples.
tau = 1000;
h1 = [0.5, zeros(1, tau)];
h2 = [zeros(1, tau) 1];
h = h1 + h2;
y = conv(f,h);
Notice that in the impulse response h2
I placed the 1 at the index 1001 rather than 1000. This is because putting a 1 at the first index corresponds to no delay, so I needed to add 1000 to that in order to delay my signal. Also, I made h1
longer than it needs to be. In fact, h1
could have just been h1 = 0.5
, since trailing zeros will have no effect in the convolution. However, I wanted to make it the same length as h2
so that I could add the two of them together.
Hopefully this is enough to get you started.
After some work and help from a colleague, I managed to get an answer. For posterity, here it is:
And apparently, yes, we're supposed to use convolution from the fact that we're asked for impulse response.
% Creating our sine-signal
clear
t = -50:50;
Fs = 25;
x=sin(2*pi*(1/Fs)*t);
% Creating our impulse responses. They're unit steps, going from all-zeroes to all-ones.
h1 = [zeros(1,50) ones(1,50)];
h2 = [zeros(1,40) ones(1,60)];
% Calculating the convolusion result of the square signals above with our original sine-signal.
convPlot1 = conv(x,h1);
convPlot2 = conv(x,h2);
% Plot and check our result.
plot(convPlot1)
plot(convPlot2)
Best Answer
The impulse response provides the response of the system (output response) for the exact input value given. For instance, if I need the output response for the time input of 10 secs I get the output accordingly. On the other hand, step response provides the response within the limit of the input.