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.
Subsystem with unknown characteristics.
Next, let's declare an auxiliary function to run the model.
# Подключение вспомогательной функции запуска модели.
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
Let's run the model and analyse the recorded data.
run_model("freqrespLTI") # Запуск модели.
inp = collect(inp);
inp = inp.value;
out = collect(out);
out = out.value;
Plot the spectrum for input and output values.
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")
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.