# Calculate Impulse Response of a System From Its Input/Output Waveform via FFT

From the theory, I knew something like :

$$y(n) = x(n)*h(n)$$

$$Y(n) = X(n)H(n)$$

$$H(n) = \frac{Y(n)}{X(n)}$$

Now I have $$y(n)$$ and $$x(n)$$ from a system, and $$y(n)$$ is 2176 samples long, $$x(n)$$ is 2176 samples long. However, if I used following code to calculate impluse response, it wasn't correct to me, anyone could help figure out where I am wrong ?

bit = load('C:\Users\wangyang\Desktop\bit_wf.txt')

x = bit(:,2)

subplot(2,1,1)
plot(x)
title('x(n)')

y = sbr(:,2)

subplot(2,1,2)
plot(y)
title('y(n)')

X = fft(x)
Y = fft(y)
h = ifft(Y/X)
plot(h) %plot impulse response If I used ./ instead of / to calucalte the h as folloiwng:

X = fft(x)
Y = fft(y)
h = ifft(Y./X)
plot(h) %plot impulse response


The h looks like as following : Thanks so much.

• One way to test your current approach is to plot conv(h, x) over the top of the y that you do have. For a more concrete metric, see what the difference is mean(abs(y - conv(h, x))) – Engineer Apr 28 at 11:52
• I failed to do that, I found my h is not a vector, so I can't do conv operation, the size(h) is 2716*2716, I don't know how to extract the proper vector from it for this calculation. – WangYang.Cao Apr 28 at 16:24
• In MATLAB, component wise division is ./ not /. Try making that change – Engineer Apr 28 at 16:27
• Also, if h is a matrix what are you showing in your last plot? – Engineer Apr 28 at 16:27
• I just used the / to get h as showed above, and the last diagram is just result from plot(h) directly, I also updated the plot if I used ./ for reference. – WangYang.Cao Apr 28 at 17:09

It would be best to upload the exact data for $$x[n]$$ and $$y[n]$$, but the reason I think of, is that either at least one of your signals is not a perfect baseband signal and has considerable amount of energy everywhere, or (this one is more probable) the signals are baseband but your sampling rate is not high enough, hence the Nyquist criterion is not satisfied and aliasing has occurred. In the latter case, try increasing the number of samples per each signal. Note that this is also an approximate, because the DFT package of MATLAB operates on discrete signals, yet with truncation in both time and frequency.