I have measured time signals of input (pink noise) and output of a system. I need to calculate TF of a system and it's impulse response.
In order to calculate TF I can do in Matlab directly TF = tfestimate(in, out)
or compute fft
of both then do TF = fft(out)./fft(in)
. At this point everything is clear and expected for me, but then when I calculate Impulse response of the system by doing ifft(fft(out)./fft(in))
I get impulse response which has a tail at the end. I was thinking maybe something wrong with my measurements and decided to repeat experiment in matlab synthesizing exponential chirp and passing it trough a filter with following impulse response calculation. Then I get the "same" tale at the end:
Impulse response with a "tail" at the end
Please see the code below
t = 0:1/48000:10;
fo = 1;
f1 = 24000;
x = chirp(t,fo,10,f1,'logarithmic');
x = x(:);
y = lowpass(x,1000,48000);
y = y(:);
% playing with FFT length here
% nfft=length(x)*2-1;
% nfft = 4*1024;
nfft=length(x);
tf = tfestimate(x, y, hann(nfft), nfft/2, nfft, 48000);
if mod(length(tf),2)==0 % iseven
tf_sym = conj(tf(end:-1:2));
else
tf_sym = conj(tf(end-1:-1:2));
end
ir_from_tfestimate = ifft([tf; tf_sym]);
in = fft(x, nfft);
out = fft(y, nfft);
tf1 = out./in;
ir_from_fft = ifft(tf1);
figure
stem(ir_from_tfestimate)
hold on
stem(ir_from_fft)
set(gca, 'XScale', 'log')
So I am wondering what is the nature of this tale? Maybe there is a mistake in my code? I was google and looking for this problem/explanation, but did not find anything
Can it be related how I define nfft and what is the right choice for number of points? Can we say if nfft is defined not correctly, impulse response will not be correct?
When I am trying to recover symmetric part of a spectrum obtained from
tfestimate
, am I doing it correctly: ?
if mod(length(tf),2)==0 % iseven tf_sym = conj(tf(end:-1:2)); else; tf_sym = conj(tf(end-1:-1:2));end
Thank you!