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)')

sbr = load('C:\Users\wangyang\Desktop\wf.txt')

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))) Apr 28, 2020 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. Apr 28, 2020 at 16:24
• In MATLAB, component wise division is ./ not /. Try making that change Apr 28, 2020 at 16:27
• Also, if h is a matrix what are you showing in your last plot? Apr 28, 2020 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. Apr 28, 2020 at 17:09

2 Answers

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.

• Thanks, Ayaz, I am not sure how to attach the file here, they are 2000+ lines for each. They should be perfect baseband signal, and I generated them from a tool called ADS. The sample is 32 samples per UI. And they are 4 period of 0000_1_0000, 32*9 = 544 samples per period, 2176 samples for 4 period in total. Apr 27, 2020 at 19:00

A periodic signal has a line spectrum. Which means that your $$X(n)$$ has lots of zeros and dividing by it is not a good idea: this is a very ill-conditioned problem. Usually transfer functions are evaluated using aperiodic noise signals that don't exhibit non-zero stretches in the frequency domain.

Also FFT is primarily a computational tool rather than an analytical one since it applies only to discrete periodic signals with a fixed $$2^N$$ period. Applying it to any other kind of signal will require a fair bunch of trickery to make it deliver useful results.