3
$\begingroup$

Having an impulse response of an audio system recorded as a wav file, how to calculate the frequency response of the system with octave?

$\endgroup$
1
$\begingroup$

I recommend using freqz in Octave as this computes samples of the DTFT (Discrete Time Fourier Transform) instead of the DFT. The DTFT is a continuous function of frequency, which is more likely what you would want to see if you are looking for the frequency response. (freqz([time domain vector])).

To see this clearly, consider the simplest FIR filter specified by the impulse response [1 1]. This is a two tap FIR filter with unity gain coefficients, and the frequency response is a continuous function given by the following equation, describing the expected low pass filter result:

$$F(\omega) = 1 + e^{-j\omega}$$

Where $\omega$ is the normalized radian frequency with the sampling rate $f_s = 2\pi $

This result is the DTFT of the sampled impulse response, not the DFT (which the FFT computes).

The FFT (fft([1 1]) would return just two samples on this frequency response, but freqz would provide 512 samples (default) of the true frequency response as described in the equation above. You could also simply do (fft[1 1], 512) to zero pad the fft as this will also return samples on the DTFT. (512 in this case to match the default number of samples used in freqz).

Result for freqz([1 1]):

enter image description here

Note that the frequency resolution of your answer will be 1/T where T is the length of the audio file. Adding zeros to the time domain sequence does NOT increase frequency resolution. For more detailed explanations on the difference between the DTFT and DFT please see:

For 2D signals can it be said that the frequency response is the same as the Fourier transform?

$\endgroup$
6
  • $\begingroup$ How does freqz return a continuous function? It returns a frequency response vector evaluated at a discrete set of frequencies. If those frequencies are equidistant, it uses an FFT, otherwise it uses Horner's method for polynomial evaluation. $\endgroup$
    – Matt L.
    Feb 25 '17 at 8:42
  • $\begingroup$ True, it returns what would appear to be a continuous function when plotted as it interpolates all samples between the number of points in your sampled impulse response, up to any number of samples desired. (Unlike an FFT but just like an FFT that is zero padded on both ends). I will reword that as of course it is not truly a continuous function, thanks! $\endgroup$ Feb 25 '17 at 13:07
  • $\begingroup$ Besides the plotting abilities (Or plotting oriented) of freqz it adds no information to fft. When you plot the fft the graphical engine interpolates between the points. $\endgroup$
    – Royi
    Feb 25 '17 at 14:46
  • $\begingroup$ For a discrete impulse response, freqz does tell you what the response would be for the frequency points that are in between the samples provided by the fft: Consider the FIR described by [1 1]: freqz and the DTFT would accurately predict the amplitude and phase of an input that is at normalized frequency of fs/8 (for example). Point is the user wants the freq response not the FFT. $\endgroup$ Feb 25 '17 at 15:01
  • $\begingroup$ (See my other post linked in my answer on the difference between the DTFT and DFT. The FFT is the DFT, and freqz returns samples of the DTFT. (Just as you would get by zero padding at the beginning and end of your sequence in the time domain, which adds frequency samples but does not change the freq resolution--- but it does provide the frequency response accurately at those frequency locations that would otherwise not be included) $\endgroup$ Feb 25 '17 at 15:10
4
$\begingroup$

The Frequency Response of a system is the Fourier Transform of the Impulse Response of the system.

Since we're in the real world and we have finite number of samples observed over finite time interval we use the Discrete Fourier Transform (DFT).
In Ocatve and MATLAB the DFT is implemented in efficient way using the Fast Fourier Transform (FFT).

In order to calculate it on MATLAB / Octave you can do the following:

% Assuming Impulse Response is given by 'vImpulseResponse'

vFreqResponse = fft(vImpulseResponse);

figure();
plot(abs(vFreqResponse));

Enjoy.

$\endgroup$
2
$\begingroup$

For the sake of completeness, here is my solution:

fs = 44100;                       # sampling frequency
y = wavread('i-rsp.wav');         # read wav file
b = y(:, [1]);                    # use first channel for analysis
figure(1);                        # plot the impulse response
plot(b, 'marker', '*');           # ...
[h, w] = freqz (b, 1, 512, fs);   # calculate frequncy response
figure(2);                        # plot the frequncy response
freqz_plot(w, h);                 # ...

octave impulse response octave frequency response

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.