diff --git a/res/autocorrelation_u.jpg b/res/autocorrelation_u.jpg new file mode 100644 index 0000000..6b376b1 Binary files /dev/null and b/res/autocorrelation_u.jpg differ diff --git a/res/autocorrelation_y.jpg b/res/autocorrelation_y.jpg new file mode 100644 index 0000000..ded9fba Binary files /dev/null and b/res/autocorrelation_y.jpg differ diff --git a/res/autocovariance_u.jpg b/res/autocovariance_u.jpg new file mode 100644 index 0000000..37ac525 Binary files /dev/null and b/res/autocovariance_u.jpg differ diff --git a/res/autocovariance_y.jpg b/res/autocovariance_y.jpg new file mode 100644 index 0000000..2287411 Binary files /dev/null and b/res/autocovariance_y.jpg differ diff --git a/res/cdf_u.jpg b/res/cdf_u.jpg new file mode 100644 index 0000000..1d4cdce Binary files /dev/null and b/res/cdf_u.jpg differ diff --git a/res/cdf_y.jpg b/res/cdf_y.jpg new file mode 100644 index 0000000..e60d0f0 Binary files /dev/null and b/res/cdf_y.jpg differ diff --git a/res/hist_u.jpg b/res/hist_u.jpg new file mode 100644 index 0000000..d4e759e Binary files /dev/null and b/res/hist_u.jpg differ diff --git a/res/hist_y.jpg b/res/hist_y.jpg new file mode 100644 index 0000000..36a5c29 Binary files /dev/null and b/res/hist_y.jpg differ diff --git a/res/model.png b/res/model.png new file mode 100644 index 0000000..bda179a Binary files /dev/null and b/res/model.png differ diff --git a/res/mutual_corellation_uy.jpg b/res/mutual_corellation_uy.jpg deleted file mode 100644 index 0a61141..0000000 Binary files a/res/mutual_corellation_uy.jpg and /dev/null differ diff --git a/res/mutual_correlation_uy.jpg b/res/mutual_correlation_uy.jpg new file mode 100644 index 0000000..8993112 Binary files /dev/null and b/res/mutual_correlation_uy.jpg differ diff --git a/res/mutual_correlation_yu.jpg b/res/mutual_correlation_yu.jpg new file mode 100644 index 0000000..3559ffe Binary files /dev/null and b/res/mutual_correlation_yu.jpg differ diff --git a/res/mutual_covariance_uy.jpg b/res/mutual_covariance_uy.jpg deleted file mode 100644 index 81be012..0000000 Binary files a/res/mutual_covariance_uy.jpg and /dev/null differ diff --git a/res/samplecount.png b/res/samplecount.png new file mode 100644 index 0000000..e844874 Binary files /dev/null and b/res/samplecount.png differ diff --git a/res/signal_u.jpg b/res/signal_u.jpg new file mode 100644 index 0000000..645fd28 Binary files /dev/null and b/res/signal_u.jpg differ diff --git a/res/signal_y.jpg b/res/signal_y.jpg new file mode 100644 index 0000000..6977021 Binary files /dev/null and b/res/signal_y.jpg differ diff --git a/res/step_response.png b/res/step_response.png new file mode 100644 index 0000000..dfd02e4 Binary files /dev/null and b/res/step_response.png differ diff --git a/res/u_autocorellation.jpg b/res/u_autocorellation.jpg deleted file mode 100644 index 55580a2..0000000 Binary files a/res/u_autocorellation.jpg and /dev/null differ diff --git a/res/u_autocovariance.jpg b/res/u_autocovariance.jpg deleted file mode 100644 index 50c97ec..0000000 Binary files a/res/u_autocovariance.jpg and /dev/null differ diff --git a/res/u_dist.jpg b/res/u_dist.jpg deleted file mode 100644 index 3eac794..0000000 Binary files a/res/u_dist.jpg and /dev/null differ diff --git a/res/u_hist.jpg b/res/u_hist.jpg deleted file mode 100644 index e4b876b..0000000 Binary files a/res/u_hist.jpg and /dev/null differ diff --git a/res/u_input_plot.jpg b/res/u_input_plot.jpg deleted file mode 100644 index 721fe17..0000000 Binary files a/res/u_input_plot.jpg and /dev/null differ diff --git a/res/y_autocorellation.jpg b/res/y_autocorellation.jpg deleted file mode 100644 index 2d664df..0000000 Binary files a/res/y_autocorellation.jpg and /dev/null differ diff --git a/res/y_autocovariance.jpg b/res/y_autocovariance.jpg deleted file mode 100644 index 00292cd..0000000 Binary files a/res/y_autocovariance.jpg and /dev/null differ diff --git a/res/y_dist.jpg b/res/y_dist.jpg deleted file mode 100644 index 8ce34e8..0000000 Binary files a/res/y_dist.jpg and /dev/null differ diff --git a/res/y_hist.jpg b/res/y_hist.jpg deleted file mode 100644 index 41c5d10..0000000 Binary files a/res/y_hist.jpg and /dev/null differ diff --git a/res/y_input_plot.jpg b/res/y_input_plot.jpg deleted file mode 100644 index b269d65..0000000 Binary files a/res/y_input_plot.jpg and /dev/null differ diff --git a/solution.tex b/solution.tex index c64e599..9cfd99e 100644 --- a/solution.tex +++ b/solution.tex @@ -1,5 +1,5 @@ Jazyk zvolený pre vypracovanie práce bol Python, pseudonáhodné dáta -reprezentujúce signál boli vygenerované programom Matlab. +reprezentujúce signál boli vygenerované programom Matlab - Simulink\footnotemark{}. \\ \\ Kód je dostupný na nasledujúcom odkaze:\\ @@ -8,29 +8,113 @@ Kód je dostupný na nasledujúcom odkaze:\\ Kód tohto protokolu je dostupný na nasledujúcom odkaze:\\ \url{https://git.dotya.ml/wanderer/ak9im-proto1}. -\subsection{Vygenerovanie signálu} +\footnotetext{Matlab bol používaný na systéme Arch Linux (btw\texttrademark) +\href{https://bbs.archlinux.org/viewtopic.php?id=277970}{po} +\href{https://bbs.archlinux.org/viewtopic.php?pid=2051175#p2051175}{prekonaní} +\href{https://uk.mathworks.com/matlabcentral/answers/1798895-invalid-cross-device-link-18-when-saving-a-file-on-arch-linux}{viacerých} +\href{https://www.mathworks.com/matlabcentral/answers/93703-why-do-i-receive-host-id-error-after-selecting-a-license-file-during-installation}{problémov} +s~inštaláciou, aktiváciou, QT + Wayland, \texttt{libfreetype.so} a inými.} + +\subsection{Spojitý model} +\begin{equation*} + G(s) = \frac{1}{2s^2 + 5s + 1} +\end{equation*} + +\subsection{Simulinkové schéma pre simuláciu pseudonáhodného signálu} \begin{figure}[ht] - \includegraphics[width=.75\textwidth]{res/u_input_plot} - \caption{Náhodne vygenerovaný signál} - \label{signalorig} + \centering + \includegraphics[width=.80\textwidth]{res/model} + \caption{Simulinkové schéma pre simuláciu pseudonáhodného signálu} + \label{fig:model} +\end{figure} + +\newpage +\subsection{Perióda vzorkovania} +\begin{figure}[ht] + \centering + \includegraphics[width=.80\textwidth]{res/step_response} + \caption{Prechodová charakteristika modelu podľa \texttt{step(1, [2 5 1])}} + \label{fig:stepresponse} +\end{figure} + +Prechodová charakteristika zobrazená na obrázku~\ref{fig:stepresponse} bola +získaná príkazom \texttt{step(1 [2 5 1])} v Matlabe. V amplitúde nadobúda +stabilne hodnotu $1$ po cca.~30 sekundách, perióda vzorkovania na výstupoch +\textit{u} a \textit{y} bola teda podľa zadania zvolená na 3s (aktívna časť = +10 vzoriek $\rightarrow 30s / 10 = 3s$). Minimálny počet vzoriek bol predpísaný +na 250, dĺžka vzorkovania bola preto nastavená na 750s. + + +\newpage +\subsection{Vybudenie sústavy pseudonáhodným signálom} +Sústava zobrazená na obrázku~\ref{fig:model} bola vybudená pseudonáhodným +signálom s rovnomerným (\textit{uniform}) rozložením hodnôt v intervale +$<-1;1>$. Vzorkovaním signálu bolo získaných celkom 251 hodnôt. + +\begin{figure}[ht] + \centering + \includegraphics[width=.35\textwidth]{res/samplecount} + \caption{Počet vzoriek zachytených na výstupoch \textit{u} a \textit{y}} + \label{samplecount} +\end{figure} + + +\subsection{Uloženie zachytených vzoriek do CSV} +Kvôli ďalšiemu spracovávaniu dát v Pythone bolo nutné dostať vzorky z Matlabu +do CSV súboru. To sa dalo našťastie celkom jednoducho vykonať nasledujúcimi +príkazmi: + +\begin{figure}[h] + \centering + \begin{varwidth}{\linewidth} + \begin{verbatim} + >> % matlab command prompt + >> cd + >> m = [out.u, out.y] + >> matrixwrite(m, 'm.csv') + \end{verbatim} + \end{varwidth} + \caption{Uloženie dát do CSV} +\end{figure} + +Najskôr sme sa premiestnili do \texttt{}, následne sme si so +zachytených vzoriek (jednorozmerné polia rovnakej dĺžky) vytvorili +\textit{maticu}. Túto maticu sme nakoniec zapísali príkazom +\texttt{matrixwrite} do želaného súboru. + +Súbor bolo dodatočne potrebné manuálne upraviť - pridať mu CSV "hlavičku" s +názvami stĺpcov, aby ho bolo možné za pomoci knižnice +\href{https://pandas.pydata.org/}{\texttt{Pandas}} bez problémov spracovať. + + +\newpage +\subsection{Získané signály} +\begin{figure}[ht] + \centering + \includegraphics[width=.77\textwidth]{res/signal_u} + \caption{Náhodne vygenerovaný signál pred aplikáciou filtra - u} + \label{fig:signalorig} \end{figure} \begin{figure}[ht] - \includegraphics[width=.75\textwidth]{res/y_input_plot} - \caption{Náhodne vygenerovaný signál s filtrom} - \label{signalfiltered} + \centering + \includegraphics[width=.77\textwidth]{res/signal_y} + \caption{Náhodne vygenerovaný signál po aplikácii filtra - y} + \label{fig:signalfiltered} \end{figure} \newpage \subsection{Histogram} \begin{figure}[ht] - \includegraphics[width=.75\textwidth]{res/u_hist} + \centering + \includegraphics[width=.77\textwidth]{res/hist_u} \caption{Histogram u} \label{histu} \end{figure} \begin{figure}[ht] - \includegraphics[width=.75\textwidth]{res/y_hist} + \centering + \includegraphics[width=.77\textwidth]{res/hist_y} \caption{Histogram y} \label{histy} \end{figure} @@ -38,128 +122,150 @@ Kód tohto protokolu je dostupný na nasledujúcom odkaze:\\ \newpage \subsection{Distribučná funkcia} \begin{figure}[ht] - \includegraphics[width=.75\textwidth]{res/u_dist} + \centering + + \includegraphics[width=.77\textwidth]{res/cdf_u} + \caption{Distribučná funkcia u} \label{distfuncu} \end{figure} \begin{figure}[ht] - \includegraphics[width=.75\textwidth]{res/y_dist} + \centering + + \includegraphics[width=.77\textwidth]{res/cdf_y} + \caption{Distribučná funkcia y} \label{distfuncy} \end{figure} \newpage \subsection{Štatistické charakteristiky\ 1.\ a\ 2.\ rádu} -Boli vypočítané štatistické charakteristiky prvého a druhého rádu, ktorými sú: +Vypočítali sme štatistické charakteristiky prvého a druhého rádu, ktorými sú: \begin{itemize} - \item stredná hodnota - \item rozptyl - \item koeficient korelácie - \item kovariančná matica (viď~\ref{covmatrix}) - \item autokorelačná funkcia pre u, y - \item vzájomne korelačná funkcia - \item autokovariačná funkcia pre u, y - \item vzájomná kovariačná funkcia + \item stredná hodnota pre u, y (viď tabuľka~\ref{table:stats}) + \item rozptyl pre u, y (viď tabuľka~\ref{table:stats}) + \item koeficient korelácie (viď tabuľka~\ref{table:stats}) + \item kovariančná matica (viď tabuľka~\ref{table:covmatrix}) + \item autokorelačná funkcia pre u, y (obr.~\ref{fig:autocorrelation-u},~\ref{fig:autocorrelation-y}) + \item vzájomne korelačná funkcia (obr.~\ref{fig:mutualcorrelation-uy},~\ref{fig:mutualcorrelation-yu}) + \item autokovariančná funkcia pre u, y (obr.~\ref{fig:autocovar-u}, + \ref{fig:autocovar-y}) \end{itemize} -\begin{table}[!hbt] -\centering -\begin{tabular}{r|cc} - & \textbf{u} & \textbf{y} \\ -\hline -\textbf{u} & 2.889406e-02 & 1.584866e+09 \\ -\textbf{y} & 1.584866e+09 & 1.948590e+23 \\ -\end{tabular} - -\label{covmatrix} -\caption{Kovariačná matica} -\end{table} - \newpage \subsection{Korelácia} \subsubsection{Autokorelačná funkcia u} \begin{figure}[ht] - \includegraphics[width=.75\textwidth]{res/u_autocorellation} + \centering + \includegraphics[width=.77\textwidth]{res/autocorrelation_u} \caption{Autokorelačná funkcia u} - \label{autocorrelationu} + \label{fig:autocorrelation-u} \end{figure} \subsubsection{Autokorelačná funkcia y} \begin{figure}[ht] - \includegraphics[width=.75\textwidth]{res/y_autocorellation} + \centering + \includegraphics[width=.77\textwidth]{res/autocorrelation_y} \caption{Autokorelačná funkcia y} - \label{autocorrelationy} + \label{fig:autocorrelation-y} \end{figure} \newpage \subsubsection{Vzájomne korelačná funkcia} \begin{figure}[ht] - \includegraphics[width=.75\textwidth]{res/mutual_corellation_uy} - \caption{Vzájomne korelačná funkcia} - \label{mutualcorrelation} + \centering + \includegraphics[width=.77\textwidth]{res/mutual_correlation_uy} + \caption{Vzájomne korelačná funkcia uy} + \label{fig:mutualcorrelation-uy} +\end{figure} + +\begin{figure}[ht] + \centering + \includegraphics[width=.77\textwidth]{res/mutual_correlation_yu} + \caption{Vzájomne korelačná funkcia yu} + \label{fig:mutualcorrelation-yu} \end{figure} \newpage \subsection{Kovariancia} -\subsubsection{Autokovariačná funkcia u} +\subsubsection{Autokovariančná funkcia u} \begin{figure}[ht] - \includegraphics[width=.75\textwidth]{res/u_autocovariance} - \caption{Autokovariačná funkcia u} - \label{autocovarianceu} + \centering + \includegraphics[width=.77\textwidth]{res/autocovariance_u} + \caption{Autokovariančná funkcia u} + \label{fig:autocovar-u} \end{figure} -\subsubsection{Autokovariačná funkcia y} +\subsubsection{Autokovariančná funkcia y} \begin{figure}[ht] - \includegraphics[width=.75\textwidth]{res/y_autocovariance} - \caption{Autokovariačná funkcia y} - \label{autocovariancey} + \centering + \includegraphics[width=.77\textwidth]{res/autocovariance_y} + \caption{Autokovariančná funkcia y} + \label{fig:autocovar-y} \end{figure} + \newpage -\subsubsection{Vzájomne kovariačná funkcia} -\begin{figure}[ht] - \includegraphics[width=.75\textwidth]{res/mutual_covariance_uy} - \caption{Vzájomne kovariačná funkcia} - \label{mutcovariance} -\end{figure} - -\newpage -\subsection{Štatistické charakteristiky} +\subsection{Štatistické charakteristiky - súhrn} \begin{table}[!hbt] -\centering -\begin{tabular}{r|cc} - & \textbf{u} & \textbf{y} \\ -\hline -\textbf{stredná hodnota} & 0.13739797971503992 & 20217121352.41238 \\ -\textbf{rozptyl} & 0.028836383482803592 & 1.9447005240730458e+23 \\ -\textbf{koeficient korelácie} & \multicolumn{2}{c}{0.021121664240700538} \\ -\textbf{koeficient kovariancie} & \multicolumn{2}{c}{1.58170285e+09} \\ -\end{tabular} + \centering + \begin{tabular}{r|cc} + & \textbf{u} & \textbf{y} \\ + \hline + \textbf{u} & 0.30774141 & -0.00436625 \\ + \textbf{y} & -0.00436625 & 0.01241115 \\ + \end{tabular} -\label{stats} -\caption{Súhrn štatistickúch charakteristík} + \caption{Kovariančná matica} + \label{table:covmatrix} \end{table} +Zo zaznamenaných dát signálov sme spočítali odhady stredných hodnôt a +rozptylov. +V~tabuľke~\ref{table:stats} môžeme vidieť výrazné posuny signálu po prechode +filtrom oproti pôvodnému signálu ako v strednej hodnote tak v rozptyle. + + +\begin{table}[!hbt] + \centering + \begin{tabular}{r|cc} + & \textbf{u} & \textbf{y} \\ + \hline + \textbf{$\hat{\mu}_{u,y}$ (stredná hodnota)} & -0.0016865221052993265 & 0.0030596815877553443 \\ + \textbf{$\hat{\sigma}^{2}_{u,y}$ (rozptyl)} & 0.3077414110318535 & 0.012411153945455982 \\ + \textbf{$\hat{r}(U,Y)$ (koeficient korelácie)} & \multicolumn{2}{c}{-0.07064959453763188} \\ + \end{tabular} + + \caption{Súhrn štatistických charakteristík} + \label{table:stats} +\end{table} + +Hodnota koeficientu korelácie je mierne záporná, čo znamená jemný náznak +tvrdenia, že signály spolu nesúvisia, resp. vzhľadom na to ako blízko je +daná záporná hodnota 0 ide skôr o preukázanie neexistencie súvisu. + +Toto by som ja osobne nebol schopný konštatovať len z pohľadu na grafy signálov +pred a po aplikácii filtra, viď obrázky~\ref{fig:signalorig} +a~\ref{fig:signalfiltered}. Je, samozrejme, možné pozorovať jemné +\textit{sploštenie} a \textit{zjemnenie} signálu, stále však vidieť podobnú +\textit{chaotickosť.} + + \newpage \section{Záver} V tejto úlohe sme si oprášili vedomosti týkajúce sa štatistických charakteristík prvého a druhého rádu, museli sme zistiť, ako vygenerovať pseudonáhodný signál v programe Matlab-Simulink, upraviť vygenerované dáta do -formátu, v ktorom sa dajú jednoducho spracovať \texttt{python} knižnicou -\texttt{Pandas} a nakoniec napísať malý program, ktorý tieto dáta konečne -spracuje a vygeneruje z nich grafy. +formátu, v ktorom sa dajú jednoducho spracovať napr. za pomoci +\textit{\texttt{python} knižnice pre dátovú analýzu} +\href{https://pandas.pydata.org/}{\texttt{Pandas}} a nakoniec napísať malý +program, ktorý tieto dáta konečne spracuje a vygeneruje z nich grafy. -Už na prvý grafy pohľad vyzerajú veľmi prekvapivo a následná analýza\\ -štatistických charakteristík len potvrdila môj dojem z vygenerovaných dát -- -zatiaľ čo pôvodné dáta nadobúdali hodnoty takmer s normálnym rozložení, po -prejdení filtrom došlo v signále k veľkému skresleniu a tak je možné -neprekvapivo konštatovať, že z korelačných hodnôt nie je vidieť priveľký súvis -medzi vstupným a výstupným signálom (koeficient korelácie blízky 0 signifikuje -neexistujúci súvis). - -Za dôvod vyššie konštatovaného je mimo programátorskej chyby možné považovať už -snáď len vstupné dáta, resp. konfiguráciu sústavy v programe Matlab-Simulink, -s~ktorým nie som príliš oboznámený. +Grafy síce vyzerajú na prvý pohľad relatívne príbuzne, následná analýza +štatistických charakteristík však nepotvrdila pozitívnu koreláciu medzi +signálmi na vstupe a výstupe po prejdení filtrom, co môžeme zrejme pripísať +istej miere skreslenia. Koeficient korelácie blízky 0 signifikuje neexistujúci +súvis medzi skúmanými veličinami.