Effacer les filtres
Effacer les filtres

Is there any other way to realize Simulink Block of "Tapped Delay" function?

2 vues (au cours des 30 derniers jours)
wang hua
wang hua le 25 Oct 2012
I just want to realize some function ,store a series data into a array,just like this below:
double x;
double y[200];
int i=0;
step_interrupt(void)
{
y[i]=x;
i++;
if(i==200)
i=0;
}
So, I just realize it by Block of "Tapped Delay" in Discrete, like this <<http://xjtudownload.googlecode.com/files/1.jpg>>,but when I generated the code,it's so inefficiency,just like this:
32 void test_step(void)
33 {
34 int_T i;
35
36 /* S-Function (sfix_udelay): '<Root>/Tapped Delay' */
37 memcpy(&y[0], &test_DWork.TappedDelay_X[0], 200U * sizeof(real_T));
38
39 /* Update for S-Function (sfix_udelay): '<Root>/Tapped Delay' incorporates:
40 * Update for Inport: '<Root>/In1'
41 */
42 for (i = 0; i < 199; i++) {
43 test_DWork.TappedDelay_X[i] = test_DWork.TappedDelay_X[i + 1];
44 }
45
46 test_DWork.TappedDelay_X[199] = x;
47
48 /* End of Update for S-Function (sfix_udelay): '<Root>/Tapped Delay' */
49 }
I think some Block like "Delay" in Discrete Library have the Circular buffer function,except "Tapped Delay" Block. how can I realize it ?

Réponse acceptée

wang hua
wang hua le 26 Oct 2012
thank Ryan, you have encouraged me. I have solved it today by using the Delay Block.Connect the input to a Delay Block with Terminator Block instead "Tapped Delay" Block.
  1 commentaire
wang hua
wang hua le 26 Oct 2012
now,it's generate code like this, I think it solved.
21 real_T x; /* '<Root>/In1' */
22
23 /* Exported block states */
24 real_T y[200]; /* '<Root>/Delay' */
34 void temp_step(void)
35 {
36 /* Update for Delay: '<Root>/Delay' incorporates:
37 * Update for Inport: '<Root>/In1'
38 */
39 y[temp_DWork.CircBufIdx] = x;
40 if (temp_DWork.CircBufIdx < 199U) {
41 temp_DWork.CircBufIdx++;
42 } else {
43 temp_DWork.CircBufIdx = 0U;
44 }
45
46 /* End of Update for Delay: '<Root>/Delay' */
47 }

Connectez-vous pour commenter.

Plus de réponses (1)

Ryan G
Ryan G le 25 Oct 2012
Modifié(e) : Ryan G le 25 Oct 2012
You can try changing some of the optimizations in the configuration parameters to see if that changes the generated code at all. Otherwise, this may be the only way it is generated, in which case you should submit an enhancement request if you believe the circular method is better.
Furthermore, you could write an s-function of your own using the code you specified instead of the built in block.

Catégories

En savoir plus sur Simulink Coder dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by