Difference between revisions of "Aufgaben:Exercise 4.11Z: C Program "acf2""

From LNTwww
 
(28 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_ID395__Sto_Z_4_11.png|right|]]
+
[[File:EN_Sto_Z_4_11_neu.png|right|frame|C program  $2$  for ACF–calculation]]
:Sie sehen rechts das C-Programm &bdquo;akf2&rdquo; zur Berechnung der diskreten AKF-Werte <i>&phi;<sub>x</sub></i>(<i>k</i>) mit Index <i>k</i> = 0, ... , <i>l</i>. Im Gegensatz zum  Programm &bdquo;akf1&rdquo; aus Aufgabe A4.11 wird hier der im Theorieteil 4.4 beschriebene Algorithmus direkt angewendet. Dabei ist zu beachten:
+
You can see on the right the C program&nbsp; "acf2"&nbsp; for calculating the discrete ACF values&nbsp; $\varphi_x(k)$&nbsp; with index&nbsp; $k = 0$, ... , $l$.  
  
:Der an das Programm &uuml;bergebene Long-Wert sei hier <i>l</i>&nbsp;=&nbsp;10. Die berechneten 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 Hauptprogramm zur&uuml;ckgegeben. In den Zeilen 7 und 8 wird dieses Feld mit Nullen vorbelegt.
+
In contrast to the program&nbsp; "acf1"&nbsp; from&nbsp; [[Aufgaben:Exercise_4.11:_C_Program_"acf1"|Exercise 4.11]],&nbsp; here the algorithm described in the theory part is applied directly.&nbsp; It should be noted:
  
:Die Zufallsgr&ouml;&szlig;e <i>x</i>( ) ist als Float-Funktion in Zeile 4 definiert, ebenso ein Hilfsfeld <i>H</i>[10000], in das die <i>N</i> = 10000 Abtastwerte <i>x<sub>&nu;</sub></i> eingetragen werden (Zeile 9 und 10).
+
*Let the long value passed to the program be&nbsp; $l=10$.
 +
*The calculated ACF values&nbsp; $\varphi_x(0)$, ... , $\varphi_x(10)$&nbsp; are returned to the main program with the float field&nbsp; $\rm ACF[ \ ]$.&nbsp; In lines 7 and 8,&nbsp; this field is prefilled with zeros.
 +
*The random variable&nbsp; $x( \ )$&nbsp; is defined as a float function in line 4,&nbsp; as is an auxiliary field&nbsp; ${\rm H}[10000 ]$,&nbsp; into which the&nbsp; $N = 10000$&nbsp; samples&nbsp; $x_\nu$&nbsp; are entered&nbsp; (lines 9 and 10).
 +
*The names of the control variables in line 6 are adapted to the given algorithm.
 +
*The actual ACF calculation is done from line 11.&nbsp; This program part is marked red in the program code.
  
:Die Bezeichnungen der Laufvariablen in Zeile 6 sind an den angegebenen Algorithmus angepasst.
 
  
:Die eigentliche AKF-Berechnung erfolgt ab Zeile 11. Dieser Programmteil ist im Programmcode rot gekennzeichnet.
 
  
:<b>Hinweis:</b> Die Aufgabe beschreibt den im Kapitel 4.4 angegebenen Berechnungsalgorithmus.
+
Hints:  
 +
*This exercise belongs to the chapter&nbsp; [[Theory_of_Stochastic_Signals/Auto-Correlation_Function|Auto-Correlation Function]].
 +
*In particular, reference is made to the pages&nbsp;
 +
**[[Theory_of_Stochastic_Signals/Auto-Correlation_Function#Numerical_ACF_determination|Numerical ACF determination]],
 +
**[[Theory_of_Stochastic_Signals/Auto-Correlation_Function#Accuracy_of_the_numerical_ACF_calculation|Accuracy of the numerical ACF calculation]].
 +
  
  
===Fragebogen===
+
===Questions===
  
 
<quiz display=simple>
 
<quiz display=simple>
{Auf wie vielen Summanden (<i>S</i>) basiert die AKF-Berechnung f&uuml;r den Index <i>k</i> = 0 bzw. für <i>k</i> = 10?
+
{On how many summands&nbsp; ($S$)&nbsp; is the ACF calculation based for index&nbsp; $k=0$&nbsp; &nbsp;resp.&nbsp; for&nbsp; $k=10$&nbsp;?
 
|type="{}"}
 
|type="{}"}
$S_\text{$k=0$}$ = { 10000 3% }
+
$S_{k=0} \ = \ $ { 10000 }
$S_\text{$k=10$}$ = { 9990 3% }
+
$S_{k=10} \ = \ $ { 9990 }
  
  
{Welche der nachfolgenden Aussagen sind richtig?
+
{Which of the following statements are correct?
 
|type="[]"}
 
|type="[]"}
+ Die Rechenzeit steigt linear mit <i>l</i> + 1, also mit der Anzahl der zu berechnenden AKF-Werte.
+
+ The calculation time increases linearly with&nbsp; $l + 1$,&nbsp; i.e. with the number of ACF values to be calculated.
- Die Rechenzeit nimmt mit der Anzahl <i>N</i> der berücksichtigten Abtastwerte quadratisch  zu.
+
- The calculation time increases quadratically with the number&nbsp; $N$&nbsp; of samples considered.
+ Die Berechnung wird mit steigendem <i>N</i> genauer.
+
+ The calculation becomes more accurate as&nbsp; $N$&nbsp; increases.
+ Wird eine Floatvariable mit 4 Byte dargestellt, so benötigt &bdquo;akf2&rdquo; mindestens 4 &middot; <i>N</i> Byte Speicherplatz.
+
+ If a float variable is represented with&nbsp; $\rm 4 \ bytes$,&nbsp; "acf2"&nbsp; needs at least&nbsp; $4 \cdot N$&nbsp; bytes of memory.
  
  
{Welche der nachfolgenden Aussagen sind zutreffend?
+
{Which of the following statements are true?
 
|type="[]"}
 
|type="[]"}
+ Je st&auml;rker die inneren statistischen Bindungen des Prozesses sind, desto ungenauer ist bei gegebenem <i>N</i> das AKF-Ergebnis.
+
+ The stronger the internal statistical bindings of the process are,&nbsp; the more&nbsp; <u>inexact</u>&nbsp; is the ACF result for a given&nbsp; $N$.
- Je st&auml;rker die inneren statistischen Bindungen des Prozesses sind, desto genauer ist bei gegebenem <i>N</i> das AKF-Ergebnis.
+
- The stronger the internal statistical bindings of the process are,&nbsp; the more&nbsp; <u>accurate</u>&nbsp; is the ACF result for a given&nbsp; $N$.
+ Besitzt der Prozess statistische Bindungen, so sind die Fehler der numerischen AKF-Berechnung ebenfalls korreliert.<br> <i>Beispiel:</i> Ist der Wert <i>&phi;<sub>x</sub></i>(<i>k</i> = 5) zu gro&szlig;, so werden mit gro&szlig;er Wahrscheinlichkeit auch <i>&phi;<sub>x</sub></i>(<i>k</i> = 4) und <i>&phi;<sub>x</sub></i>(<i>k</i> = 6) zu gro&szlig; sein.
+
+ If the process has statistical bindings,&nbsp; the errors of the numerical ACF calculation are also correlated. <br>&nbsp; &nbsp; <u>Example:</u> &nbsp; &nbsp; If the value&nbsp; $\varphi_x(k=5)$&nbsp; is too large,&nbsp; it is very likely that&nbsp; $\varphi_x(k=4)$&nbsp; and&nbsp; $\varphi_x(k=6)$&nbsp; will also be too large.
  
  
Line 44: Line 51:
 
</quiz>
 
</quiz>
  
===Musterlösung===
+
===Solution===
 
{{ML-Kopf}}
 
{{ML-Kopf}}
:<b>1.</b>&nbsp;&nbsp;Zur Berechnung des AKF-Wertes <i>&phi;<sub>x</sub></i>(0) wird &uuml;ber <i>N</i> = <u>10000</u> Summanden gemittelt, f&uuml;r <i>&phi;<sub>x</sub></i>(10) nur &uuml;ber <i>N</i> &ndash; <i>l</i> = <u>9990</u>.
+
'''(1)'''&nbsp; To calculate the ACF value&nbsp; $\varphi_x(0)$&nbsp; you have to average over&nbsp; $\underline{N =10000}$&nbsp; summands, for&nbsp; $\varphi_x(10)$&nbsp; only over&nbsp; $\underline{N = 9990}$.
  
:<b>2.</b>&nbsp;&nbsp;Die Rechenzeit steigt mit <i>N</i> und <i>l</i> + 1 n&auml;herungsweise linear an, wie aus der rot hervorgehobenen AKF-Berechnung hervorgeht. Die Rechenzeit für die weiteren Programmteile kann demgegen&uuml;ber vernachl&auml;ssigt werden. Nat&uuml;rlich wird die Berechnung mit steigendem <i>N</i> auch genauer. Dies geht hier &ndash; im Gegensatz zum Programm &bdquo;akf1&rdquo; von Aufgabe A4.11 &ndash; allerdings auf Kosten des erforderlichen Speicherbedarfs. Da jede Float-Variable genau vier Byte beansprucht, ben&ouml;tigt alleine das Hilfsfeld <i>H</i>[10000] einen Speicher von 40 kByte. Richtig sind somit <u>die Lösungsvorschläge 1, 3 und 4</u>.
 
  
:<b>3.</b>&nbsp;&nbsp;Je st&auml;rker die statistischen Bindungen innerhalb des Zufallsprozesses sind, desto ungenauer ist bei gegebenem <i>N</i> die AKF-Berechnung. Diesen Sachverhalt kann man sich beispielsweise anhand der Leistungsberechnung (AKF-Wert an der Stelle <i>k</i> = 0) verdeutlichen: Sind alle  <i>N</i> Abtastwerte statistisch  unabh&auml;ngig, so liefern alle Beitr&auml;ge die maximale Information &uuml;ber den AKF&ndash;Wert  <i>&phi;<sub>x</sub></i>(<i>k</i> = 0).
 
  
:Bestehen jedoch statistische Bindungen zwischen <i>x<sub>&nu;</sub></i> und <i>x</i><sub><i>&nu;</i>+1</sub>, nicht jedoch zwischen <i>x<sub>&nu;</sub></i> und <i>x</i><sub><i>&nu;</i>+2</sub>, so liefern nur die H&auml;lfte aller Abtastwerte die volle Information &uuml;ber <i>&phi;<sub>x</sub></i>(<i>k</i> = 0) und alle anderen nur eingeschr&auml;nkte Informationen. Dieser auf Korrelationen beruhende Informationsverlust kann in diesem Beispiel nur durch eine Verdopplung von <i>N</i> ausgeglichen werden.
+
'''(2)'''&nbsp; Correct are&nbsp; <u>the proposed solutions 1, 3 and 4</u>:
 +
*The computation time increases approximately linearly with&nbsp; $N$&nbsp; and&nbsp; $l + 1$&nbsp; as can be seen from the ACF calculation highlighted in red.
 +
* In contrast,&nbsp; the computation time for the other parts of the program can be neglected.
 +
*Naturally,&nbsp; the calculation also becomes more accurate with increasing&nbsp; $N$.
 +
*This goes here &ndash; in contrast to the program&nbsp; "acf1"&nbsp; of Exercise 4.11 &ndash; however at the expense of the necessary memory requirement.  
 +
*Since each float variable takes up exactly four bytes, the auxiliary field&nbsp; ${\rm H}[10000 ]$&nbsp; alone requires a memory of 40 kByte.  
  
:Die letzte Aussage trifft ebenfalls zu, wie im Kapitel 4.4 auf der Seite Genauigkeit der numerischen AKF-Berechnung im Theorieteil ausführlich erl&auml;utert wird. Richtig sind somit die <u>Lösungsvorschläge 1 und 3</u>.
+
 
 +
 
 +
'''(3)'''&nbsp; Correct are the&nbsp; <u>suggested solutions 1 and 3</u>:
 +
*The stronger the statistical bindings within the random process,&nbsp; the less accurate is the ACF calculation for a given&nbsp; $N$.
 +
*This fact can be illustrated for example by the power calculation&nbsp; $($ACF value at&nbsp; $k=0)$&nbsp;:
 +
**If all&nbsp; $N$&nbsp; samples are statistically independent,&nbsp; then all contributions provide the maximum information about the ACF value&nbsp; $\varphi_x(k=0)$.
 +
**However,&nbsp; if there are statistical bindings between&nbsp; $x_\nu$&nbsp; and&nbsp; $x_{\nu+1}$,&nbsp; but not between&nbsp; $x_\nu$&nbsp; and&nbsp; $x_{\nu+2}$,&nbsp; only half of all samples provide the full information&nbsp; about&nbsp; $\varphi_x(k=0)$&nbsp; and the others provide only limited information.
 +
*This loss of information based on correlations can only be compensated in this example by doubling&nbsp; $N$&nbsp;.
 +
*The last statement is also true,&nbsp; as explained in detail on the page&nbsp; "Accuracy of the numerical ACF calculation"&nbsp; in the theory section.
 
{{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:27, 28 April 2022

C program  $2$  for ACF–calculation

You can see on the right the C program  "acf2"  for calculating the discrete ACF values  $\varphi_x(k)$  with index  $k = 0$, ... , $l$.

In contrast to the program  "acf1"  from  Exercise 4.11,  here the algorithm described in the theory part is applied directly.  It should be noted:

  • Let the long value passed to the program be  $l=10$.
  • The calculated ACF values  $\varphi_x(0)$, ... , $\varphi_x(10)$  are returned to the main program with the float field  $\rm ACF[ \ ]$.  In lines 7 and 8,  this field is prefilled with zeros.
  • The random variable  $x( \ )$  is defined as a float function in line 4,  as is an auxiliary field  ${\rm H}[10000 ]$,  into which the  $N = 10000$  samples  $x_\nu$  are entered  (lines 9 and 10).
  • The names of the control variables in line 6 are adapted to the given algorithm.
  • The actual ACF calculation is done from line 11.  This program part is marked red in the program code.


Hints:


Questions

1

On how many summands  ($S$)  is the ACF calculation based for index  $k=0$   resp.  for  $k=10$ ?

$S_{k=0} \ = \ $

$S_{k=10} \ = \ $

2

Which of the following statements are correct?

The calculation time increases linearly with  $l + 1$,  i.e. with the number of ACF values to be calculated.
The calculation time increases quadratically with the number  $N$  of samples considered.
The calculation becomes more accurate as  $N$  increases.
If a float variable is represented with  $\rm 4 \ bytes$,  "acf2"  needs at least  $4 \cdot N$  bytes of memory.

3

Which of the following statements are true?

The stronger the internal statistical bindings of the process are,  the more  inexact  is the ACF result for a given  $N$.
The stronger the internal statistical bindings of the process are,  the more  accurate  is the ACF result for a given  $N$.
If the process has statistical bindings,  the errors of the numerical ACF calculation are also correlated.
    Example:     If the value  $\varphi_x(k=5)$  is too large,  it is very likely that  $\varphi_x(k=4)$  and  $\varphi_x(k=6)$  will also be too large.


Solution

(1)  To calculate the ACF value  $\varphi_x(0)$  you have to average over  $\underline{N =10000}$  summands, for  $\varphi_x(10)$  only over  $\underline{N = 9990}$.


(2)  Correct are  the proposed solutions 1, 3 and 4:

  • The computation time increases approximately linearly with  $N$  and  $l + 1$  as can be seen from the ACF calculation highlighted in red.
  • In contrast,  the computation time for the other parts of the program can be neglected.
  • Naturally,  the calculation also becomes more accurate with increasing  $N$.
  • This goes here – in contrast to the program  "acf1"  of Exercise 4.11 – however at the expense of the necessary memory requirement.
  • Since each float variable takes up exactly four bytes, the auxiliary field  ${\rm H}[10000 ]$  alone requires a memory of 40 kByte.


(3)  Correct are the  suggested solutions 1 and 3:

  • The stronger the statistical bindings within the random process,  the less accurate is the ACF calculation for a given  $N$.
  • This fact can be illustrated for example by the power calculation  $($ACF value at  $k=0)$ :
    • If all  $N$  samples are statistically independent,  then all contributions provide the maximum information about the ACF value  $\varphi_x(k=0)$.
    • However,  if there are statistical bindings between  $x_\nu$  and  $x_{\nu+1}$,  but not between  $x_\nu$  and  $x_{\nu+2}$,  only half of all samples provide the full information  about  $\varphi_x(k=0)$  and the others provide only limited information.
  • This loss of information based on correlations can only be compensated in this example by doubling  $N$ .
  • The last statement is also true,  as explained in detail on the page  "Accuracy of the numerical ACF calculation"  in the theory section.