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

54 views (last 30 days)
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.

Accepted Answer

Jon
Jon on 8 Nov 2021
Edited: Jon on 8 Nov 2021
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 Comments
Jon
Jon on 9 Nov 2021
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.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!