# MATLAB - deriving frequency response from impulse response

Discussion in 'Programmer's Corner' started by kdillinger, Dec 5, 2009.

1. ### kdillinger Thread Starter Active Member

Jul 26, 2009
141
3
Hello,

I am trying to write a MATLAB routine that will plot the frequency response of a circuit based on the circuits impulse response.

For starters, I am using a simple RC low pass filter with values of R=1kΩ and C=1μF. The transfer function will be:

(1/RC)/(s+(1/RC)) or 1000/(s+1000).

The commands I am using are:

num=[1000];
den=[1 1000];
Hs=tf(num,den);
ImpRes=impulse(Hs);
MagFFT=abs(fft(ImpRes));
plot(MagFFT);

I am confident up until the plot of the magnitude of the fft. Any ideas?

2. ### kdillinger Thread Starter Active Member

Jul 26, 2009
141
3
109 views and no replies.

I decided to skip writing my own FFT in MATLAB and use the freqs routine instead.

An FFT will come at a later date.

3. ### guitarguy12387 Active Member

Apr 10, 2008
359
12
I don't understand... whats the issue? Did you get an unexpected/incorrect result?

4. ### kdillinger Thread Starter Active Member

Jul 26, 2009
141
3
The problem is I am getting what appears to be incorrect results. I am entering a transfer function; i.e., 1000/(s+1000), getting the impulse response and then taking the FFT of that data. I am expecting the frequency response. More importantly, a frequency response as in gain & phase vs. frequency. But I am having difficulty formatting the results.

5. ### guitarguy12387 Active Member

Apr 10, 2008
359
12
Why don't you just plot the abs of your original transfer function? Oh also, plot on a loglog() axis