\subsection{Dataset}
We have conducted experiments on the following datasets(Mainly For Phase 1):
\begin{center}
\begin{tabular}{| l | c |}
  \hline
  Dataset Name & Advogato  \\ \hline
  Largest conn compo & 5054  \\ \hline
  Size & 6551 vertices  \\ \hline
  Volume & 51332 edges \\ \hline
\end{tabular}
\end{center}

In out final experiment suit, a more large and diverse datasets from different domains will be explored. The tentative source of experiment dataset are listed below:
\begin{description}
	\item{{\bf SNAP:}}{It has abundant data about social network, we plan to conduct triangle counting, pagerank, radius computing experiment which will reveal the underlying feature of large graphs and spot strange graphs.}
	\item{{\bf Konect:}}{Konect has more diverse datasets compared to SNAP, like citation network. It's a good target to analyze features of non-social networks, we will examine whether such networks follow power law by generating degree distribution, etc.}
\end{description}

In phase 1, we explored Task 1-3, and do several visualization for experiment results. Figure \ref{fig:results}(a) shows the in degree distribution, we took log of rank to emphasize the effect. Figure \ref{fig:results}(b) shows the out degree distribution, also took logarithm. Figure \ref{fig:pagerank} plots the distribution of different rank value.We also calculated statistics about the weakly connected components in table \ref{table:wcc}.We compute radius for every node in Advogato dataset, the result is in table \ref{table:radius}:

\begin{figure}[htbf]
\begin{center}
\begin{tabular}{cc}
     \includegraphics[width=0.4\textwidth]{FIG/indegree.png} &
     \includegraphics[width=0.4\textwidth]{FIG/outdegree.png} \\
    (a) & (b)
\end{tabular}
\caption{In degree distribution (a) and out degree distribution (b)}
\label{fig:results}
\end{center}
\end{figure}

\begin{figure}[htbf]
\begin{center}
     \includegraphics[width=0.6\textwidth]{FIG/pagerank.png}
\caption{Pagerank distribution}
\label{fig:pagerank}
\end{center}
\end{figure}

\begin{table}
\begin{center}
\begin{tabular}{| l | c |}
  \hline
  Size of WCC & Count  \\ \hline
  1 & 1384  \\ \hline
  2 & 55  \\ \hline
  3 & 1 \\ \hline
  5054 & 1 \\ \hline
\end{tabular}
\caption{Statistics about Weakly connected components}
\label{table:wcc}
\end{center}
\end{table}

\begin{table}
\begin{center}
\begin{tabular}{| l | c |}
  \hline
  radius & number of vertices  \\ \hline
  0 & 1896  \\ \hline
  1 & 84  \\ \hline
  2 & 11 \\ \hline
  3 & 7 \\ \hline
  4 & 634 \\ \hline
  5 & 2194 \\ \hline
  6 & 826 \\ \hline
  7 & 117 \\ \hline
  8 & 13 \\ \hline
  9 & 2 \\ \hline
\end{tabular}
\caption{statistics about radius}
\label{table:radius}
\end{center}
\end{table}

\begin{figure}[htbf]
\begin{center}
     \includegraphics[width=0.6\textwidth]{FIG/radius.png}
\caption{Radius Plot}
\label{fig:radius}
\end{center}
\end{figure}

\subsection{Triangle Counting(Design)}
The main reason of triangle counting is to compare the capability of each solution(RDBMS, general purpose programming language). We will apply RDBMS version and c++/java version, record their running time and resource usage, then do performance analysis.

\subsection{Belief Propagation(Design)}
In order to investigate the gain of using RDBMS, We plan to compare the efficiency of RDBMS's implementation of BP with BP in general purpose languages like c++/java. We ponder that the difference will be only observable in large dataset, we will conduct experiments to try to estimate that.

\subsection{Eigenvalue/SVD(Design)}
SVD is a powerful tool at dimension reduction, or in another words, clustering. So We plan to apply SVD to social networks to find communities, and some work has been done by researchers in data mining and matrix analysis.


%!TEX root = ../main.tex

\documentclass[../main.tex]{subfiles}
\begin{document}

\section{Simulation Study}\label{sec:simulation_study}
The previous section shows how the model presented in this thesis can be useful in the identification of changes in relative skill prices in panel data. Following this identification strategy, changes in the prices of skills can be determined on the basis of the realized wages and task choices. In this section, I provide an exemplary application of this identification in the format of a simulation study.\footnote{Program codes of this simulation study are available on GitHub: github.com/DaLueke/estimating\_skill\_prices.}
\\
As part of this simulation study I, first, generate a representation of a panel data set. The data generating process endogenously provides optimal task choices and according realized wages for each simulation period on the basis of potential task specific wages. For each task the potential wages are composed of exogenous skill prices as well as  skill endowments that are exogenous in the initial period and evolve endogenously based on optimal task choices in subsequent periods.
\\
In a second step, I rely on this simulated data for an estimation of changes in relative skill prices following the identification strategy presented in section \ref{sec:tractable-model-of-cont-task-choice} of this thesis. This involves an estimation of skill accumulation and changes in amenities in a base period. Subsequently, these estimated are used to isolate effects of changes in skill prices from skill accumulation and changes in amenities in the following period. After this preliminary step, adjusted wage changes are used to estimate changes in relative skill prices.

\subsection{Data Generating Process} \label{sec:DGP}
% Generate 3 points in time so that I observe two intertemporal changes
%% Split into base period and a subsequent estimation period
% Generate potential wages
%% Skill prices: Exogeneously given. Constant in base period, changing in estimation period
%% Skill Endowments: Exogenous starting values, skill accumulation afterwards
%% Learning by doing process: Workers become better at the task they are doing relatively much.
% Penalty term: generate exogenous preferences for a task split
% Obtain optimally chosen task choice parameters by maximizing wages minus penalty
% Determine wage that results from optimal choice of tasks
% Can I find some nice way of visualizing my simulated data?
In order to produce a representation of a panel data set, the data generating process provides data on three points in time so that two inter temporal changes can be calculated. The first thereof serves as a base period and the second as an estimation period. Following the discussion of the model in section \ref{sec:implications-with-j=2}, this simulation is based on two different tasks. With the objective of simulating a utility maximization process in mind, both wages and penalty term need to be simulated (see equation \ref{eq:utility}). Therefore, I first describe the data generating process for potential task specific wages. Second, I present the parameterization of the penalty term.
\\
The wage function depends on task specific potential wages, which are assumed to result as sum of respective skill prices and individual skill endowments (see section \ref{sec:identifying-changes-in-skill-prices}, particularly equation (\ref{eq:potential_wages})). Prices of each skill in each period are exogenous to the data generating process. In this simulation study specifically, relative skill prices are set to be constant during the base period and changing during the estimation period. In order to facilitate the evaluation of estimation results, the change of relative skill prices in the estimation period is deterministic.
\\
Initial values of skill endowments are exogenous to the data generating process and, thus, are drawn from a normal distribution. In subsequent periods, skills endowments experience an accumulation that is modeled as a learning by doing process. In particular, workers gain relative skill in that task, which they execute to a relatively large extent. The stronger a worker focuses on one single task, the larger is the gain in relative skill herein. This results in an endogenous skill accumulation that depends on task choices. The particular functional form of skill accumulation is presented in equation (\ref{eq:skill_accumulation}).
\begin{equation} \label{eq:skill_accumulation}
\tilde{s}_{i,t} = \tilde{s}_{i, t-1} + (\lambda_{i, t-1}^* - 0.5)
\end{equation}
In accordance to the normalization of potential wages introduced in section \ref{sec:implications-with-j=2}, potential wages of task one are normalized to zero so that potential wages of task two need to be understood as relative sizes. Specifically, a skill endowment for task two that is positive indicates that a worker has a comparative advantage in executing this task and vice versa for negative skill endowments. Analogously, a relative skill price that is larger than zero implies a higher compensation for executing task two than for task one.
\\
The penalty term is a function of individual time allocation preference, which is captured in parameter $b_i$. For this simulation study this parameter is generally assumed to be uniformly distributed within some borders $\{b_{low}, b_{high}\}$ with $b_{low}, b_{high} \in [0, 1] \; \text{and} \; b_{low} \leq b_{high}$. The resulting interval is assumed to be centered at the equal split of working time on both tasks, so that neither task is systematically preferred to the other. Additionally, it is assumed that workers dislike strong specialization (section \ref{sec:utility-max-problem}). To do justice to this assumption, the limits of the parameter for preferred allocations should, therefore, not be chosen in the extremes. In the data generated process that is used for the simulation study, the borders of individual time allocation preferences are set to $b_{low} = 0.3$ and $b_{high} = 0.7$.
\\
For this simulation study, I use a quadratic specification of the penalty function, i.e. the penalty exponent is set to $\phi = 2$. This specification meets  the assumed properties of the penalty function. At the same time, it results optimal task choices that are a linear function in relative potential wages, which makes the linear interpolation of inter temporal changes in task choices an exact solution. The penalty weight parameter is set to a value of $\theta = 15$ in this data generating process. This weight is chosen so that neither realized wages nor the penalty dominates the utility function. While the first case could result in a large number of corner solutions where every worker focuses on the task with higher potential wage, the second case would produce a dataset in which workers mostly stick with their preferred task choice so that potential wages, and more importantly changes thereof, impact task choice very little. Based on both, potential wages and the penalty term, the optimal task choice parameter $\lambda_{i,t}^*$ can be obtained in each period by maximizing the individual utility (i.e., realized wage lessened by the penalty term). Furthermore, resulting realized wages can be calculated using this optimal task choice.
\\
A representation of the simulated data can be seen in figure \ref{fig:simulated_data}. Particularly, the figure shows the combinations of optimal task choices $\lambda_{i,t=0}^*$ and realized wages $w_{i,t=0}$ for all $N=100$ simulated workers in the initial period from one of the Monte Carlo iterations. From the graphic it can be seen that task choices (horizontal axis) are distributed around the equal split, with no worker engaging in an complete specialization on either one of the tasks. The histogram of realized relative wages (vertical axis) shows an increased frequency at the center of the distribution around a relative wage of zero. Both, relatively high and low realized relative wages are less frequent.
\\
In the data generating process, the relative price of skills for task two is fixed at $0.1$ in the initial period $t=0$, which implies that the skill price of task two is $10 \%$ higher than the skill price of task one. This setting should result in relatively high realized wages for workers that spend the majority of their working time on task two. Indeed, it can be seen that workers who have higher $\lambda_{i,t}^*$ tend to earn relatively high wages. This impression is supported by the position of a regression line (black dotted line in figure \ref{fig:simulated_data}), which shows to have a slightly negative slope, indicating that larger values for task choices tend to correlate with higher realized wages.
\begin{figure}[!htbp]
	\centering
	\includegraphics[scale=0.7]{./FIG/simulated_data.png}
	\caption{Simulated data resulting from a data generating process that is specified as described in section \ref{sec:DGP}. This figure illustrates $N=100$ combinations of realized relative wages (i.e., sum of potential wages, weighted by task choices) and optimal task choices (i.e., the fraction of working time spent on task two) from the initial period $t=0$ in a scatter plot. Along each axis a histogram of the respective variable is plotted. The dashed line results from an OLS fit of realized relative wages (vertical axis) on optimal task choices (horizontal axis).}
	\label{fig:simulated_data}
\end{figure}
\\
Overall, the data generating process described in this section provides simulated data on task choices and realized wages for each period. From this, wage changes as well as adjustments in task choices can be calculated for the base period as well as a subsequent estimation period. Utilizing both, changes in task choices and realized wages, allows to draw inferences on the change in relative skill prices on which the data generating process is based. The next section shows the results of a Monte Carlo estimation of changes in skill prices relying on the identification strategy discussed in section \ref{sec:model_estimation} and using data that is generated by the process described in this section.

\FloatBarrier
\subsection{Monte Carlo Estimation of Skill Prices} \label{sec:MC_estimation}
% Following the identification strategy presented in section 2.4.:
%% use base period (without price changes) to estimate effects of changes in skill endowments as well as pentalty term
%%% Present regression table: Show that I need to drop some regressors (multicol.), show that I capture most of the variance, show that estiates are highly significant.
%% use these estimations to calculate a "residual wage change" in estimation period, i.e., adjust wage changes for above mentioned effect
%% Regress residual wage change on mean lambda
%%% Show regression rslt: high significance, point estimate, R^2 should be relatively high in this model, too
% Present results from MC-Simulation (distribution of point estimates)
% Find reasons for bias in estimation: Why is my estimate too high?
%% Do I not completely capture skill changes (same regressor)?
%% Does dropping regressors in first step result in inappropriate estimators and, thus, biased estimations?
% overall: Model allows to obtain a close estimate of true price changes
%% Potentil problems and (1) Why they are not that relevant in real data and (2) what can be done to mitigate
This section presents the results of a Monte Carlo estimation of changes in skill prices and serves as a proof of concept of the model presented in section \ref{sec:tractable-model-of-cont-task-choice} of this thesis, particularly of the estimation strategy discussed in section \ref{sec:model_estimation}. For this purpose it relies on data generated in the process described in previous section.
\\
The estimation of skill prices consists of three steps: First, it uses a base period to estimate the effects of skill accumulation and changes in the penalty term in the absence of changes in skill prices. This allows for second, adjusting observed wage changes of a subsequent period for these previously estimated effects. Finally, changes in skill prices are estimated based on these residual wage changes in a third step. Each of these steps is repeated $M=1000$ times in a Monte Carlo estimation, each time considering data on $N=100$ simulated individuals.
\\
In the particular model discussed in this work both, changes in skills and changes in the penalty term from $t-1$ to $t$, depend on task choices $\lambda_{i,t-1}^*$ and $\lambda_{i,t}^*$. This can be seen from equation (\ref{eq:wage_change}). Specifically, the effect of skill accumulation depends on the mean task choice of both periods, $\bar{\lambda}_{i,t}^*$. The change in penalty term, however, results as a polynomial of degree $\phi$ of these optimal task choices. A derivation of this result can be seen in appendix \ref{app:derive_changes_penalty_term}. In the setting of the data generating process that is used in this simulation study, it is assumed that $\phi = 2$. In this case, changes in the penalty term can be shown to be equivalent to the expression in equation (\ref{eq:changes_in_penalty}) below as shown in appendix \ref{app:derive_changes_penalty_term}. Therefore, both $\lambda_{i,t-1}^*$ and $\lambda_{i,t}^*$ as well as their squared values need to be included in a regression model to capture changes in skill endowments and penalty terms.
\begin{equation}\label{eq:changes_in_penalty}
	\rho_{i}(\lambda_{i,t}^*) - \rho_{i}(\lambda_{i,t-1}^*) = \lambda_{i,t-1}^{*2} + \lambda_{i,t}^{*2} + 2b_i(\lambda_{i,t-1}^* + \lambda_{i,t}^*)
\end{equation}
% Now find the model that is actually used in estimation
% Due to strong correlation of lmbs, I suspect i will have to drop some. So go check different specifications and see how they perform in
% (a) modelling base period and
% (b) adjusting in estimation period
In an estimation of skill accumulation and changes in the penalty term, however, not all of these regressors can be included due to their near perfect multicollinearity. Not only will each task choice be correlated with its square. In addition, optimal task choices of subsequent periods will be correlated in the theoretical framework presented in this thesis. This is for two reasons: First, optimal task choices (equation (\ref{eq:lmb_opt})) are a function of potential wages. Potential wages, in term, are modeled as the sum of log skills and log skill prices. By the assumption of skill accumulation as a learning by doing process, potential wages will correlate between periods and, thereby, optimal task choices will be correlated as well. Second, optimal task choices are a function of the allocation preferences $b_i$ which are modeled to be time invariant. Calculating the correlation coefficients between task choices in $t-1$ and $t$ as well as their squares for one of the Monte Carlo iterations reveals that, indeed, correlations are very close to one. A correlation heatmap can be found in figure \ref{fig:corr_heatmap} of appendix \ref{app:tables_and_figures}.
\\
In order to avoid this multicollinearity, only task choices of either period $t-1$ or $t$ can be included as regressors. As seen from the estimation results in tables \ref{tab:base_period_regression_rlst_t-1} and \ref{tab:base_period_regression_rlst_t} (appendix \ref{app:tables_and_figures}), both of these estimation specifications appear to fit the simulation data well with an adjusted $R^2$ of 0.999 in either case. Each iteration of the Monte Carlo estimation is based on $N=100$ simulated observations. While this number is small enough to keep the computational load low, the resulting estimates have small standard deviations and high significance ($p<0.001$ for both estimates).
\\
Given there is an adjustment in task choices between periods, by construction the mean task choice lies in between the task choices in $t-1$ and $t$. This implies that dropping task choices in $t-1$ or $t$ in the estimation of skill accumulation and changes in the penalty term in the base period increases, or respectively, decreases the estimates. Consequently, estimated skill accumulation and changes in the penalty term will be biased. Therefore, both specifications will be considered in the following. In each of the $M=1000$ iterations of this Monte Carlo estimation, changes in skills and penalty term in the base period are estimated, once including task choices from $t-1$ and once from $t$. After that, wage changes of the subsequent time period are adjusted for the product of the estimated coefficient from the base period and the estimation period's task choices. Again, both possible setups are considered in this adjustment. Resulting residual wage changes are the basis of the estimation of changes in skill prices.
\\
\begin{figure}[!htbp]
	\centering
	\includegraphics[scale=0.7]{../FIG/MC_estimation_rslt.png}
	\caption{Histogram of the result of $M=1000$ Monte Carlo estimations of changes in relative skill prices. The true price changed used in the data generating process is $0.1$. Wage changes of the estimation period are adjusted for skill accumulation and changes in the penalty term. In the left panel, this adjustment uses task choices in $t-1$, in the right panel it uses task choices in $t$.}
	\label{fig:MC_est_rslt}
\end{figure}
Figure \ref{fig:MC_est_rslt} presents histograms of the results of the Monte Carlo estimation. The left panel presents the results from a setting where wage changes are adjusted based on an estimation that includes task choices from $t-1$. The panel on the right hand side results from a setting where this adjustment is based on task choices in $t$. Estimation results reveal to be noticeably biased in both panels. In the left panel estimation results have a positive bias, i.e. changes in relative wages are overestimated by up to approximately $0.5$ percentage points. Put into perspective with the true change in relative skill prices of $10 \%$, this corresponds to an overestimation in the order of magnitude of $5 \%$. In the right panel the opposite can be seen: changes in relative prices are underestimated. The estimation error is slightly smaller in this case and amounts up to circa $0.25$ percentage points. This corresponds to a relative deviation of $2.5 \%$. The true change in relative price changes ($0.1,$ indicated with the red vertical line) lies in between the estimation results based on adjustments using task choices in $t-1$ and the results based on adjustments using task choices in $t$.
\\
As argued above, a biased estimation result is to be expected as task choices of only one point in time can be included in the estimation of skill accumulation and changes in the penalty term. This leads to a biased estimation of these effects and, thus, either an under- or over correction of wage changes in the estimation period for changes in skill endowments and penalty. An accurate estimation of changes in relative skill prices can only result in a setting where task choices of both points in time, $t-1$ and $t$, are included. This specification, however, suffers from near perfect multicollinearity.
\end{document}


\documentclass[letterpaper,12pt]{scrartcl}
\usepackage{epsfig,latexsym,amsmath,amssymb,epic,eepic,psfrag,subfigure,float,euscript,array}
\usepackage[latin1]{inputenc}
\usepackage[margin=24mm]{geometry}
\usepackage{enumitem}
\usepackage{tikz,pgf,pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{decorations, arrows}

\usepackage[amssymb]{SIunits}

\newenvironment{exercise}[1][Uppgift]{\begin{trivlist} \item[\hskip
    \labelsep {\stepcounter{exerctr}\bfseries #1
      \arabic{exerctr}}]}{\end{trivlist}\vspace{10mm}}

\newcounter{exerctr}
\newcounter{abcctr}[exerctr]

\newcommand{\abc}{\noindent\vspace{1mm}\\ {\bf
    \stepcounter{abcctr}(\alph{abcctr})\ }}
\newcommand{\bbm}{\begin{bmatrix}}
\newcommand{\ebm}{\end{bmatrix}}
\newcommand{\point}[1]{\hfill {\bf (#1p)}\\ \vspace{-5mm}}
\newcommand{\ctrb}{\EuScript{S}}
\newcommand{\Lap}{\mathcal{L}}
\newcommand{\obsv}{\EuScript{O}}
\newcommand{\realdel}{\text{Re}}
\newcommand{\imagdel}{\text{Im}}
\newcommand{\bC}{\mathbb{C}}
\newcommand{\bR}{\mathbb{R}}
\newcommand{\bmpv}{\begin{minipage}[t]}
\newcommand{\bmps}{\begin{minipage}[t]{45mm}}
\newcommand{\bmpm}{\begin{minipage}[t]{90mm}}
\newcommand{\bmpl}{\begin{minipage}[t]{\textwidth}}
\newcommand{\emp}{\end{minipage}}
\newcommand{\mexp}[1]{\ensuremath{\mathrm{e}^{#1}}}
\newcommand*{\laplaceinv}[1]{\ensuremath{\mathcal{L}^{-1} \left\{#1\right\}}}
\newcommand*{\ztrf}[1]{\ensuremath{\mathcal{Z} \left\{#1\right\}}}
\newcommand*{\shift}{\ensuremath{\operatorname{q}}}
\newcommand*{\diff}{\ensuremath{\operatorname{p}}}

\newcommand{\AxisRotator}[1][rotate=0]{%
    \tikz [x=0.2cm,y=0.60cm,line width=.1ex,-stealth,#1] \draw (0,0) arc (-150:150:1 and 1);%
}

\addtolength{\topmargin}{-8mm}
%\textheight 22.5cm
%\oddsidemargin 1.3cm
%\evensidemargin 1.3cm

\makeatletter
\newcommand*{\rom}[1]{\expandafter\@slowromancap\romannumeral #1@}
\makeatother

\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}

\title{Computerized Control partial exam 2 (15\%)}
\author{Kjartan Halvorsen}
\date{}

\begin{document}

\maketitle

\begin{description}
\item[Time] April 3 17:35-18.55
\item[Place] 5105
\item[Permitted aids] The single colored page with your own notes, table of Laplace transforms, calculator
\end{description}

All answers should be readable and well motivated (if nothing else is written). Solutions/motivations should be written on the provided spaces in this exam. Use the last page if more space is needed.

\begin{center}
{\Large Good luck!} \\
\end{center}

\noindent
\fbox{
\bmpl
{\bf Matricula and name:}\\
\vspace*{14mm}
\emp}

%\clearpage

%-----------------------------------------------------------------

\subsection*{Problem 1}
% PI controller, forward approximation

The euler forward approximation of a derivative is
\[ \frac{d}{dt} f(t) \approx \frac{f(t+h)-f(t)}{h}, \]
which can be written using the derivative operator $\diff = \frac{d}{dt}$ and the shift operator $\shift$ as
\[ \diff f \approx \frac{\shift - 1}{h} f. \]

\subsubsection*{(a)}
Use the forward approximation to find a discrete approximation $F_d(z)$ of the PI-controller
\[ F(s) = K(1 + \frac{1}{T_is}). \]

\noindent
\fbox{
\bmpl
{\bf Calculations and answer:}\\
\vspace*{64mm}
\emp}

\subsubsection*{(b)}
The block diagram below shows the discrete-time controller.
\begin{center}
  \begin{tikzpicture}[scale = 0.8, node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}]

    \node[coordinate] (input) {};
     \node[sumnode, right of=input, node distance=16mm] (sum) {\tiny $\sum$};
     \node[block, right of=sum, node distance=26mm] (controller) {$F_d(z)$};
     \node[coordinate, right of=controller, node distance=20mm] (output) {};
     \node[coordinate, below of=sum, node distance=12mm] (feedback) {};

     \draw[->] (input) -- node[above, pos=0.3] {$y_{ref}(k)$} (sum);
     \draw[->] (sum) -- node[above] {$e(k)$} (controller);
     \draw[->] (controller) -- node[above, near end] {$u(k)$} (output);
     \draw[->] (feedback) -- node[right, near start] {$y(k)$} node [left, near end] {$-$} (sum);
   \end{tikzpicture}
   \end{center}
Write the controller as a \emph{difference equation} using $F_d(z)$ determined in (a).

\noindent
\fbox{
\bmpl
{\bf Calculations and answer:}\\
\vspace*{64mm}
\emp}

\subsection*{Problem 2}

The magnetic levitation (maglev) system below is an example of an unstable system.
\begin{center}
\includegraphics[width=0.4\linewidth]{../../../MR2004/figures/magnetic-suspension}
\end{center}
Ignoring friction in the system, a linearized model is given by the state space system
\begin{equation}
\begin{aligned}
  \dot{x}(t) &= \bbm 0 & 1\\ \omega^2 & 0 \ebm x(t) + \bbm 0\\1 \ebm u(t)\\
  y(t) &= \bbm 1 & 0 \ebm x(t),
\end{aligned}
\label{eq:maglevcont}
\end{equation}
with poles in $s = \pm \omega$. The input signal $u(t)$ is a deviation in the current $i(t)=i_0-u(t)$ applied to the windings, the state variable $x_1(t)$ is a deviation in the position of the suspension mass $z(t) = z_0 + x_1(t)$, and the state variable $x_2(t)$ is the velocity of the mass. The tuple ($i_0$, $z_0$, $\dot{z}=0$) forms an operating point, for which the system is in (unstable) equilibrium.

Discretizing the system using zero-order-hold with $\omega=1$ and $\omega h = 0.2$  gives the discrete-time state space system
\begin{equation}
\begin{aligned}
  x(k+1) &= \underbrace{\bbm 1.02 & 0.20\\0.20 & 1.02 \ebm}_{\Phi} x(k) + \underbrace{\bbm 0.02\\0.20 \ebm}_{\Gamma} u(k)\\[2mm]
  y(t) &= \bbm 1 & 0 \ebm x(k).
\end{aligned}
\label{eq:maglev}
\end{equation}

\subsubsection*{(a)}

Determine the poles of the discrete-time open-loop system.

\noindent
\fbox{
\bmpl
{\bf Calculations and answer:}\\
\vspace*{64mm}
\emp}

\subsubsection*{(b)}

Assume that the state vector $x(k)$ must be estimated using an observer. Determine an observer gain vector $K$ such that the observer has poles in the origin.

\noindent
\fbox{
\bmpl
{\bf Calculations and answer:}\\
\vspace*{114mm}
\emp}

\subsection*{Problem 3}
A discrete-time controller with sampling period $h=0.2$ has been designed for the maglev system, according to the closed-loop block diagram in figure \ref{fig:block}.
\begin{figure}[!h]
\begin{center}
  \begin{tikzpicture}[scale = 0.8, node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}]

    \node[coordinate] (input) {};
     \node[sumnode, right of=input, node distance=16mm] (sum) {\tiny $\sum$};
     \node[block, right of=sum, node distance=26mm] (controller) {$F_d(z)$};
     \node[block, right of=controller, node distance=26mm] (zoh) {ZOH};
     \node[block, below of=zoh, node distance=26mm] (sampler) {Sampler};
     \node[block, right of=zoh, node distance=26mm] (plant) {$G(s)$};
     \node[coordinate, right of=plant, node distance=30mm] (output) {};

     \draw[->] (input) -- node[above, pos=0.3] {$y_{ref}(k)$} (sum);
     \draw[->] (sum) -- node[above] {$e(k)$} (controller);
     \draw[->] (controller) -- node[above] {$u(k)$} (zoh);
     \draw[->] (zoh) -- node[above] {$u(t)$} (plant);
     \draw[->] (plant) -- node[coordinate] (measure) {} node[above, near end] {$y(t)$} (output);
     \draw[->] (measure) |- (sampler);
     \draw[->] (sampler) -| node[above, near start] {$y(k)$} node [left, pos=0.95] {$-$} (sum);
   \end{tikzpicture}
   \end{center}
\caption{Discrete-time feedback control of the maglev system.}
\label{fig:block}
\end{figure}

Let $G_o(z)$ denote the loop gain (gain from $e(k)$ to $y(k)$) of the system, with bode diagram given in figure \ref{fig:loopgainbode}.

\begin{figure}[!h]
\begin{center}
\includegraphics[width=0.9\linewidth]{../../figures/maglev_ss_loopgain_bode}
\end{center}
\caption{Bode diagram of the loop gain for the discrete-time control system in figure \ref{fig:block}.}
\label{fig:loopgainbode}
\end{figure}

\subsubsection*{(a)}
Determine the cross-over frequency and phase margin of the system.

\noindent
\fbox{
\bmpl
{\bf Answer:}\\
\vspace*{54mm}
\emp}

\subsubsection*{(b)}
In the design of the controller in the feedback system of figure \ref{fig:block} it was assumed that an anti-aliasing filter was not needed. However, later it was found that it was indeed necessary to filter the noise in the measured output signal $y(t)$. The modified control system is shown in figure \ref{fig:block-aa}.
\begin{figure}[!h]
\begin{center}
  \begin{tikzpicture}[scale = 0.8, node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}]

    \node[coordinate] (input) {};
     \node[sumnode, right of=input, node distance=16mm] (sum) {\tiny $\sum$};
     \node[block, right of=sum, node distance=26mm] (controller) {$F_d(z)$};
     \node[block, right of=controller, node distance=26mm] (zoh) {ZOH};
     \node[block, below of=zoh, node distance=26mm] (sampler) {Sampler};
     \node[block, right of=zoh, node distance=36mm] (plant) {$G(s)$};
     \node[block, below of=plant, node distance=26mm] (aa) {$H_b(s)$};
     \node[coordinate, right of=plant, node distance=30mm] (output) {};

     \draw[->] (input) -- node[above, pos=0.3] {$y_{ref}(k)$} (sum);
     \draw[->] (sum) -- node[above] {$e(k)$} (controller);
     \draw[->] (controller) -- node[above] {$u(k)$} (zoh);
     \draw[->] (zoh) -- node[above] {$u(t)$} (plant);
     \draw[->] (plant) -- node[coordinate] (measure) {} node[above, near end] {$y(t)$} (output);

     \node[sumnode, below of=measure, node distance=26mm] (sumnoise) {\tiny $\sum$};
     \draw[->] (measure) -- (sumnoise);
     \draw[->] (sumnoise) -- (aa);
     \draw[->] (sumnoise) ++(12mm,0) -- node[above, near start] {$n(t)$} (sumnoise);
     \draw[->] (aa) -- (sampler);
     \draw[->] (sampler) -| node[above, near start] {$y(k)$} node [left, pos=0.95] {$-$} (sum);
   \end{tikzpicture}
   \end{center}
\caption{Discrete-time feedback control of the maglev system with anti-aliasing filter.}
\label{fig:block-aa}
\end{figure}

The anti-aliasing filter $H_b(s)$ is a second-order Bessel filter with Bode diagram given below.
\begin{center}
\includegraphics[width=0.8\linewidth]{../../figures/maglev_bessel_aa_bode}
\end{center}
What is the phase margin of the control system \textbf{with} anti-aliasing filter? How would you \textbf{describe} such a closed-loop system?

\noindent
\fbox{
\bmpl
{\bf Calculations and answer:}\\
\vspace*{104mm}
\emp}

\cleardoublepage

\section*{Solutions}

\subsection*{Problem 1}

\subsubsection*{(a)}
The forward approximation becomes
\[ F_d(z) = F(s)|_{s = \frac{z-1}{h}} = K(1 + \frac{1}{T_i\frac{z-1}{h}}) = K( 1 + \frac{h}{T_i(z-1)}). \]

\subsubsection*{(b)}
The controller is
\[ U(z) = F_d(z)E(z), \]
which using the pulse transfer operator can be written
\[ u(kh) = K(1 + \frac{h}{T_i(\shift-1)}) e(kh) = K \frac{\shift-1 + \frac{h}{T_i}}{\shift-1} e(kh)\]
\[ (\shift -1) u(kh) = K(\shift -1+\frac{h}{T_i}) e(kh)\]
\[ u(kh+h) - u(kh) = K\big(e(kh+h) - (1-\frac{h}{T_i})e(kh)\big)\]
\[ u(kh+h) = u(kh) + K\big(e(kh+h) - (1-\frac{h}{T_i})e(kh)\big)\]

\subsection*{Problem 2}

\subsubsection*{(a)}
The poles are given by the eigenvalues of the $\Phi$ matrix, which in turns are the solutions to the characteristic equation \( \det (zI - \Phi) = 0\). With
\[ \Phi = \bbm 1.02 & 0.20\\0.20 & 1.02 \ebm, \]
we get
\[ \det \bbm z - 1.02 & -0.20\\ -0.20 & z-1.02 \ebm = (z-1.02)^2 - 0.2^2 = z^2 -2.04z + 1.02^2 - 0.2^2.\]
with solutions
\[ z = 1.02 \pm \frac{1}{2}\sqrt{(-2.04)^2 - 4(1.02^2 - 0.2^2)} = \begin{cases} 1.22\\0.82 \end{cases}. \]
Evidently one of the poles are outside the unit circle.

\subsubsection*{(b)}
The dynamics of the observer is given by
\[\hat{x}(k+1) = \big(\Phi - KC\big)\hat{x}(k) + \Gamma u(k) + Ky(k),\] where
\[ KC = \bbm k_1\\k_2 \ebm \bbm 1 & 0 \ebm = \bbm k_1 & 0\\k_2 & 0\ebm.\]
The characteristic polynomial becomes
\begin{equation*}
\begin{aligned}
\det \big( zI - (\Phi-KC)\big) &= \det \left( \bbm z & 0 \\ 0 & z \ebm - \bbm 1.02-k_1 & -0.2\\0.2-k_2 & 1.02\ebm\right)\\
&= \det \bbm z-1.02+k_1 & -0.2\\-0.2+k_2 & z-1.02\ebm = (z-1.02+k_1)(z-1.02) + 0.2(-0.2+k_2)\\
&= z^2 + (-2.04 + k_1)z - 1.02(k_1-1.02) - 0.2^2 + 0.2k_2 = z^2 + (k_1-2.04)z - 1.02k_1 + 0.2k_2 + 1.02^2 - 0.2^2.
\end{aligned}
\end{equation*}
Comparing with the desired characteristic polynomial (poles in the origin) $z^2$, we get the equations
\begin{align*}
k_1 - 2.04 &= 0\\
- 1.02k_1 + 0.2k_2 + 1.02^2 - 0.2^2 &= 0
\end{align*}
with solution
\[ K = \bbm k_1\\k_2 \ebm = \bbm 2.04\\5.40 \ebm.\]

\subsection*{Problem 3}

\subsubsection*{(a)}
\begin{center}
\includegraphics[width=0.9\linewidth]{../../figures/maglev_ss_loopgain_bode_sol}
\end{center}

\subsubsection*{(b)}
At the cross-over frequency the bessel filter has a phase of about $-36^\circ$.
\begin{center}
\includegraphics[width=0.8\linewidth]{../../figures/maglev_bessel_aa_bode_sol}
\end{center}
This means that the phase margin for the system \textbf{with} anti-aliasing filter becomes
\[ \varphi_m = 42.9 - 36 = 6.9^\circ.\] A closed-loop system with this little phase margin will have a large resonance peak and an oscillatory response.

\end{document}