# Communication System
## [Upsampling and downsampling](https://www.eetimes.com/multirate-dsp-part-1-upsampling-and-downsampling/)
### Upsampling
#### Time domain

#### Freq. domain

### Downsampling
#### Time domain

#### Freq. domain

## Z transform
$$X(z)=\sum_{n=-\infty}^{\infty}x[n]z^{-n}$$
When ==$\vert z\vert=1$==, it is known as the DTFT.
Multiplying by $z^{−1}$ is a shift (delay block) that pushed the delta impulse by one unit over. To delay by $N$ steps instead of just 1 step, one simply multiplies by N of these functional delay blocks, i.e. $z^{-N}$.
==So a z-transform is (in the most basic intuitive sense) a description of how to functionally build a system out of delay blocks.==
The Z-transform of the signal will give rise to the pole-zero plot which discusses issues such as ++stability, causality++ etc. of the system.
* Causal
ROC must ++contain infinity++ and the system function will be a right-sided sequence.
* Stable
ROC ++contains the unit circle++.
* Causal and stable
All the poles of the system function must be ++inside the unit circle++.
## [FIR vs IIR](https://www.juansaudio.com/post/iir-vs-fir-understanding-their-differences#:~:text=IIR%20(infinite%20impulse%20response)%20filters,response%20with%20a%20finite%20length.)
In general, digital filters are build with two elemental blocks: delays and gains.
### FIR filters
The idea of FIR filters is to connect the input of the filter to a series of delays (often called a delay line).

### IIR filters
An IIR filter, in addition to using delays for the input values of the filter, also takes values at the output, applies a new delay chain and ==feeds back== this signal to the input of the filter.

## Eigendecomposition vs SVD
### Eigendecomposition
Eigenvectors make understanding linear transformations easy. They are the "axes" (directions) along which a linear transformation acts simply by "stretching/compressing" and/or "flipping"; eigenvalues give you the factors by which this compression occurs.
$$\mathbf{A} =\mathbf{Q}\mathbf{\Lambda}\mathbf{Q}^{-1}$$
* Vector of $\mathbf{Q}$ are not necessarily orthogonal, so the change of basis isn't a simple rotation.
### SVD
$$\mathbf{A}=\mathbf{U}\mathbf{\Sigma}\mathbf{V}^H$$
* $\mathbf{U}$ and $\mathbf{V}$ have orthogonal vectors.
* the diagonal matrix $\mathbf{\Sigma}$ are all real and nonnegative.
==The two are equal when when $\mathbf{A}$ is symmetric positive-semidefinite.==
## Convolution
$$x_1(t)*x_2(t)=\int x_1(\tau)x_2(t-\tau)d\tau$$
* 取樣:$x(t)\delta(t-a) = x(t-a)\delta(t-a)$
* 平移:$x(t)*\delta(t-a) = x(t-a)$
### Autocorrelation
Random process: $R_x(t_1,t_2) = E[x(t_1)x^*(t_2)]$
* $R_x(0) = E$ (energy)
* $R_x(\tau) = R_x(-\tau)$ for real $x$
## Probability
### Independence
$f_{X,Y}(x,y)=f_X(x)f_Y(y), \forall x, y$
### Correlation
$R_{XY} = E[XY]$
### Uncorrelated
Random variables $X$ and $Y$ are ++uncorrelated++ if their ++covariance++ $\text{cov}(X,Y)=E[XY]-E[X]E[Y]$ is zero.
### Gaussian
* If random processes are uncorrelated Gausian processes, then they are independent.
* Gaussian $\to$ LTI system $\to$ Gaussian
### AWGN
* A channel is AGN channel if
* its channel impulse response is $c(n)=\delta(n)$
* channel noise $q(n)$ is a Gaussian random process
* If the noise also satisfy $E[q(n)q^*(m)]=0$ then it is an AWGN channel.
* AGN and AWGN channels have no ISI.
## Random processes
### Real random variables
A random variable is a ++function++ $x(\eta)$ that maps the set of experiment outcomes $\eta$ to the set of numbers. $\eta$ is usually dropped for convenience.
* CDF: $F_x(a) = P(x\le a)=\int_{-\infty}^a f_x(x)dx$
* Expected value: $E[g(x)]=\int g(x)f_x(x)dx$
* Mean: $\mu_x=E[x]$
* Mean square: $E[x^2]$
* Variance: $E[(x-\mu_x)^2]=E[x^2]-\mu_x^2$
### Complex random variables
* Mean: $\mu_x=E[x]$
* Mean square: $E[|x|^2]$
* Variance: $E[|x-\mu_x|^2]$
* Cross correlation: $R_{xy}=E[xy^*]$
#### Physical interpretation
* $\langle x(t)\rangle = E[x]:$ DC component
* $\langle x(t)\rangle^2 = E[x]^2:$ DC power
* $\langle x^2(t)\rangle = E[x^2]:$ signal power
* $\langle x^2(t)\rangle-\langle x(t)\rangle^2 = E[x^2]-E[x]^2:$ AC power
* $R_x(0)=\int S(f)df:$ signal power
* $R_x(\tau\to \infty)=\mu_x^2:$ DC power
* $R_x(0)-R_x(\tau\to \infty):$ AC power
### Random processes
A random process is a rule that maps every outcome $\eta$ of an experiment to a function $x(t, \eta)$. $\eta$ is usually dropped for convenience. ++We can view $x(n)$ (or $X_t$) for every $n$ as a r.v.++.
## Wide-sense-stationary
A continuous time random process $\{X_t\}$ which is WSS has the following restrictions on its mean function $m_x(t)\triangleq E[X_t]$ and autocovariance function $R_{X}(t_1,t_2)=E[X_{t_1}X^*_{t_2}]$:
1. $m_x(t) = m_x(t+\tau) \quad \forall \tau$
The ++mean function must be constant++.
2. $R_{X}(t_1,t_2)=R_{X}(t_1-t_2, 0)=R_X(\tau)\quad \forall t_1,t_2$
The ++autocovariance function depends only on the difference between $t_1$ and $t_2$++ and only needs to be indexed by one variable rather than two variables.
3. $E[\vert X_t\vert^2]\lt\infty \quad \forall t$
The second moments must be finite for any time.
### LTI systems
* WSS process $\to$ LTI system $\to$ WSS process
--
* $\mu_y = \mu_xH(0)$ (DC)
* $R_y(\tau) = R_x(\tau)*h(\tau)*h^*(-\tau)$
* $S_y(f) = S_x(f)|H(f)|^2$
* $P_y$(power of $y(t)$) $=R_y(0)=\int S_y(f)df$
## Passing through D/C and C/D
### C/D

* $r[n] = w_a(nT)=(r_a*p_2)(t)|_{t=nT}$
* $R_r(k) = R_{w_a}(kT)=R_{r_a}(\tau)*p_2(\tau)*p^*(-\tau)|_{t=kT}$
### D/C

* $x_a(t)=\sum_n x[n]p_1(t-nT)$
* $R_{x_a}(\tau)=\frac{1}{T}\sum_k R_x(k)h(\tau-kT)$, where $h(\tau)=p_1(\tau)*p^*_1(-\tau)$
* $S_{x_a}(f)=\frac{1}{T}S_x(e^{j2\pi fT})|P_1(f)|^2$
## PSD
$S_x(f)=\lim_{T\to \infty}E[\frac{|X_T(f)|^2}{2T}]$, where $x_T(t)=x(t), -T<t<T$.
### Wiener–Khinchin theorem
For a ++wide-sense-stationary++ random process $x(t)$, its power spectrum $S_x(f) = \vert X(f)\vert^2= \mathcal{F}(R_x(\tau))$.
## LTI systems
### Linearity
If $H[x_1(t)]=y_1(t)$ and $H[x_2(t)]=y_2(t)$. Then $H[c_1 x_1(t)+c_2 x_2(t)]=c_1y_1(t)+c_2y_2(t)$.
### Time invariant
$H[x(t-a)]=y(t-a)$
### BIBO stable
$\int|h(t)|dt\lt\infty$
### Causality
$h(t)=0 \quad \forall t<0$
The output signal value at any time $t$ depends only on input signal values for times less than $t$.
### Memoryless
The output signal value at any time t depends only on the input signal value at that same time.
## Sampling theorem
$$m(t)\to g(t)=\sum\delta (t-nT_s)\to m_\delta(t)$$
$m_\delta(t) = \sum m(nT_s)\delta(t-nT_s)$
$M\delta(f) = M(f)*(f_s\sum\delta(f-kf_s))=f_s\sum M(f-kf_s)$ (Repeat every $f_s$)

Nyquist rate: $f_s=2W$
## Nyquist ISI criterion
$G(f)$ is the Fourier transform of the system impulse response $g(t)=p_1(t)*c(t)*p_2(t)$.
++Frequency-shifted replicas of $G(f)$ must add up to a constant value.++ When the baseband filters in the communication system satisfy the Nyquist criterion, symbols can be transmitted over a channel with flat response within a limited frequency band, without ISI.
Examples of such baseband filters are the raised-cosine filter, or the sinc filter as the ideal case.
### Intersymbol interference (ISI)
The spreading of the pulse beyond its allotted time interval causes it to interfere with neighboring pulses. It is a signal-dependent form of interference.
#### Causes
* Multipath propagation
* Inherent linear or non-linear frequency response of a communication channel causing successive symbols to blur together
* Bandlimited channels
A relatively tight filter in the frequency domain MUST have a long impulse response in the time domain. So if you have a filter with a long impulse response, it goes to say that it's response to one symbol will extend into other symbols, causing ISI.
#### Solve
* Guard periods
* ==ISI is negligible== in comparison to that of channel noise
* use a ==matched filter==
* received signal-to-noise ratio is high enough to ignore the effect of channel noise
* ==pulse shaping==
--
Communication systems that transmit data over bandlimited channels usually ++implement ==pulse shaping== to avoid interference caused by the bandwidth limitation++.
#### Why OFDM uses CP while single carrier uses match filter(and pulse shaping) to deal with ISI?
https://dsp.stackexchange.com/questions/7725/why-does-ofdm-use-cyclic-prefix-while-qpsk-uses-root-raised-cosine-filters
https://www.dsprelated.com/thread/10630/do-we-use-a-matched-filter-in-an-ofdm-system-for-pulse-shaping
==ISI means different things in the context of PSK and OFDM signals.==
In PSK signals the symbols almost always have ==tails== that extend, in the time-domain, into the times of other symbols.
They eliminate the negative effects of intersymbol interference by very carefully shaping the symbols so that when the receiver filters them through a matched filter, ==the other symbols have zero output at the sampling times of the other symbols==.
### Controled ISI
* $W = f_s/2$
* duobinary coding
* feedback devision $\to$ error propagation
--
The purpose of the ==base-band filter== in OFDM TX is to ==smooth the transition== from one symbol to another in the time domain.
The reason cyclic prefix is used in OFDM systems is to ==avoid complex equalizers in receivers==. Cyclic prefix converts linear convolution of fading channel $h(t)$ & Tx data $x(t)$ into ==circular convolution==.
## Fading channel
### Fading type

### Coherence Time and Coherence Bandwidth
#### Coherence Time
* Maximum doppler: $f_y = f_c\dfrac{v}{c}$
* ==Coherence time==: $\frac{1}{f_y}$
Time over which channel is constant
##### Fast fading
* High Doppler Spread
* ==Coherence Time < Symbol Period==
* ==Channel impulse response changes rapidly== within the symbol duration
* It occurs for very low data rates
* NO ISI (OFDM)
* The transmitter may take advantage of the variations in the channel conditions using ==time diversity== to help increase robustness of the communication to a temporary deep fade.

##### Slow fading
* ==Coherence Time >> Symbol Period==
* High data rate
* ISI

#### Coherence Bandwidth
* Maximum delay spread $D$: difference between the time of arrival of the earliest significant multipath component and the time of arrival of the last multipath components
* ==Coherence bandwidth==:$\frac{1}{D}$
* Flat fading: signal bandwidth is smaller than the channel coherence bandwidth. ==All frequency components of the signal will experience the same magnitude of fading.==
* Frequency selective fading: ==Different frequency components of the signal therefore experience uncorrelated fading.==
### Why OFDM can combat frequency selective channel
OFDM divides the wideband signal into many slowly modulated narrowband subcarriers, each exposed to flat fading rather than frequency selective fading. This can be combated by means of error coding, simple equalization or adaptive bit loading. Inter-symbol interference is avoided by introducing a guard interval between the symbols called a cyclic prefix.
#### Deep fade
Strong destructive interference is frequently referred to as a deep fade and may result in temporary failure of communication due to a severe drop in the channel signal-to-noise ratio.
#### Rayleigh
* LOS is blocked
* large number of scattering
#### Rician
* LOS exists
* large number of scattering
### Error rate
For BPSK:

* AWGN decrease exponentially.
* Rayleigh decrease linearly.
#### Diversity
To ensure the data symbols passing thru ++multiple paths++, each of which ++fades independently++.
* Time diversity
Transmit the same signal in different time slots. (seperation > coherence time)
* Frequency diversity
Transmit the same signal in different freq. bands. (seperation > coherence bandwidth)
* ==Spatial diversity (MIMO)==
Different antenna. (seperation > wavelength/2)
* Selection combining (SC)
Select ++one branch++ with the ++highest SNR++.
* Equal gain combining (EGC)
All the received signals are summed ++coherently++. $\to$ reverse the effect of channel phase shift
* Maximal ratio combining (MRC)
The received signals are ++weighted with respect to their SNR and then summed++.
## Bayes decision theory



* Partition the received signals into $M$ regions: $z_1,z_2$.
* If the received signal fall in region $z_i$, then $\hat{s}=s_i$.
* $H_i$: signal "$i$" event ($H_0, H_1$).
* Prior probability $P(H_i)$ and likelihood function $f(\overrightarrow{x}|H_i)$ are known.
###
* Decision cost $C_{ij}$: cost of "send $j$ but decided as $i$"
* $P(\hat{H_i}|H_j)$: send $j$ and decided as $i$
* Bayesian risk
\begin{align} R = & C_{00}P(H_0)P(\hat{H_0}|H_0)+C_{10}P(H_0)P(\hat{H_1}|H_0)\\
+&C_{01}P(H_1)P(\hat{H_0}|H_1)+C_{11}P(H_1)P(\hat{H_1}|H_1)
\end{align}
### Bayes decision rule
Find $z_1, z_2$ to minimize $R$.

### MAP (Maximum a posteriori Probability)
For $C_{00}=C_{11}=0$ and $C_{01}=C_{10}=1$,
then $R=P(H_0)P(\hat{H_1}|H_0)+P(H_1)P(\hat{H_0}|H_1)=P_e$


### ML (Maximum Likelihood、觀測機率)
When ==$P(s_i)=\frac{1}{M}, \forall i$ (事前機率皆相等)==


### MD (Minimum Distance)
When the channel is ==AWGN==.


### MC (Maxmum Correlator)
When $E_i=|s_i|^2=E$ (==$s_i(t)$ 能量相等==)

### ==Decision summary==

## Single-carrier vs. multi-carrier
#### Single-carrier
Pros
* Simple in flat fading channels
Cons
* Bad for high rate wireless transmission due to high-complexity equalizer to deal with ISI.
#### Multi-carrier
Pros
* High bandwidth efficiency
Cons
* large ACI(adjecent carrier interference) for a small number of subcarriers
### [Why multicarrier?](https://www.bartleby.com/essay/Advantages-And-Disadvantages-Of-Multicarrier-Modulation-PCC7LYW92R)
Multicarrier modulation provides ==immunity to fading== caused by data transmission over multipath fading channels or frequency-selective fading channels. ==Each of the subchannel experiences flat fading due to the decreased bandwidth==. Also, due to the ==increase in the symbol period, it provides enhanced immunity to ISI==(because $T >> \Delta t$). Another advantage of multicarrier modulation technique is it can provide ==better spectral efficiency== compared to single carrier modulation, since the ==spectrum of the subcarrier can be overlapped==.

==For singlecarrier, as the symbol rate increases, the signal bandwidth becomes larger== (In order to support the symbol rate of $R_s$ symbols per second, the minimum required bandwidth is the Nyquist bandwidth, which is given by $R_s/2$). When the signal bandwidth becomes ==larger than the coherence bandwidth== in the wireless channel, the link suffers from ==multi-path fading, incurring the ISI==.
In conclusion, ==a high data rate single-carrier transmission may not be feasible due to too much complexity of the equalizer in the receiver==.
### Serial to parallel (S/P)
將一連串的高速寬頻資料經序列轉平行(S/P)分成多個低速的窄頻資
料後以不同的載波來傳輸。原本資料傳輸速率為 1/T,符元長度為 T,經過 S/P 後資料速率降為 1/NT,符元長度增長為 NT,當 N 越大,符元長度拉的越長,所以在相同的傳輸速率下,多載波調變系統能忍受較大的通道延遲。
## Parseval's theorem
$$\int\vert x(t)\vert^2dt=\int\vert X(f)\vert^2df$$
## Hilbert transform
It imparts a ++phase shift of ±90°++ ($\frac{\pi}{2}$ radians) to every frequency component of a function.
### Analytic signal
an analytic signal is a ++complex-valued function that has no negative frequency components++. The real and imaginary parts of an analytic signal are real-valued functions related to each other by the Hilbert transform.
## SNR

* Pre-dection SNR: $SNR_I=\frac{P_T}{N_0 B_T}$
* Post-dection SNR: $SNR_O=\frac{\text{power of }km(t)}{\text{power of }n_0(t)}$
* Channel SNR: $SNR_C=\frac{P_T}{N_0 W}$
* Figure of Merit(FOM, larger the better): $\frac{SNR_O}{SNR_C}$
## Spread spectrum (展頻)
Signal bandwidth is deliberately spread in the frequency domain, resulting in a signal with a wider bandwidth.
* Robust against noise, interference, jamming.
* Higher privacy.
* CDMA: Multiple users can transmit simultaneously in the same frequency band as long as they use different spreading sequences.
## Information theory
### Channel Capacity
Max rate of a channel with arbitrarily small error probability.
#### Outage
When the transmit rate is highter than the channel capacity.
#### Outage capacity
Largest transmit rate such that the outage capacity is less than $\epsilon$.
### Information content (bit)
若資訊源有 m 種消息,且每個消息的可能性相等,該信源的訊息量可表示如: $I=\log_2{m}$
### Information entropy
$$H(X)=\sum_i P(x_i)I(x_i)=\sum_i P(x_i)\log_2{\frac{1}{P(x_i)}}$$
### Shannon's first theorem (source coding thoerem, noiseless coding theorem)
==limits to possible data compression==
#### Source coding
Source symbols can be exactly recovered from the binary bits (lossless source coding) or recovered within some distortion (lossy source coding). ==data compression==
#### Shannon–Fano Code

#### Huffman Code

### Shannon's second theorem (channel coding theorem)
This theorem introduces ==the channel capacity as the bound for reliable communication over a noisy channel==.
#### Channel coding
A process of ==detecting and correcting bit errors== in digital communication systems.
### Shannon's third theorem (Shannon–Hartley theorem)
For ==AWGN channel, the channel capacity $C\text{(bps)}=B\log_2{(1+\dfrac{S}{N})}$==, where $B$ is the bandwidth of the channel, $S$ is the average received signal power and $N$ is the average power of the noise.
## Forward Error Correction (FEC)
A ==channel encoding== method: Enough redundent information so the receiver can recover the signal.
==Goal: smallest code distance.==
#### Hamming weight
Number of 1s in a string.
#### Hamming distance
Number of different bits between two strings.
## Error correction code (ECC)
### block codes
work on fixed-size blocks (packets) of bits or symbols of predetermined size.
### convolutional codes
work on bit or symbol streams of arbitrary length. They are most often soft decoded with the Viterbi algorithm
### Interleaving
Errors typically occur in bursts rather than independently. If the number of errors within a code word exceeds the error-correcting code's capability, it fails to recover the original code word. Interleaving alleviates this problem by shuffling source symbols across several code words, thereby creating a more uniform distribution of errors.

## MIMO
### Diversity Combining Techniques
#### Selective Combining
++Select one++ branch with the highest received SNR.
#### Equal Gain Combining
++Coherently combine++ received signal.
#### Maximal Ratio Combining
++Coherently combine++ received signal + ++weighted for signal quality++.
### Capacity of SIMO/MISO Channel
#### SIMO (single Tx multiple Rx)
* Capacity: $\log_2{(1+SNR\cdot|\mathbf{h}[m]|)}$, where channel vector $\mathbf{h}[m]=[h_1[m] h_2[m]... h_L[m]]^H$.
#### MISO
* Transmit diversity
Whether channel stat information is known at the Tx affects the achievable rate of MISO
* If Tx and Rx both have perfect CSI
MISO channel capacity = SIMO channel capacity
* If Tx has no CSI but Rx has perfect CSI
MISO channel capacity < SIMO channel capacity
Channel capacity won't improve as the number of antennas reached a certain point.
### Capacity of MIMO Channel
$$C=\sum_{i=1}^r\log{(1+\dfrac{E_i}{N_0}\sigma_i^2)}$$
Where $E_1+...+E_r\le E_s$.
==The channel capacity can be increased by the factor of $\min{(N_T,N_R)}$==
* $\mathbf{H}\in \mathbb{C}^{N_R\times N_T}=\mathbf{U\Sigma V}^H$.
* $\mathbf{V}\in \mathbb{C}^{N_T\times N_T}$ is the precoding matrix.
* $\mathbf{U}^H\in \mathbb{C}^{N_R\times N_R}$ is the decoding matrix.
Precoding through SVD of $\mathbf{H}$ can decomposed MIMO channel as $r$ parallel channels, where $r=\min{(N_T,N_R)}$.

* $\lambda_i$ is the $i$-th eigenvalue of $\mathbf{HH}^H$.
* $\sqrt{\lambda_i}=\sigma_i$ is the $i$-th singular value of $\mathbf{H}$.
#### Perfect CSIT
We can maximize $C$ by $\max_{\{E_i\}}\sum_{i=1}^r\log{(1+\dfrac{E_i}{N_0}\sigma_i^2)}$ and use the Lagrange multiplier to find the solution. $\to$ water filling method
* Eigen channel 狀況好 $\to$ 分配到更多功率
#### No CSIT
Space time processing at Tx
##### Assume the channel is unkown at Tx and Rx.
* High SNR
$C \approx r\cdot \log{(\frac{SNR}{N_T})}$
* Low SNR
==$C$ is linearly porpotional to $N_R$ and independent of $N_T$.==
##### Assume the channel is kown at Tx.
* High SNR
$C \approx r\cdot \log{(\frac{SNR}{r})}$
==CSI is not so important when SNR is large enough.==
### Diversity & multiplexing
* Diversity
不同天線借由資料的擺放方式設計達成錯誤率低的傳輸(reliability)
* Multiplexing
不同的傳輸天線傳不同data stream,在 independent channels 上做傳輸,增加data rate (throughput)
* Diversity–multiplexing tradeoff
error probability vs throughput