How do I get the average of a signal over every certain time duration (simulink)?

106 ビュー (過去 30 日間)
Hamza Ali
Hamza Ali 2021 年 11 月 8 日
コメント済み: Paul 2024 年 4 月 12 日 11:51
What I want do is I want to find the average over every 0.1 seconds of this signal, and output it as another signal within simulink. I've only been able to compute the overall average of this signal, not for every certain time duration.
To give some background, this is an amplitude key shifted bitstream. The duration a bit lasts is 0.1 seconds. If the bit is 1 it is represented by a sinusoid with a maximum of ~1 and a minimum of 0 (as can be seen in from 0 to 0.1 seconds of the signal). If the bit is 0, the signal is simply 0 for 0.1 seconds.
Therefore, once I average every bit duration (0.1s) the 1's will be represented as a value of ~0.5 as that is the average value of the sinusoid which represents a 1. Also, every 0 will be represented by a 0, because every 0 bit is represented by a value 0 lasting for 0.1 seconds.
If anyone could point me in the right direction, that would be greatly appreciated.

採用された回答

Jon
Jon 2021 年 11 月 8 日
編集済み: Jon 2021 年 11 月 8 日
So I'm assuming you are looking for an output signal that has a sampling period of 0.1 seconds, which gives the average value of the last 0.1 seconds of data. I think you could do this with the combination of an integrator and a zero order hold. The idea would be to integrate the signal for 0.1 seconds, then divide by 0.1 seconds (giving the average value) then reset the integrator to zero. You would then pass that signal throuh a zero order hold block (in discrete blocks) using a sample time of 0.1 seconds to get just the average values.
Note you would have to set the external reset parameter of the integrator block to provide an external reset port, for example with a rising signal. Then drive this with the output of a pulse generator source block set with a 0.1 second period.
You may have to put in a little phase delay on the pulse so the signal doesn't get reset before the zero order hold samples it.
  4 件のコメント
Hamza Ali
Hamza Ali 2021 年 11 月 9 日
@Paul This worked perfectly. Thank you so much for the help guys.
Jon
Jon 2021 年 11 月 9 日
Hi Hamza,
Glad you got this working. I don't have the Communication Toolbox, so I couldn't try your example directly. By the way if you have the communication toolbox, maybe you could just use the derepeat block. https://www.mathworks.com/help/comm/ref/derepeat.html. I think it might do what you want but I couldn't try it.
I tried to see if I could find an issue with resetting the integrator I have attached a small model based on yours. I had to add some blocks to generate the input signal, as I couldn' t run yours which needed the Communication Toolbox. I don't see any problem getting the integrator to reset in this example and I don't think I'm doing anything fundamentally different than you.

サインインしてコメントする。

その他の回答 (1 件)

Joana Urbano
Joana Urbano 2024 年 4 月 12 日 9:07
@Paul @Hamza Ali Hello, I had the same problem and tried this approach. In my case, I have a simulation time of 600s and need to determine the average of my input every 30s.
I was expecting an output of 20 average values. With this, I get those 20 correct average values, but, in the beggining my output is 0. So, basically, my output has 21 values: first a 0 and then the 20 expected average values. Do you know why this is happening and what should I do to correct it?
Thanks a lot!
  1 件のコメント
Paul
Paul 2024 年 4 月 12 日 11:51
It sounds like the initial value of whatever averaging scheme your using. In other words, the initial value of the average is zero, and that value is held until t = 30, at which time the output becomes the average value over the interval from t = 0 to t = 30.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDiscontinuities についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by