AGC model using Engee Function¶ AGC (Automatic Gain Control) is a method of controlling the signal strength in communication systems.
is a signal level control technique in communication systems whose main purpose
is to maintain a stable level
of the output signal as the amplitude of the input signal changes.
Examples of AGC applications
In radios, it helps to stabilise the volume of the sound
regardless of the strength of the received signal.
In audio systems, it maintains a constant recording level
even with sudden changes in the volume of the audio source.
Thus, AGC provides comfortable and high quality signal reception/playback in various conditions.
reception/playback of signals in various conditions.
The model we have realised is presented below.
The model has an Engee Function block, which implements the algorim
for calculating the gain in this function. The envelope variable is an analogue of MATLAB constant variable ( persistent ). It is local
for the function in which it is created, but at the same time it is not reset at each step of the
calculations, but stores the previous value in itself, i.e. they are stored in memory between function calls.
in memory between function calls.
Let's take a closer look at the implementation of this function.
Block structure
Block is a structure that inherits
from AbstractCausalComponent. It contains a field
envelope of type Float64, which is used
to store the envelope value of the signal.
The Block() constructor itself initialises
a new Block object with the initial
envelope value equal to 0.
Call function
This is the main function of our algorithm. It
takes three arguments: t (time), level and loudness.
If the envelope value is less than 0.08, envelope_gain is set to 0.08.
Otherwise, the current envelope value is used.
The function returns the loudness value divided by envelope_gain,
which is the final value of the gain
gain at a particular calculation step.
Function update!
This function updates the envelope value in the object
Block. It calculates the difference between level and the current envelope value.
If the difference is positive, envelope is increased by 80% of this difference.
difference. Otherwise, it decreases by 1% of this difference. As a result
the function returns an updated Block object, which allows us to store and redefine it.
us to store and redefine this value at each of the calculation steps.
Now that we have decided how to organise the model, let's move on to running it and analysing the results.
Out[0]:
run_model (generic function with 1 method)
Running and analysing the model¶
Building...
Progress 0%
Progress 0%
Progress 6%
Progress 6%
Progress 13%
Progress 13%
Progress 18%
Progress 18%
Progress 23%
Progress 23%
Progress 29%
Progress 29%
Progress 34%
Progress 34%
Progress 40%
Progress 40%
Progress 45%
Progress 45%
Progress 50%
Progress 50%
Progress 56%
Progress 56%
Progress 61%
Progress 61%
Progress 66%
Progress 66%
Progress 72%
Progress 72%
Progress 77%
Progress 77%
Progress 83%
Progress 83%
Progress 88%
Progress 88%
Progress 94%
Progress 94%
Progress 99%
Progress 99%
Progress 100%
Progress 100%
Progress 100%
Progress 100%
Out[0]:
SimulationResult(
"Out" => WorkspaceArray("agc_code/Out"),
"inp" => WorkspaceArray("agc_code/inp")
)
Let's compare one of the frames of the first channel at the input and output of the model.
As we can see, the amplitude of the output signal on this frame is significantly lower than the amplitude of the input signal.
is much lower than the amplitude of the input signal,
which shows us that our function is working correctly.
Now let's listen to both audio tracks.
Your browser does not support the audio element.
Your browser does not support the audio element.
Conclusion¶ As we could see from this example, our algorithm of automatic signal gain control works correctly.
{"id": "45533b05-2153-4cd5-a3e9-2e43094adad1", "data": [{"showlegend": true, "mode": "lines", "xaxis": "x", "colorbar": {"y": 0.513888888888889, "title": {"text": ""}, "len": 0.9525371828521435, "x": 0.9934383202099738}, "name": "input data", "yaxis": "y", "legendgroup": "input data", "line": {"color": "rgba(0, 154, 250, 1.000)", "shape": "linear", "dash": "solid", "width": 1}, "y": [0.008697509765625, 0.008575439453125, 0.008453369140625, 0.00836181640625, 0.00823974609375, 0.008087158203125, 0.0079345703125, 0.007781982421875, 0.00762939453125, 0.00750732421875, 0.007415771484375, 0.00738525390625, 0.007354736328125, 0.00738525390625, 0.007415771484375, 0.0074462890625, 0.007476806640625, 0.007476806640625, 0.007415771484375, 0.007354736328125, 0.00726318359375, 0.00714111328125, 0.00701904296875, 0.006927490234375, 0.0068359375, 0.0068359375, 0.006866455078125, 0.006927490234375, 0.007080078125, 0.00726318359375, 0.0074462890625, 0.007659912109375, 0.007843017578125, 0.00799560546875, 0.00811767578125, 0.008209228515625, 0.008270263671875, 0.008270263671875, 0.00823974609375, 0.00823974609375, 0.008209228515625, 0.008209228515625, 0.008209228515625, 0.008209228515625, 0.00823974609375, 0.00823974609375, 0.00823974609375, 0.008209228515625, 0.008148193359375, 0.008056640625, 0.007965087890625, 0.007904052734375, 0.00787353515625, 0.007843017578125, 0.007904052734375, 0.0079345703125, 0.008087158203125, 0.008270263671875, 0.0084228515625, 0.0086669921875, 0.00885009765625, 0.009002685546875, 0.00909423828125, 0.0091552734375, 0.0091552734375, 0.009063720703125, 0.00897216796875, 0.008819580078125, 0.008697509765625, 0.008575439453125, 0.008544921875, 0.008575439453125, 0.008697509765625, 0.00885009765625, 0.009033203125, 0.00927734375, 0.009490966796875, 0.009674072265625, 0.00982666015625, 0.009918212890625, 0.009979248046875, 0.00994873046875, 0.009918212890625, 0.009857177734375, 0.00982666015625, 0.00982666015625, 0.009857177734375, 0.009918212890625, 0.010040283203125, 0.010223388671875, 0.01043701171875, 0.0106201171875, 0.010833740234375, 0.010986328125, 0.0111083984375, 0.01116943359375, 0.011199951171875, 0.011199951171875, 0.011138916015625, 0.0111083984375, 0.01104736328125, 0.010986328125, 0.010986328125, 0.010986328125, 0.010986328125, 0.011016845703125, 0.011016845703125, 0.011016845703125, 0.010986328125, 0.01092529296875, 0.01080322265625, 0.0106201171875, 0.01043701171875, 0.010162353515625, 0.0098876953125, 0.00958251953125, 0.009307861328125, 0.009033203125, 0.00885009765625, 0.0086669921875, 0.008544921875, 0.00848388671875, 0.008453369140625, 0.00848388671875, 0.008575439453125, 0.0086669921875, 0.008758544921875, 0.00885009765625, 0.008941650390625, 0.00897216796875, 0.009002685546875, 0.009002685546875, 0.008941650390625, 0.0089111328125, 0.00885009765625, 0.008819580078125, 0.0087890625, 0.008819580078125, 0.008880615234375, 0.00897216796875, 0.009002685546875, 0.009063720703125, 0.00909423828125, 0.009063720703125, 0.009002685546875, 0.00885009765625, 0.008636474609375, 0.008453369140625, 0.008270263671875, 0.008087158203125, 0.007965087890625, 0.0079345703125, 0.007965087890625, 0.008056640625, 0.00823974609375, 0.008453369140625, 0.008697509765625, 0.00897216796875, 0.00921630859375, 0.009490966796875, 0.00970458984375, 0.00994873046875, 0.0101318359375, 0.010345458984375, 0.01055908203125, 0.0107421875, 0.010986328125, 0.01116943359375, 0.01141357421875, 0.011627197265625, 0.011810302734375, 0.011962890625, 0.0120849609375, 0.012176513671875, 0.01220703125, 0.01214599609375, 0.01202392578125, 0.0118408203125, 0.011627197265625, 0.011322021484375, 0.011016845703125, 0.0106201171875, 0.010223388671875, 0.009796142578125, 0.0093994140625, 0.009002685546875, 0.008575439453125, 0.00823974609375, 0.007965087890625, 0.0076904296875, 0.007476806640625, 0.007354736328125, 0.00726318359375, 0.007232666015625, 0.0072021484375, 0.007232666015625, 0.007293701171875, 0.007354736328125, 0.007415771484375, 0.007476806640625, 0.007598876953125, 0.007781982421875, 0.007965087890625, 0.008209228515625, 0.00848388671875, 0.0087890625, 0.00909423828125, 0.0093994140625, 0.009674072265625, 0.0098876953125, 0.01007080078125, 0.0101318359375, 0.0101318359375, 0.010101318359375, 0.00994873046875, 0.009765625, 0.00958251953125, 0.0093994140625, 0.00921630859375, 0.009033203125, 0.008941650390625, 0.00885009765625, 0.0087890625, 0.008758544921875, 0.008758544921875, 0.00872802734375, 0.008697509765625, 0.0086669921875, 0.00860595703125, 0.008514404296875, 0.0084228515625, 0.008331298828125, 0.00823974609375, 0.008148193359375, 0.00811767578125, 0.008087158203125, 0.008056640625, 0.008026123046875, 0.008026123046875, 0.00799560546875, 0.007965087890625, 0.00787353515625, 0.00775146484375, 0.00762939453125, 0.007476806640625, 0.00732421875, 0.007171630859375, 0.00701904296875, 0.00689697265625, 0.006805419921875, 0.006744384765625, 0.006683349609375, 0.00665283203125, 0.00665283203125, 0.00665283203125, 0.00665283203125], "type": "scatter", "x": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256], "zaxis": null, "z": null, "metadata": {"shouldEnableSmartZoom": false, "smartZoomParams": {"minCount": 25000, "maxCount": 256, "currentCount": 256}}}, {"showlegend": true, "mode": "lines", "xaxis": "x", "colorbar": {"y": 0.513888888888889, "title": {"text": ""}, "len": 0.9525371828521435, "x": 0.9934383202099738}, "name": "output data", "yaxis": "y", "legendgroup": "output data", "line": {"color": "rgba(227, 111, 71, 1.000)", "shape": "linear", "dash": "solid", "width": 1}, "y": [0.00069580078125, 0.00068603515625, 0.00067626953125, 0.0006689453125, 0.0006591796875, 0.00064697265625, 0.000634765625, 0.0006225585937500001, 0.0006103515625, 0.0006005859375, 0.00059326171875, 0.0005908203125, 0.00058837890625, 0.0005908203125, 0.00059326171875, 0.000595703125, 0.00059814453125, 0.00059814453125, 0.00059326171875, 0.00058837890625, 0.0005810546875, 0.0005712890625, 0.0005615234375000001, 0.00055419921875, 0.000546875, 0.000546875, 0.00054931640625, 0.00055419921875, 0.00056640625, 0.0005810546875, 0.000595703125, 0.0006127929687500001, 0.00062744140625, 0.0006396484375, 0.0006494140625, 0.00065673828125, 0.00066162109375, 0.00066162109375, 0.0006591796875, 0.0006591796875, 0.00065673828125, 0.00065673828125, 0.00065673828125, 0.00065673828125, 0.0006591796875, 0.0006591796875, 0.0006591796875, 0.00065673828125, 0.00065185546875, 0.00064453125, 0.00063720703125, 0.00063232421875, 0.0006298828125, 0.00062744140625, 0.00063232421875, 0.000634765625, 0.00064697265625, 0.00066162109375, 0.0006738281250000001, 0.000693359375, 0.0007080078125, 0.00072021484375, 0.0007275390625, 0.000732421875, 0.000732421875, 0.00072509765625, 0.0007177734375, 0.00070556640625, 0.00069580078125, 0.00068603515625, 0.0006835937500000001, 0.00068603515625, 0.00069580078125, 0.0007080078125, 0.00072265625, 0.0007421875, 0.00075927734375, 0.00077392578125, 0.0007861328125, 0.00079345703125, 0.00079833984375, 0.0007958984375000001, 0.00079345703125, 0.00078857421875, 0.0007861328125, 0.0007861328125, 0.00078857421875, 0.00079345703125, 0.00080322265625, 0.00081787109375, 0.0008349609375, 0.000849609375, 0.0008666992187500001, 0.00087890625, 0.000888671875, 0.0008935546875, 0.00089599609375, 0.00089599609375, 0.00089111328125, 0.000888671875, 0.0008837890625, 0.00087890625, 0.00087890625, 0.00087890625, 0.00087890625, 0.00088134765625, 0.00088134765625, 0.00088134765625, 0.00087890625, 0.0008740234375, 0.0008642578125, 0.000849609375, 0.0008349609375, 0.00081298828125, 0.000791015625, 0.0007666015625, 0.0007446289062500001, 0.00072265625, 0.0007080078125, 0.000693359375, 0.0006835937500000001, 0.0006787109375000001, 0.00067626953125, 0.0006787109375000001, 0.00068603515625, 0.000693359375, 0.00070068359375, 0.0007080078125, 0.00071533203125, 0.0007177734375, 0.00072021484375, 0.00072021484375, 0.00071533203125, 0.000712890625, 0.0007080078125, 0.00070556640625, 0.000703125, 0.00070556640625, 0.00071044921875, 0.0007177734375, 0.00072021484375, 0.00072509765625, 0.0007275390625, 0.00072509765625, 0.00072021484375, 0.0007080078125, 0.00069091796875, 0.00067626953125, 0.00066162109375, 0.00064697265625, 0.00063720703125, 0.000634765625, 0.00063720703125, 0.00064453125, 0.0006591796875, 0.00067626953125, 0.00069580078125, 0.0007177734375, 0.0007373046875, 0.00075927734375, 0.0007763671875, 0.0007958984375000001, 0.0008105468750000001, 0.00082763671875, 0.0008447265625, 0.000859375, 0.00087890625, 0.0008935546875, 0.0009130859375, 0.00093017578125, 0.00094482421875, 0.00095703125, 0.000966796875, 0.00097412109375, 0.0009765625, 0.0009716796875, 0.0009619140625, 0.000947265625, 0.00093017578125, 0.00090576171875, 0.00088134765625, 0.000849609375, 0.00081787109375, 0.00078369140625, 0.000751953125, 0.00072021484375, 0.00068603515625, 0.0006591796875, 0.00063720703125, 0.000615234375, 0.00059814453125, 0.00058837890625, 0.0005810546875, 0.00057861328125, 0.000576171875, 0.00057861328125, 0.00058349609375, 0.00058837890625, 0.00059326171875, 0.00059814453125, 0.00060791015625, 0.0006225585937500001, 0.00063720703125, 0.00065673828125, 0.0006787109375000001, 0.000703125, 0.0007275390625, 0.000751953125, 0.00077392578125, 0.000791015625, 0.0008056640625000001, 0.0008105468750000001, 0.0008105468750000001, 0.00080810546875, 0.0007958984375000001, 0.00078125, 0.0007666015625, 0.000751953125, 0.0007373046875, 0.00072265625, 0.00071533203125, 0.0007080078125, 0.000703125, 0.00070068359375, 0.00070068359375, 0.0006982421875, 0.00069580078125, 0.000693359375, 0.0006884765625, 0.00068115234375, 0.0006738281250000001, 0.00066650390625, 0.0006591796875, 0.00065185546875, 0.0006494140625, 0.00064697265625, 0.00064453125, 0.00064208984375, 0.00064208984375, 0.0006396484375, 0.00063720703125, 0.0006298828125, 0.0006201171875, 0.0006103515625, 0.00059814453125, 0.0005859375, 0.00057373046875, 0.0005615234375000001, 0.0005517578125000001, 0.00054443359375, 0.00053955078125, 0.00053466796875, 0.0005322265625, 0.0005322265625, 0.0005322265625, 0.0005322265625], "type": "scatter", "x": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256], "zaxis": null, "z": null, "metadata": {"shouldEnableSmartZoom": false, "smartZoomParams": {"minCount": 25000, "maxCount": 256, "currentCount": 256}}}], "config": {"showlegend": true, "xaxis": {"showticklabels": true, "gridwidth": 0.5, "tickvals": [0, 50, 100, 150, 200, 250], "range": [-6.650000000000006, 263.65], "domain": [0.09545056867891513, 0.9934383202099738], "mirror": false, "tickangle": 0, "showline": true, "ticktext": ["0", "50", "100", "150", "200", "250"], "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "y", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "paper_bgcolor": "rgba(255, 255, 255, 1.000)", "annotations": [], "height": 400, "margin": {"l": 0, "b": 20, "r": 0, "t": 20}, "plot_bgcolor": "rgba(255, 255, 255, 1.000)", "yaxis": {"showticklabels": true, "gridwidth": 0.5, "tickvals": [0.0025, 0.005, 0.0075, 0.01, 0.0125], "range": [0.00018198242187500002, 0.012557275390625], "domain": [0.03762029746281716, 0.9901574803149606], "mirror": false, "tickangle": 0, "showline": true, "ticktext": ["0.0025", "0.0050", "0.0075", "0.0100", "0.0125"], "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "x", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "legend": {"yanchor": "auto", "xanchor": "auto", "bordercolor": "rgba(0, 0, 0, 1)", "bgcolor": "rgba(255, 255, 255, 1.000)", "borderwidth": 1, "tracegroupgap": 0, "y": 1, "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "title": {"font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}, "text": ""}, "traceorder": "normal", "x": 1}, "width": 955.21875}}