Simple multi-channel filter
In this example, we will analyze the possibilities of filtering frames in multi-channel mode using the example of a simple FIR filter.
The figure below shows the model we are studying.
in this demo.
In this model, three different types of signals are applied to the input, after which each of them passes through a filter. At the output, we can analyze all the signals together, or each signal separately.
Before starting the model analysis, we will set two auxiliary functions – the model launch function and the audio player function.
Pkg.add(["WAV"])
# Подключение вспомогательной функции запуска модели.
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
using WAV;
using .EngeeDSP;
function audioplayer(patch, fs, Samples_per_audio_channel);
s = vcat((EngeeDSP.step(load_audio(), patch, Samples_per_audio_channel))...);
buf = IOBuffer();
wavwrite(s, buf; Fs=fs);
data = base64encode(unsafe_string(pointer(buf.data), buf.size));
display("text/html", """<audio controls="controls" {autoplay}>
<source src="data:audio/wav;base64,$data" type="audio/wav" />
Your browser does not support the audio element.
</audio>""");
return s
end
Now let's run the model, and then analyze the results.
run_model("simple_filt_multichannel") # Запуск модели.
out = collect(out);
out = out.value;
Let's plot the display of all three channels of the system output.
n = 50;
Chirp = zeros(n,1);
Sine = zeros(n,1);
Signal = zeros(n,1);
for i in 1:n
a = out[i]
Chirp[i] = a[1]
Sine[i] = a[2]
Signal[i] = a[3]
end
plot(Chirp, label="Chirp")
plot!(Sine, label="Sine")
plot!(Signal, label="Signal")
On the graph, the three signals have a completely different character, and we can easily distinguish them from each other.
Now let's analyze two audio tracks – the original one and the one recorded from the model.
audioplayer("$(@__DIR__)/OSR_us_000_0030_8k.wav", 8000, 256);
audioplayer("$(@__DIR__)/output.wav", 8000, 256);
On the recording, you can hear that after filtering, the audio track does contain less extraneous noise.
Conclusion
We have explored the possibilities of multi-channel data processing. This approach is often found in communication systems and is very much in demand by developers.