# What is the formula to calculate the frequency response?

I'm newbie of dsp so i have a question for u guys:

• signal= [ -0.0018225230, -0.0015879294, +0.0000000000, +0.0036977508, +0.0080754303, +0.0085302217, -0.0000000000, -0.0173976984, -0.0341458607, -0.0333591565, +0.0000000000, +0.0676308395, +0.1522061835, +0.2229246956, +0.2504960933, +0.2229246956, +0.1522061835, +0.0676308395, +0.0000000000, -0.0333591565, -0.0341458607, -0.0173976984, -0.0000000000, +0.0085302217, +0.0080754303, +0.0036977508, +0.0000000000, -0.0015879294, -0.0018225230 ]

• I have the signal as above and I want to find the frequency response of this thing but I can not. So can anyone help me find it.

• Thank you !!

• I assume you want a power spectrum. Have you tried FFT? The command abs(fft(signal)) could give you the spectral magnitudes. If you know the sample rate, you could scale your FFT bins accordingly (the x-axis) and plot your power spectrum using the plot command. – Moses Browne Mwakyanjala Apr 17 at 10:06

Given the symmetric coefficients and that the plot is similar to a Sinc function, The "signal" appears to be the coefficients of a linear-phase low pass FIR filter (Since the FT of a Sinc is a rectangular pulse, and the coefficients of the filter are samples of the impulse response, and the FT of the impulse response is the frequency response- so if the impulse response was a Sinc, the frequency response would be a rectangular function). The frequency response can be plotted using scipy.signal.freqz in python (or freqz in Matlab/Octave) which would in this case return samples of the Discrete Time Fourier Transform, which is the frequency response of the filter.

Here is the result below of the magnitude response using w, h = sig.freqz(signal) and plotting the dB magnitude of h:

The full Python code is:

import scipy.signal as sig
import matplotlib.pyplot as plt
import numpy as np

signal= [ -0.0018225230, -0.0015879294, +0.0000000000, +0.0036977508,  +0.0080754303, +0.0085302217, -0.0000000000, -0.0173976984, -0.0341458607, -0.0333591565, +0.0000000000, +0.0676308395, +0.1522061835, +0.2229246956, +0.2504960933, +0.2229246956, +0.1522061835, +0.0676308395, +0.0000000000, -0.0333591565, -0.0341458607, -0.0173976984, -0.0000000000, +0.0085302217, +0.0080754303, +0.0036977508, +0.0000000000, -0.0015879294, -0.0018225230 ]

w,h = sig.freqz(signal)
plt.figure()

plt.plot(w, 20*np.log10(abs(h)))


• Thank you for that. Can u give me the code for more clearly <3 – Tu Le Anh Apr 17 at 15:03
• i cant even import scipy.signal.freqz :( There is no freqz on my scioy package. – Tu Le Anh Apr 17 at 15:13
• import scipy.signal as sig and then call the sig.freqz – Dan Boschen Apr 17 at 15:33
• Could you tell how you manged to guess it was fir lowpass filter coefficient? – Ran Greidi Apr 17 at 16:36
• A linear phase filter will always have symmetric (or anti-symmetric) coefficients. Next any such form that appears to look similar to a Sinc function will be a low pass filter since the frequency response is the FT of the impulse response and the coefficients are the impulse response. A perfect low pass filter (not realizable) is a rectangular function in frequency so a Sinc function in time. So just by plotting the coefficients you can recognize that familiar form. Actual implementations will taper the Sinc to reduce sidelobes in the response. (windowing is one approach) – Dan Boschen Apr 17 at 17:45

Whenever one has data to analyze, a first thing to do is to visualize it in different shapes: time series, histograms, etc. From this observation, you can imagine the DSP tools you can use to model, estimate, predict feature about your signal.

Here, we only have a vector of values. No time stamp, so we don't know whether the signal is properly sampled, uniform or not, at which rate. So let us start by supposing that the sampling is uniform.

Here is how your data looks. It seems to be informative (not random, has symmetry). It has odd length. It wiggles a bit, yet the average is clearly above zero, so the most prominent frequency is likely to be the DC or the constant mean. Indeed, you can check the sum of the values of your data: it is one. So this is a unit-sum-valued sequence. Like a window.

Yet, the shape of the peak and the side rebounds look like they have a "similar" period (with attenuation). It may look like a "cardinal sine" or sinc function.

So let us have a look at the one-sided Fourier transform, and adding (in red) a closely matching sinc shape. What is important here is that with a numerical model, you can verify some computations, and maybe find a closer match.

• Thank you for that. I love your enthusiasm. But i dont think take a similar function to calculate is best choice. – Tu Le Anh Apr 17 at 15:15
• This is the topic: |-plot the signal |- convert into frequency, plot real/imaginary/magnitude/phase |- signal = [ -0.0018225230, -0.0015879294, +0.0000000000, +0.0036977508, +0.0080754303, +0.0085302217, -0.0000000000, -0.0173976984, -0.0341458607, -0.0333591565, +0.0000000000, +0.0676308395, +0.1522061835, +0.2229246956, +0.2504960933, +0.2229246956, +0.1522061835, +0.0676308395, +0.0000000000, -0.0333591565, -0.0341458607, -0.0173976984, -0.0000000000, +0.0085302217, +0.0080754303, +0.0036977508, +0.0000000000, -0.0015879294, -0.0018225230 ] – Tu Le Anh Apr 17 at 15:17
• A similar function with a known or comparable Fourier transform can help understand properties – Laurent Duval Apr 17 at 15:20
• Yes, i agree that but is there exist any way to find the correct frequency ? – Tu Le Anh Apr 17 at 15:29
• @TuLeAnh Yes: fft(signal). – a concerned citizen Apr 17 at 17:03