Difference between revisions of "Aufgaben:Exercise 4.11: C Program "acf1""

From LNTwww
(Die Seite wurde neu angelegt: „ {{quiz-Header|Buchseite=Stochastische Signaltheorie/Autokorrelationsfunktion (AKF) }} right| :Sie sehen nebenstehend das C-…“)
 
 
(30 intermediate revisions by 4 users not shown)
Line 1: Line 1:
  
{{quiz-Header|Buchseite=Stochastische Signaltheorie/Autokorrelationsfunktion (AKF)
+
{{quiz-Header|Buchseite=Theory_of_Stochastic_Signals/Auto-Correlation_Function
 
}}
 
}}
  
[[File:P_ID391__Sto_A_4_11.png|right|]]
+
[[File:EN_Sto_A_4_11_neu2.png|right|frame|C program  $1$  for the ACF calculation]]
:Sie sehen nebenstehend das C-Programm &bdquo;akf1&rdquo; zur Berechnung der diskreten AKF-Werte <i>&phi;<sub>x</sub></i>(<i>k</i>) mit dem Index <i>k</i> = 0, ... , <i>l</i>. Hierzu ist Folgendes zu bemerken:
+
See the C&ndash;program "acf1" for calculating the discrete ACF values&nbsp; $\varphi_x(k)$&nbsp; with index&nbsp; $k = 0$, ... , $l$.&nbsp; The following should be noted about this:
  
:* Der an das Programm &uuml;bergebene Long-Wert sei <i>l</i>&nbsp;=&nbsp;10. Die AKF-Werte <i>&phi;<sub>x</sub></i>(0), ... , <i>&phi;<sub>x</sub></i>(10) werden mit dem Float-Feld <i>AKF</i>[ ] an das aufrufende Programm zur&uuml;ckgegeben. In den  Zeilen 7 und  8 wird dieses Feld mit Nullen vorbelegt.
+
* The long&ndash;value passed to the program is&nbsp; $l = 10$.&nbsp; The ACF values&nbsp; $\varphi_x(0)$, ... , $\varphi_x(10)$&nbsp; are returned to the calling program with the float field&nbsp; $\rm ACF\big[ \ \big]$.&nbsp; In lines 7 and 8 of the program given on the right,&nbsp; this field is pre-populated with zeros.
  
:* Die zu analysierenden Zufallsgr&ouml;&szlig;en <i>x<sub>&nu;</sub></i> werden mit der Float-Funktion <i>x</i>( ) erzeugt (siehe Zeile 4). Diese Funktion wird insgesamt <i>N</i> + <i>l</i> + 1 = 10011 mal aufgerufen (Zeile 9 und 18).
+
* The random variables&nbsp; $x_\nu$&nbsp; to be analyzed are generated with the float function&nbsp; $x( \ )$,&nbsp; see line 4.&nbsp; This function is called a total of&nbsp; $N + l + 1 = 10011$&nbsp; times&nbsp; $x_\nu$&nbsp; (lines 9 and 18).
  
:* Im Gegensatz zu dem im Kapitel 4.4 angegebenen Algorithmus, der im Programm &bdquo;akf2&rdquo; von Aufgabe Z4.11 direkt umgesetzt ist, ben&ouml;tigt man hier ein Hilfsfeld <i>H</i>[&nbsp;] mit nur <i>l</i> + 1 = 11 Speicherelementen.
+
* In contrast to the algorithm given in the&nbsp; [[Theory_of_Stochastic_Signals/Auto-Correlation_Function#Numerical_ACF_determination|Theory section]]&nbsp; directly implemented in the program&nbsp; "acf2"&nbsp; of&nbsp; [[Aufgaben:Exercise_4.11Z:_C_Program_"acf2"|Task 4.11Z]],&nbsp; one needs here an auxiliary field&nbsp; ${\rm H}\big[ \ \big]$&nbsp; with only&nbsp; $l + 1 = 11$&nbsp; memory elements.
  
:* Vor Beginn des eigentlichen Berechnungsalgorithmus (Zeile 11 bis 21) stehen in den 11 Speicherzellen die Zufallswerte <i>x</i><sub>1</sub> ... <i>x</i><sub>11</sub>.
+
* Before starting the actual calculation algorithm&nbsp;(lines 11 to 21),&nbsp; the eleven memory cells of&nbsp; ${\rm H}\big[ \ \big]$&nbsp; contain the random values&nbsp; $x_1$, ... ,&nbsp; $x_{11}$.&nbsp; The outer loop with the index&nbsp; $z$ &nbsp; (marked in red)&nbsp; is run&nbsp; $N$&nbsp; times.
 +
*In the inner loop &nbsp; (marked white)&nbsp; with the index&nbsp; $k = 0$, ... ,&nbsp; $l$&nbsp; all memory cells of the field&nbsp; ${\rm ACF}\big[\hspace{0.03cm} k \hspace{0.03cm} \big]$&nbsp; are increased by the contribution&nbsp; $x_\nu \cdot x_{\nu+k}$.
  
:* Die &auml;u&szlig;ere Schleife mit der Laufvariablen <i>z</i> (rot markiert) wird <i>N</i>-mal durchlaufen. In der inneren Schleife (wei&szlig; markiert) werden mit dem Laufindex <i>k</i> = 0, ... , <i>l</i> alle Speicherzellen des Feldes <i>AKF</i>[<i>k</i>] um den Betrag <i>x<sub>&nu;</sub></i> &middot; <i>x<sub>&nu; + k</sub></i> erh&ouml;ht.
+
* Finally,&nbsp; in lines 22 and 23,&nbsp; all ACF values are divided by the number&nbsp; $N$&nbsp; of analyzed  data.  
  
:* In den Zeilen 22 und 23 werden schlie&szlig;lich alle AKF-Werte durch die Anzahl <i>N</i> dividiert.
 
  
:<b>Hinweis:</b> Diese Aufgabe bezieht sich auf die Theorieseite Numerische Ermittlung der AKF.
 
  
  
===Fragebogen===
+
 
 +
 
 +
Hint:
 +
*This exercise belongs to the chapter&nbsp; [[Theory_of_Stochastic_Signals/Auto-Correlation_Function|Auto-Correlation Function]].
 +
*Reference is made in particular to the page&nbsp; [[Theory_of_Stochastic_Signals/Auto-Correlation_Function#Numerical_ACF_determination|Numerical ACF determination]].
 +
 +
 
 +
 
 +
 
 +
===Questions===
  
 
<quiz display=simple>
 
<quiz display=simple>
{Welche Elemente <i>i</i> und <i>j</i> des Hilfsfeldes <i>H</i>[ ... ] werden beim ersten Durchlauf (<i>z</i> = 0) zur Berechnung des AKF-Wertes <i>&phi;<sub>x</sub></i>(<i>k</i> = 6) verwendet? Welche Zufallswerte <i>x<sub>&nu;</sub></i> stehen in diesen Speicherzellen?
+
{Which elements&nbsp; $i$&nbsp; and&nbsp; $j$&nbsp; of the auxiliary field&nbsp; ${\rm H}\big[ \ \big]$&nbsp; are used&nbsp; <u>on the first loop pass</u> &nbsp; $(z=0)$&nbsp; to calculate the ACF&ndash;value&nbsp; $\varphi(k=6)$&nbsp;? <br>What random values&nbsp; $x_\nu$&nbsp; are in these memory cells?
 
|type="{}"}
 
|type="{}"}
$i$ = - { 0 3% }
+
$i \ = \ $ { 0. }
$j$ = { 6 3% }
+
$j \ = \ $ { 6 }
  
  
{Welche Speicherzelle  <i>H</i>[<i>i</i>] wird nach dem ersten Schleifendurchgang (<i>z</i> = 0) mit einer neuen Zufallsgr&ouml;&szlig;e <i>x<sub>&nu;</sub></i> belegt? Welcher Index <i>&nu;</i> wird dabei eingetragen?
+
{Which memory cell&nbsp; ${\rm H}\big[\hspace{0.03cm} i \hspace{0.03cm} \big]$&nbsp; will be occupied&nbsp; <u>after the first loop pass</u> &nbsp; $(z=0)$&nbsp; with a new random variable&nbsp; $x_\nu$&nbsp;? <br> Which index &nbsp; $\nu$&nbsp; is entered in the process?  
 
|type="{}"}
 
|type="{}"}
$i$ = { 0 3% }
+
$i \ = \ $   { 0. }
$v$ = { 12 3% }
+
$\nu\ =\ $ { 12 }
  
  
{Welche Speicherelemente <i>H</i>[<i>i</i>] und <i>H</i>[<i>j</i>] werden beim Schleifendurchlauf <i>z</i> = 83 zur Berechnung des AKF-Wertes <i>&phi;<sub>x</sub></i>(<i>k</i> = 6) verwendet? Welche Zufallswerte stehen in diesen Speicherzellen?
+
{Which memory elements&nbsp; ${\rm H}\big[\hspace{0.03cm} i \hspace{0.03cm} \big]$&nbsp; and&nbsp; ${\rm H}\big[\hspace{0.03cm} j \hspace{0.03cm} \big]$&nbsp; are used in the loop pass&nbsp; $z=83$&nbsp; to calculate the ACF value&nbsp; $\varphi(k=6)$&nbsp;? <br>What random values are in these memory cells?
 
|type="{}"}
 
|type="{}"}
$i$ = { 6 3% }
+
$i \ = \ $   { 6 }
$j$ = { 1 3% }
+
$j \ = \ $ { 1 }
 +
 
  
  
Line 45: Line 54:
 
</quiz>
 
</quiz>
  
===Musterlösung===
+
===Solution===
 
{{ML-Kopf}}
 
{{ML-Kopf}}
:<b>1.</b>&nbsp;&nbsp;Aus <i>z</i> = 0 und <i>k</i> = 6 ergibt sich gem&auml;&szlig; dem Programm: <u><i>i</i> = 0</u> und <u><i>j</i> = 6</u>. Die entsprechenden Speicherinhalte sind <i>H</i>[0] = <i>x</i><sub>1</sub> und <i>H</i>[6] = <i>x</i><sub>7</sub>.
+
[[File:P_ID417__Sto_A_4_11_b.png|right|frame|For the exemplary numerical ACF calculation]]
 +
<br>
 +
'''(1)'''&nbsp; With&nbsp; $z= 0$&nbsp; and&nbsp; $k=6$&nbsp; results according to the program: &nbsp; $\underline{i= 0}$&nbsp; and&nbsp; $\underline{j= 6}$.
 +
*The corresponding memory contents are&nbsp; ${\rm H}\big[\hspace{0.03cm} 0 \hspace{0.03cm}\big] = x_1$&nbsp; and&nbsp; ${\rm H}\big[\hspace{0.03cm} 6 \hspace{0.03cm}\big] = x_7$.
 +
 
 +
 
 +
 
 +
 
 +
'''(2)'''&nbsp; In the field&nbsp; ${\rm H}\big[\hspace{0.03cm} 0 \hspace{0.03cm}\big]$&nbsp; the random variable&nbsp; $x_{12}$&nbsp; is now entered:
 +
:$$\text{memory cell }\underline{i= 0},\hspace{1cm}\text{sequence index }\underline{\nu= 12}.$$
 +
 
  
:<b>2.</b>&nbsp; &nbsp;In das Feld <i>H</i>[0] wird die Zufallsgr&ouml;&szlig;e <i>x</i><sub>12</sub> eingetragen: <u><i>i</i> = 0, Index <i>&nu;</i> = 12</u>.
 
  
:<b>3.</b>&nbsp;&nbsp;Das nachfolgende Bild zeigt die Belegung des Hilfsfeldes <i>H</i>[0] ... <i>H</i>[10] mit den Zufallswerten <i>x<sub>&nu;</sub></i>. Jeweils gr&uuml;n hinterlegt ist die Speicherzelle <i>H</i>[<i>i</i>]. In diesen Speicherplatz wird jeweils am Ende der Schleife (Zeile 18) die neue Zufallsgr&ouml;&szlig;e eingetragen.
+
'''(3)'''&nbsp; The graph shows the allocation of the auxiliary field with the random values&nbsp; $x_\nu$.  
[[File:P_ID417__Sto_A_4_11_b.png|center|]]
 
  
:F&uuml;r <i>z</i> = 83 und <i>k</i> = 6 ergibt sich <u><i>i</i> = 83 mod 11 = 6</u> und <u><i>j</i> = (<i>i</i> + <i>k</i>) mod 11 = 1</u>. In diesen Speicherzellen liegen die Zufallsgr&ouml;&szlig;en <i>x</i><sub>84</sub> und <i>x</i><sub>90</sub>. Am Ende des Schleifendurchlaufs <i>z</i> = 83 wird in <i>H</i>[6] der Wert <i>x</i><sub>84</sub> durch <i>x</i><sub>95</sub> ersetzt.
+
*In each case,&nbsp; the memory cell&nbsp; ${\rm H}\big[\hspace{0.03cm} i \hspace{0.03cm}\big]$&nbsp; is highlighted in green.&nbsp; The new random variable is entered into this memory location at the end of each loop&nbsp; (line 18).
 +
*For&nbsp; $z= 83$&nbsp; and&nbsp; $K=6$&nbsp; this results in
 +
:$$\underline{i= 83 \hspace{-0.2cm}\mod \hspace{-0.15cm} \ 11 = 6},\hspace{1cm} \underline{j= (i+k)\hspace{-0.2cm}\mod \hspace{-0.15cm} \ 11 = 1}.$$
 +
*Loop pass&nbsp; $z= 83$: &nbsp; In memory cell&nbsp; ${\rm H}\big[\hspace{0.03cm} 6 \hspace{0.03cm}\big]$&nbsp; is the random variable&nbsp; $x_{84}$&nbsp; and in the memory cell&nbsp; ${\rm H}\big[\hspace{0.03cm} 1 \hspace{0.03cm}\big]$&nbsp; is the random variable&nbsp; $x_{90}$.  
 +
*At the end of loop pass&nbsp; $z= 83$&nbsp; in&nbsp; ${\rm H}\big[\hspace{0.03cm} 6 \hspace{0.03cm}\big]$:&nbsp; The content&nbsp; $x_{84}$&nbsp; is replaced by&nbsp; $x_{95}$&nbsp;.
 
{{ML-Fuß}}
 
{{ML-Fuß}}
  
  
  
[[Category:Aufgaben zu Stochastische Signaltheorie|^4.4 Autokorrelationsfunktion (AKF)^]]
+
[[Category:Theory of Stochastic Signals: Exercises|^4.4 Auto-Correlation Function^]]

Latest revision as of 16:28, 28 April 2022

C program  $1$  for the ACF calculation

See the C–program "acf1" for calculating the discrete ACF values  $\varphi_x(k)$  with index  $k = 0$, ... , $l$.  The following should be noted about this:

  • The long–value passed to the program is  $l = 10$.  The ACF values  $\varphi_x(0)$, ... , $\varphi_x(10)$  are returned to the calling program with the float field  $\rm ACF\big[ \ \big]$.  In lines 7 and 8 of the program given on the right,  this field is pre-populated with zeros.
  • The random variables  $x_\nu$  to be analyzed are generated with the float function  $x( \ )$,  see line 4.  This function is called a total of  $N + l + 1 = 10011$  times  $x_\nu$  (lines 9 and 18).
  • In contrast to the algorithm given in the  Theory section  directly implemented in the program  "acf2"  of  Task 4.11Z,  one needs here an auxiliary field  ${\rm H}\big[ \ \big]$  with only  $l + 1 = 11$  memory elements.
  • Before starting the actual calculation algorithm (lines 11 to 21),  the eleven memory cells of  ${\rm H}\big[ \ \big]$  contain the random values  $x_1$, ... ,  $x_{11}$.  The outer loop with the index  $z$   (marked in red)  is run  $N$  times.
  • In the inner loop   (marked white)  with the index  $k = 0$, ... ,  $l$  all memory cells of the field  ${\rm ACF}\big[\hspace{0.03cm} k \hspace{0.03cm} \big]$  are increased by the contribution  $x_\nu \cdot x_{\nu+k}$.
  • Finally,  in lines 22 and 23,  all ACF values are divided by the number  $N$  of analyzed data.




Hint:



Questions

1

Which elements  $i$  and  $j$  of the auxiliary field  ${\rm H}\big[ \ \big]$  are used  on the first loop pass   $(z=0)$  to calculate the ACF–value  $\varphi(k=6)$ ?
What random values  $x_\nu$  are in these memory cells?

$i \ = \ $

$j \ = \ $

2

Which memory cell  ${\rm H}\big[\hspace{0.03cm} i \hspace{0.03cm} \big]$  will be occupied  after the first loop pass   $(z=0)$  with a new random variable  $x_\nu$ ?
Which index   $\nu$  is entered in the process?

$i \ = \ $

$\nu\ =\ $

3

Which memory elements  ${\rm H}\big[\hspace{0.03cm} i \hspace{0.03cm} \big]$  and  ${\rm H}\big[\hspace{0.03cm} j \hspace{0.03cm} \big]$  are used in the loop pass  $z=83$  to calculate the ACF value  $\varphi(k=6)$ ?
What random values are in these memory cells?

$i \ = \ $

$j \ = \ $


Solution

For the exemplary numerical ACF calculation


(1)  With  $z= 0$  and  $k=6$  results according to the program:   $\underline{i= 0}$  and  $\underline{j= 6}$.

  • The corresponding memory contents are  ${\rm H}\big[\hspace{0.03cm} 0 \hspace{0.03cm}\big] = x_1$  and  ${\rm H}\big[\hspace{0.03cm} 6 \hspace{0.03cm}\big] = x_7$.



(2)  In the field  ${\rm H}\big[\hspace{0.03cm} 0 \hspace{0.03cm}\big]$  the random variable  $x_{12}$  is now entered:

$$\text{memory cell }\underline{i= 0},\hspace{1cm}\text{sequence index }\underline{\nu= 12}.$$


(3)  The graph shows the allocation of the auxiliary field with the random values  $x_\nu$.

  • In each case,  the memory cell  ${\rm H}\big[\hspace{0.03cm} i \hspace{0.03cm}\big]$  is highlighted in green.  The new random variable is entered into this memory location at the end of each loop  (line 18).
  • For  $z= 83$  and  $K=6$  this results in
$$\underline{i= 83 \hspace{-0.2cm}\mod \hspace{-0.15cm} \ 11 = 6},\hspace{1cm} \underline{j= (i+k)\hspace{-0.2cm}\mod \hspace{-0.15cm} \ 11 = 1}.$$
  • Loop pass  $z= 83$:   In memory cell  ${\rm H}\big[\hspace{0.03cm} 6 \hspace{0.03cm}\big]$  is the random variable  $x_{84}$  and in the memory cell  ${\rm H}\big[\hspace{0.03cm} 1 \hspace{0.03cm}\big]$  is the random variable  $x_{90}$.
  • At the end of loop pass  $z= 83$  in  ${\rm H}\big[\hspace{0.03cm} 6 \hspace{0.03cm}\big]$:  The content  $x_{84}$  is replaced by  $x_{95}$ .