Engee documentation
Notebook

Logarithmic amplitude-phase frequency response

In this example, the following steps are taken to construct a logarithmic amplitude-phase frequency response:

  1. A sine wave with a preset frequency has been created.
  2. Fast Fourier transform (FFT) is applied to the signal.
  3. Amplitude and phase are calculated.
  4. The amplitude characteristic on a logarithmic scale and the phase characteristic are constructed.

Before starting work, it is necessary to connect the FFTW library, which contains FFT functions.

In [ ]:
using FFTW

Now let's set the parameters of our signal.

In [ ]:
fs = 1000;    # Частота дискретизации, Гц
T = 1.0;      # Длительность, с
f_sin = 50;   # Частота синусоиды, Гц

Next, we will set a time sample for our data and generate a sinusoidal signal.

In [ ]:
t = 0:1/fs:T  # Время
x = sin.(2π * f_sin * t)  # Сигнал - синусоида
plot(t,x)
Out[0]:

Let's apply the fast Fourier transform to the generated signal.

In [ ]:
X = fft(x)
n = length(x)
freqs = (0:n-1) * (fs / n)
Out[0]:
0.0:0.999000999000999:999.000999000999

Calculate the amplitude and phase of the input signal.

In [ ]:
amplitude = abs.(X)
plot(amplitude)
Out[0]:
In [ ]:
phase = angle.(X)
plot(phase)
Out[0]:

Let's construct the amplitude response on a logarithmic scale.

In [ ]:
plot(freqs[1:div(n, 2)], 20 * log10.(amplitude[1:div(n, 2)]), title="Amplitude Response (dB)", xlabel="Frequency (Hz)", ylabel="Amplitude (dB)", legend=false)
Out[0]:

Let's construct a phase characteristic.

In [ ]:
plot(freqs[1:div(n, 2)], phase[1:div(n, 2)], title="Phase Response", xlabel="Frequency (Hz)", ylabel="Phase (radians)", legend=false)
Out[0]:

Conclusion

In this example, we have analyzed the possibilities of constructing frequency response on a logarithmic scale and frequency response for an arbitrary signal.