Engee documentation
Notebook

Determination of the frequency response of the system

In this example, we describe the application of spectral analysis to determine the frequency response of an unknown discrete system.

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

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

In this example, we take a random source to generate white noise. The figures below show our model.

Top level of the model. image.png

Subsystem with unknown characteristics.

image_2.png

Next, let's declare an auxiliary function to run 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 analyse 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%

Plot the spectrum for 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 seen that there are clear frequency regions in the output signal that are cancelled out by our system. Based on this data, we can determine the frequency response of the system in detail.

Blocks used in example