Engee documentation
Notebook

Determination of the frequency response of the system

In this example, we will analyze the use of spectral analysis to determine the frequency response of an unknown discrete system.

The easiest way is
to apply a flat spectrum signal to the input. The spectrum of the output signal in this case will
be the frequency response of the system.

There are two ways to get a flat-spectrum signal: use white noise or a pulse signal.

In this example, a random source is used to generate white noise. The pictures below show our model.

The top level of the model.
image.png

A subsystem with unknown characteristics.

image_2.png

Next, we will declare an auxiliary function for launching the model.

In [ ]:
# Подключение вспомогательной функции запуска модели.
function run_model( name_model)
    
    Path = (@__DIR__) * "/" * name_model * ".engee"
    
    if name_model in [m.name for m in engee.get_all_models()] # Проверка условия загрузки модели в ядро
        model = engee.open( name_model ) # Открыть модель
        model_output = engee.run( model, verbose=true ); # Запустить модель
    else
        model = engee.load( Path, force=true ) # Загрузить модель
        model_output = engee.run( model, verbose=true ); # Запустить модель
        engee.close( name_model, force=true ); # Закрыть модель
    end
    sleep(5)
    return model_output
end
Out[0]:
run_model (generic function with 1 method)

Let's run the model and analyze the recorded data.

In [ ]:
run_model("freqrespLTI") # Запуск модели.

inp = collect(inp);
inp = inp.value;
out = collect(out);
out = out.value;
Building...
Progress 0%
Progress 6%
Progress 11%
Progress 17%
Progress 23%
Progress 35%
Progress 42%
Progress 51%
Progress 67%
Progress 81%
Progress 87%
Progress 95%
Progress 100%
Progress 100%

Let's construct a spectrum for the input and output values.

In [ ]:
using FFTW
fs = 100
gr()
plot(fftfreq(length(inp[1:2000]), fs), abs.(fft(inp[1:2000])./length(inp[1:2000])), 
        xguide="Frequency  / Hz", yguide="Magnitude")
plot!(fftfreq(length(out[1:2000]), fs), abs.(fft(out[1:2000])./length(out[1:2000])), 
        xguide="Frequency  / Hz", yguide="Magnitude")
Out[0]:

Conclusion

We have made sure that there are obvious frequency regions in the output signal that are suppressed by our system. Based on these data, we can determine in detail the frequency response of the system.