# getting frequency response from input and output signal

How does one get the frequency response of a filter, given an input signal and the signal output by the filter?

• If you have access to MATLAB, then you can use tfestimate. If not but you do have access to fft then you can write an equivalent function yourself. – fibonatic May 6 '16 at 19:54

What you are looking for is probably an empirical transfer-function estimate (ETFE). Several methods can be used, but Welch's averaged periodogram  is arguably the most used .

The plant output data is usually generated using Gaussian white-noise excitation, although more informative input signals can be generated by experiment design, if prior information about the plant is known . The ETFE of the plant $\widehat{G}(k)$ is found as the quotient of the cross power spectral density estimate of the input and the measured output $P_{yu}(k)$, and the power spectral density estimate of the input $P_{uu}(k)$, i.e., \begin{equation*} \widehat{G}(k) = \frac{P_{yu}(k)}{P_{uu}(k)} . \end{equation*} In Welch's method, the time-series data is divided into windowed segments, with an option to use overlapping segments. Then, a modified periodogram of each segment is computed and the results are averaged. Welch's method for generating an ETFE corresponds to the function tfestimate in MATLAB. One of the advantages of Welch's method is the flexibility in terms of the number of frequency samples and excitation signal used.

Frequency response is simply the ratio of the Fourier transforms of the output and input signals.

$$H(e^{j\omega}) = \frac{Y(e^{j\omega})}{X(e^{j\omega})}$$

where $Y(e^{j\omega})$ is the Fourier transform of output $y[n]$:

$$Y(e^{j\omega}) = \sum\limits_{n=-\infty}^{+\infty} y[n] e^{-j\omega n}$$

and $X(e^{j\omega})$ is the Fourier transform of input $x[n]$:

$$X(e^{j\omega}) = \sum\limits_{n=-\infty}^{+\infty} x[n] e^{-j\omega n}$$

It might be a good idea to choose an input $x[n]$ such that $X(e^{j\omega}) \ne 0$ for all $\omega$ of interest in the frequency response.

• Keep in mind that this equation for $H(\omega)$ only holds for linear systems. Also, if the input signal has zero energy at certain frequencies you cannot know the transfer function (i.e. frequency response in this context) at these frequencies. – applesoup May 15 '16 at 17:43
• @applesoup: You can get a "best linear approximation" to non-linear systems, which might be useful in some situations, such as when synthesizing a robust control law for a given steady-state operating point. – Arnfinn Aug 5 '16 at 4:55
if you give an impulse as input , frequency response of output signal is equal to frequency response of filter.
This technique is efficient only if you don't know filter specifications.


So that I m assuming you know nothing about filter specifications. Here this matlab code implement the technique.

fs=1000;
impulse=[1 zeros(1,999)];
f=linspace(-fs/2,fs/2,length(impulse));
hpass=fdesign.highpass('Fst,Fp,Ast,Ap',100,200,40,1,fs);
Hdhp=design(hpass,'butter');
y=filter(Hdhp,impulse);
figure,plot(f,fftshift(abs(fft(y,fs))));