Engee documentation
Notebook

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.

image.png

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.

In [ ]:
Pkg.add(["WAV"])
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)
In [ ]:
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 
Out[0]:
audioplayer (generic function with 1 method)

Now let's run the model, and then analyze the results.

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

out = collect(out);
out = out.value;
Building...
Progress 0%
Progress 5%
Progress 10%
Progress 15%
Progress 20%
Progress 25%
Progress 30%
Progress 35%
Progress 40%
Progress 45%
Progress 50%
Progress 55%
Progress 60%
Progress 65%
Progress 70%
Progress 75%
Progress 80%
Progress 85%
Progress 90%
Progress 95%
Progress 100%
Progress 100%

Let's plot the display of all three channels of the system output.

In [ ]:
n = 50;
Chirp = zeros(n,1);
Sine = zeros(n,1);
Signal = zeros(n,1);
In [ ]:
for i in 1:n 
   a = out[i]
   Chirp[i] = a[1]
   Sine[i] = a[2]
   Signal[i] = a[3]
end 
In [ ]:
plot(Chirp, label="Chirp")
plot!(Sine, label="Sine")
plot!(Signal, label="Signal")
Out[0]:

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.

In [ ]:
audioplayer("$(@__DIR__)/OSR_us_000_0030_8k.wav", 8000, 256);
In [ ]:
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.