使用 Engee 函数的 AGC 模型¶ AGC(自动增益控制)是一种在通信系统中控制信号强度的方法。
是通信系统中的一种信号电平控制技术,其主要目的是
是通信系统中的一种信号电平控制技术,其主要目的
是通信系统中的一种信号电平控制技术,其主要目的是在输入信号的振幅发生变化时保持输出信号的稳定电平。
AGC 应用实例
1.在收音机中,无论接收信号的强度如何,它都能帮助稳定音量。
无论接收信号的强度如何。
2.在音频系统中,即使音源音量突然变化,它也能保持稳定的录音电平。
2. 在音频系统中,即使音源音量突然变化,它也能保持稳定的录音音量。
因此,AGC 可在各种条件下提供舒适和高质量的信号接收/回放。
在各种条件下接收/播放信号。
我们实现的模型如下。
该模型有一个 Engee 功能块,用于实现计算增益的算法。
计算增益的算法。包络变量是一个类似于 MATLAB 常量变量(持久 )的变量。它是本地的
但同时,它在每一步计算中都不会被重置,而是会存储上一步的值。
也就是说,它们在函数调用之间被保存在内存中。
在两次函数调用之间保存在内存中。
让我们仔细看看这个函数的实现。
1.区块结构
块是一种继承于
AbstractCausalComponent 的结构。它包含一个
envelope 字段,其类型为 Float64,用于存储信号的包络值。
用于存储信号的包络值。
Block() 构造函数本身会初始化
一个新的 Block 对象,其初始
包络值等于 0。
2.调用功能
这是我们算法的主要函数。它
需要三个参数:t(时间)、电平和响度。
如果包络值小于 0.08,则 envelope_gain 设置为 0.08。
否则,将使用当前的包络值。
函数返回响度值除以 envelope_gain、
即增益的最终值
增益的最终值。
3.功能更新!
此函数更新对象
块。它计算电平与当前包络值之间的差值。
如果差值为正,则包络值将增加该差值的 80%。
差值。否则,包络值将减少该差值的 1%。因此
函数将返回一个更新后的 Block 对象,以便我们存储和重新定义它。
在每个计算步骤中,我们都可以存储和重新定义该值。
既然我们已经决定了如何组织模型,接下来就开始运行并分析结果吧。
Out[0]:
run_model (generic function with 1 method)
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")
)
让我们比较一下模型输入和输出的第一个通道的其中一个帧。
我们可以看到,该帧输出信号的振幅明显低于输入信号的振幅。
比输入信号的振幅低得多、
这表明我们的函数工作正常。
现在让我们来听听这两个音轨的声音。
Your browser does not support the audio element.
Your browser does not support the audio element.
从这个例子可以看出,我们的自动信号增益控制算法运行正常。
{"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}}