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

From LNTwww
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|frame|C-Programm  $1$  zur AKF–Berechnung '''Korrektur''']]
+
[[File:P_ID391__Sto_A_4_11.png|right|frame|C program  $1$  for AKF–calculation '''correction''']]
Sie sehen nebenstehend das C–Programm "akf1" zur Berechnung der diskreten AKF-Werte  $\varphi_x(k)$  mit dem Index  $k = 0$, ... , $l$.  Hierzu ist Folgendes zu bemerken:
+
See the C–program "akf1" for calculating the discrete AKF values  $\varphi_x(k)$  with index  $k = 0$, ... , $l$.  The following should be noted about this:
  
* Der an das Programm übergebene Long–Wert sei  $l = 10$.  Die AKF-Werte  $\varphi_x(0)$, ... , $\varphi_x(10)$  werden mit dem Float-Feld  $\rm AKF\big[ \ \big]$  an das aufrufende Programm zurückgegeben. In den  Zeilen 7 und  8 des rechts anggebenen Programms wird dieses Feld mit Nullen vorbelegt.
+
* Let the long–value passed to the program  $l = 10$.  The AKF values  $\varphi_x(0)$, ... , $\varphi_x(10)$  are returned to the calling program with the float field  $\rm AKF\big[ \ \big]$  . In lines 7 and 8 of the program given on the right, this field is pre-populated with zeros.
  
* Die zu analysierenden Zufallsgrößen  $x_\nu$  werden mit der Float-Funktion  $x( \ )$  erzeugt (siehe Zeile 4).  Diese Funktion wird insgesamt  $N + l + 1 = 10011$  mal aufgerufen (Zeile 9 und 18).
+
* The random variables to be analyzed  $x_\nu$  are generated with the float function  $x( \ )$  (see line 4).  This function is called a total of  $N + l + 1 = 10011$  times (lines 9 and 18).
  
* Im Gegensatz zu dem im  [[Theory_of_Stochastic_Signals/Autokorrelationsfunktion_(AKF)#Numerische_AKF-Ermittlung|Theorieteil]]  angegebenen Algorithmus, der im Programm  "akf2"  von  [[Aufgaben:4.11Z_C-Programm_„akf2”|Aufgabe 4.11Z]]  direkt umgesetzt ist, benötigt man hier ein Hilfsfeld  ${\rm H}\big[ \ \big]$  mit nur  $l + 1 = 11$  Speicherelementen.
+
* In contrast to the algorithm given in the  [[Theory_of_Stochastic_Signals/Auto-Correlation_Function#Numerical_ACF_determinationTheory section]]  program  "akf2"  of  [[Aufgaben:Exercise_4.11Z:_C_Program_"acf2"|Task 4.11Z]]  directly implemented, one needs here an auxiliary field  ${\rm H}\big[ \ \big]$  with only  $l + 1 = 11$  memory elements.
 +
11Z_C-Programm_"akf2"|Task 4.11Z]]  directly implemented, one needs here an auxiliary field  ${\rm H}\big[ \ \big]$  with only  $l + 1 = 11$  memory elements.
  
* Vor Beginn des eigentlichen Berechnungsalgorithmus (Zeile 11 bis 21) stehen in den elf Speicherzellen von  ${\rm H}\big[ \  \big]$  die Zufallswerte  $x_1$, ... ,  $x_{11}$.
 
  
* Die äußere Schleife mit der Laufvariablen  $z$  (rot markiert) wird  $N$-mal durchlaufen.  
+
* 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}$.
*In der inneren Schleife  (weiß markiert)  werden mit dem Laufindex  $k = 0$, ... ,  $l$  alle Speicherzellen des Feldes  ${\rm AKF}\big[\hspace{0.03cm} k \hspace{0.03cm} \big]$  um den Beitrag  $x_\nu \cdot x_{\nu+k}$  erhöht.
+
*The outer loop with the run variable  $z$  (marked in red) is run  $N$ times.  
 +
*In the inner loop  (marked white)  with the run index  $k = 0$, ... ,  $l$  all memory cells of the field  ${\rm AKF}\big[\hspace{0.03cm} k \hspace{0.03cm} \big]$  are increased by the contribution  $x_\nu \cdot x_{\nu+k}$ .
  
* In den Zeilen 22 und 23 werden schließlich alle AKF–Werte durch die Anzahl  $N$  der analysierten Daten  dividiert.  
+
* Finally, in lines 22 and 23, all AKF–values are divided by the number  $N$  of data analyzed.  
  
  
Line 24: Line 25:
  
  
''Hinweise:''
+
Hint:
*Die Aufgabe gehört zum  Kapitel  [[Theory_of_Stochastic_Signals/Autokorrelationsfunktion_(AKF)|Autokorrelationsfunktion]].
+
*Die Aufgabe gehört zum  Kapitel  [[Theory_of_Stochastic_Signals/Auto-Correlation_Function|Auto-Correlation Function]].
*Bezug genommen wird insbesondere auf die Seite  [[Theory_of_Stochastic_Signals/Autokorrelationsfunktion_(AKF)#Numerische_AKF-Ermittlung|Numerische AKF-Ermittlung]].
+
*Reference is made in particular to the page  [[Theory_of_Stochastic_Signals/Auto-Correlation_Function#Numerical_ACF_determination|Numerical ACF determination]].
 
   
 
   
  
  
  
===Fragebogen===
+
===Questions===
  
 
<quiz display=simple>
 
<quiz display=simple>
{Welche Elemente&nbsp; $i$&nbsp; und&nbsp; $j$&nbsp; des Hilfsfeldes&nbsp; ${\rm H}\big[ \ \big]$&nbsp; werden <u>beim ersten Durchlauf</u>&nbsp; $(z=0)$&nbsp; zur Berechnung des AKF&ndash;Wertes&nbsp; $\varphi(k=6)$&nbsp; verwendet? <br>Welche Zufallswerte&nbsp; $x_\nu$&nbsp; 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 <u>on the first pass</u>&nbsp; $(z=0)$&nbsp; to calculate the AKF&ndash;value&nbsp; $\varphi(k=6)$&nbsp;? <br>What random values&nbsp; $x_\nu$&nbsp; are in these memory cells?
 
|type="{}"}
 
|type="{}"}
$i \ = \ $   { 0. }
+
$i \ = \ $ { 0. }
 
$j \ = \ $ { 6 }
 
$j \ = \ $ { 6 }
  
  
{Welche Speicherzelle&nbsp; ${\rm H}\big[\hspace{0.03cm} i \hspace{0.03cm} \big]$&nbsp; wird <u>nach dem ersten Schleifendurchgang</u>&nbsp; $(z=0)$&nbsp; mit einer neuen Zufallsgr&ouml;&szlig;e&nbsp; $x_\nu$&nbsp; belegt? <br>Welcher Index&nbsp; $\nu$&nbsp; wird dabei eingetragen?
+
{Which memory cell&nbsp; ${\rm H}\big[\hspace{0.03cm} i \hspace{0.03cm} \big]$&nbsp; will be occupied <u>after the first loop pass</u>&nbsp; $(z=0)$&nbsp; with a new random variable&nbsp; $x_\nu$&nbsp;?
|type="{}"}
 
$i \ = \ $  { 0. }
 
$\nu\ =\ $ { 12 }
 
  
  
{Welche Speicherelemente&nbsp; ${\rm H}\big[\hspace{0.03cm} i \hspace{0.03cm} \big]$&nbsp; und&nbsp; ${\rm H}\big[\hspace{0.03cm} j \hspace{0.03cm} \big]$&nbsp; werden beim Schleifendurchlauf&nbsp; $z=83$&nbsp; zur Berechnung des AKF-Wertes&nbsp; $\varphi(k=6)$&nbsp; verwendet? <br>Welche Zufallswerte stehen in diesen Speicherzellen?
+
{Welche Speicherelemente&nbsp; ${\rm H}\big[\hspace{0.03cm} i \hspace{0.03cm} \big]$&nbsp; und&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 AKF value&nbsp; $\varphi(k=6)$&nbsp;? <br>What random values are in these memory cells?
 
|type="{}"}
 
|type="{}"}
$i \ = \ $   { 6 }
+
$i \ = \ $ { 6 }
 
$j \ = \ $ { 1 }
 
$j \ = \ $ { 1 }
  
Line 56: Line 54:
 
</quiz>
 
</quiz>
  
===Musterlösung===
+
===Solution===
 
{{ML-Kopf}}
 
{{ML-Kopf}}
[[File:P_ID417__Sto_A_4_11_b.png|right|frame|Zur numerischen AKF-Berechnung]]
+
[[File:P_ID417__Sto_A_4_11_b.png|right|frame|For numerical AKF calculation]]
 
<br>
 
<br>
'''(1)'''&nbsp; Mit&nbsp; $z= 0$&nbsp; und&nbsp; $k=6$&nbsp; ergibt sich gem&auml;&szlig; dem Programm: &nbsp; $\underline{i= 0}$&nbsp; und&nbsp; $\underline{j= 6}$.
+
'''(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}$.
*Die entsprechenden Speicherinhalte sind&nbsp; ${\rm H}\big[\hspace{0.03cm} 0 \hspace{0.03cm}\big] = x_1$&nbsp; und&nbsp; ${\rm H}\big[\hspace{0.03cm} 6 \hspace{0.03cm}\big] = x_7$.
+
*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 das Feld&nbsp; ${\rm H}\big[\hspace{0.03cm} 0 \hspace{0.03cm}\big]$&nbsp; wird nun die Zufallsgr&ouml;&szlig;e&nbsp; $x_{12}$&nbsp; eingetragen:
+
'''(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{Speicherzelle  }\underline{i= 0},\hspace{1cm}\text{Folgenindex  }\underline{\nu= 12}.$$
+
:$$\text{memory cell }\underline{i= 0},\hspace{1cm}\text{sequence index }\underline{\nu= 12}.$$
  
  
  
'''(3)'''&nbsp; Die Grafik zeigt die Belegung des Hilfsfeldes mit den Zufallswerten&nbsp; $x_\nu$.  
+
'''(3)'''&nbsp; The graph shows the allocation of the auxiliary field with the random values&nbsp; $x_\nu$.  
  
*Jeweils gr&uuml;n hinterlegt ist die Speicherzelle&nbsp; ${\rm H}\big[\hspace{0.03cm} i \hspace{0.03cm}\big]$.&nbsp; In diesen Speicherplatz wird jeweils am Ende der Schleife (Zeile 18) die neue Zufallsgr&ouml;&szlig;e eingetragen.
+
*In each case, the memory cell is highlighted in green&nbsp; ${\rm H}\big[\hspace{0.03cm} i \hspace{0.03cm}\big]$.&nbsp; The new random variable is entered into this memory location at the end of each loop (line 18).
*F&uuml;r&nbsp; $z= 83$&nbsp; und&nbsp; $K=6$&nbsp; ergibt sich
+
*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}.$$
 
:$$\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}.$$
*Schleifendurchlauf&nbsp; $z= 83$: &nbsp; In der Speicherzelle&nbsp; ${\rm H}\big[\hspace{0.03cm} 6 \hspace{0.03cm}\big]$&nbsp; steht die Zufallsgr&ouml;&szlig;e&nbsp; $x_{84}$&nbsp; und in der Speicherzelle&nbsp; ${\rm H}\big[\hspace{0.03cm} 1 \hspace{0.03cm}\big]$&nbsp; die Zufallsgr&ouml;&szlig;e&nbsp; $x_{90}$.  
+
*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}$.  
*Am Ende des Schleifendurchlaufs&nbsp; $z= 83$&nbsp; wird in&nbsp; ${\rm H}\big[\hspace{0.03cm} 6 \hspace{0.03cm}\big]$&nbsp; der Inhalt&nbsp; $x_{84}$&nbsp; durch&nbsp; $x_{95}$&nbsp; ersetzt.
+
*At the end of the 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ß}}
  

Revision as of 00:24, 1 March 2022

C program  $1$  for AKF–calculation correction

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

  • Let the long–value passed to the program  $l = 10$.  The AKF values  $\varphi_x(0)$, ... , $\varphi_x(10)$  are returned to the calling program with the float field  $\rm AKF\big[ \ \big]$  . In lines 7 and 8 of the program given on the right, this field is pre-populated with zeros.
  • The random variables to be analyzed  $x_\nu$  are generated with the float function  $x( \ )$  (see line 4).  This function is called a total of  $N + l + 1 = 10011$  times (lines 9 and 18).

11Z_C-Programm_"akf2"|Task 4.11Z]]  directly implemented, 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 run variable  $z$  (marked in red) is run  $N$ times.
  • In the inner loop  (marked white)  with the run index  $k = 0$, ... ,  $l$  all memory cells of the field  ${\rm AKF}\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 AKF–values are divided by the number  $N$  of data analyzed.




Hint:



Questions

1

Which elements  $i$  and  $j$  of the auxiliary field  ${\rm H}\big[ \ \big]$  are used on the first pass  $(z=0)$  to calculate the AKF–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$ ?


{Welche Speicherelemente  ${\rm H}\big[\hspace{0.03cm} i \hspace{0.03cm} \big]$  und  ${\rm H}\big[\hspace{0.03cm} j \hspace{0. 03cm} \big]$  are used in the loop pass  $z=83$  to calculate the AKF value  $\varphi(k=6)$ ?
What random values are in these memory cells?

$i \ = \ $

$j \ = \ $


Solution

For numerical AKF 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 is highlighted in green  ${\rm H}\big[\hspace{0.03cm} i \hspace{0.03cm}\big]$.  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 the 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}$ .