# Impulse Response from Complex Frequency Response

Discussion in 'MATLAB' started by Kurt, Aug 6, 2004.

1. ### KurtGuest

I'm having a hard time constructing an impulse response from a
frequency response. I have a complex frequency response and the
corresponding frequency data that I want to convert into an impulse
response. This can be done using an ifft, correct?

To test how it all works, I created a simple lowpass filter, then
used the bode command to extract the magnitude and phase data. I
combined these into a complex number and then attempted to perform an
ifft on it. The result was compared to the result of the matlab
function impulse(H) where H is the transfer function of the lowpass
filter.

I've never been able to get the same results using an ifft as I can
using the impulse command on the transfer function. I won't have a
transfer function when I use collected data, so an ifft is the only
way to go.

I included the code I'm using below, does anyone see where I'm going
wrong? I can never get the two plots at the end to match..

Thanks for any help.

% Setup 4096 Frequency Points
w = 2e8 : 4.8791e7 : 2e11

fc = 10e8;
RC = ((sqrt(3)) / (2*pi*fc));

% Lowpass Filter
H = tf([(1/(RC))], [1 (1/(RC))])

% Bode Plot on Transfer Function & Save Data
[mag,phase] = bode(H,w);

% Z is Complex Number (Frequency Response)
Z = mag ).*exp(i*phase )* (pi/180));

% Setup Time Step for ifft
Z_Size = size(Z,1);
T_S = (1 / max(w));
t = 0:T_S Z_Size-1)*T_S;

% Compute ifft
Z_Doubled = [Z; fliplr(conj(Z))];
Z_ifft = real((ifft(Z_Doubled)) / (2*T_S));
Z_Impulse = Z_ifft(1:Z_Size);

% Plot Impulse Responses
figure(1);

%ifft version
plot(t,Z_Impulse,'b-');
hold on;

% Impulse(H) version
[y1,t1] = impulse(H,t)
plot(t1,y1,'r-');

Kurt, Aug 6, 2004

2. ### George DixonGuest

Kurt,

I have had a quick look, and at the upper frequency you are
considering, the absolute value of Z is still 0.02.

It is possible that applying a window, to taper your frequency
response to zero at the extremes, and then applying a correction
factor to restore the magnitude will give you better matching between
the two methods you are considering.

'help window' will let you browse a selection of window types, you
should find one that goes to zero at the extremes, like the hanning
window.

There are some formulae which help you find this windowing correction
factor - sorry, I can't remember which book they are in, possibly
Bendat & Piersol, or Newland.

I hope this helps,

George

George Dixon, Aug 9, 2004