How do I get the average of a signal over every certain time duration (simulink)?
109 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponse acceptée
Jon
le 8 Nov 2021
Modifié(e) : Jon
le 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 commentaires
Jon
le 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.
Plus de réponses (1)
Joana Urbano
le 12 Avr 2024 à 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 commentaire
Paul
le 12 Avr 2024 à 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.
Voir également
Catégories
En savoir plus sur Discontinuities dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!