Discrete Signal Processing (DSP):

Discrete Signals


By Prof. Seungchul Lee
http://iai.postech.ac.kr/
Industrial AI Lab at POSTECH

Table of Contents

1. Discrete Time Signals

A signal $x[n]$ is a function that maps an independent variable to a dependent variable.

In this course, we will focus on discrete-time signals $x[n]$:

  • Independent variable is an integer: $n \in \mathbb{Z}$
  • Dependent variable is a real or complex number: $x[n] \in \mathbb{R}$ or $\mathbb{C}$




1.1. Plot Real Signals

  • plot for continuous signals in MATLAB

  • stem for discrete signals in MATLAB

$$x(t) = \sin(2\pi t)$$
In [2]:
%plot -s 560,200

t = 0:0.01:2;
x = sin(2*pi*t);

plot(t, x, 'linewidth', 2);
ylim([-1.1 1.1]);
xlabel('t [sec]');
ylabel('x(t)');

$$x[n] = \sin \left(\frac{2 \pi}{N}n \right)$$
In [3]:
%plot -s 560,400

N = 20;
n = 0:N-1;
x = sin(2*pi/N*n);

subplot(2,1,1)
plot(n,x,'o'), axis tight, ylim([-1.2, 1.2])
subplot(2,1,2)
stem(n,x,'filled'), axis tight, ylim([-1.2, 1.2])

2. Signal Properties

2.1. Finite/Infinite-Length Signals

  • An infinite-length discrete-time signal $x[n]$ is defined for all $n \in \mathbb{Z}$, i.e., $-\infty < n < \infty$



  • An finite-length discrete-time signal $x[n]$ is defined only for a finite range of $N_1 < n < N_2$




2.2. Periodic Signals

  • A discrete-time signal is periodic if it repeats with period $N \in \mathbb{Z}$


$$x[n+mN] = x[n], \qquad \forall m \in \mathbb{Z}$$




  • The period $N$ must be an integer
  • A periodic signal is infinite in length
  • Convert an infinite-length signal $x[n]$ into a finite-length signal $y[n]$ by windowing


$$y[n] = \begin{cases}x[n] & N_1 \leq n \leq N_2\\ 0 & \text{otherwise} \end{cases}$$


  • Convert a finite-length signal $x[n]$ defined for $N_1 \leq n \leq N_2$ into an infinite-length signal by either
    • (infinite) zero padding, or
      $$y[n] = \begin{cases} 0 & n < N_1\\ x[n] &N_1 \leq n \leq N_2\\ 0 & N_2 < n\end{cases}$$
    • periodization with period $N$
      $$\begin{align*}y[n] &= \sum_{m=-\infty}^{\infty}x[n-mN]\\&=\cdots + x[n+N] + x[n] + x[n-N]+ \cdots\end{align*}$$




2.3. Modular Arithmetic

  • Modular arithmetic with modulus $N$ takes place on a clock with $N$
    • Modular arithmetic is inherently periodic $$\cdots = (-12)_8 = (-4)_8 = (4)_8 = (12)_8 = (20)_8 = \cdots$$




  • Periodization via Modular Arithmetic
    • Consider a length-$N$ signal $x[n]$ defined for $0 \leq n \leq N-1$
    • A convenient way to express periodization with period $N$ is $y[n] = x[(n)_N]$
    • Important interpretation
      • Infinite-length signals live on the (infinite) number line
      • Periodic signals live on a circle
In [4]:
%plot -s 560,100

N = 8;
n = 0:N-1;
x = [0 1 2 3 4 3 2 1];

stem(n,x,'filled');
xlabel('n'), ylabel('x[n]')
xlim([-16,23]), 
yticks([0,4])
box('off')

In [5]:
%plot -s 560,100

%% periodic using mod
y = [];
n = -16:23;

for i = 1:length(n)
    y(i) = x(mod(n(i),N)+1);
end

stem(n,y,'filled'), axis tight
xlabel('n'), ylabel('y[n]')
yticks([0,4])
box('off')

2.4. Finite-Length and Periodic Signals

  • Finite-length and periodic signals are equivalent
    • All of the information in a periodic signal is contained in one period (of finite length)
    • Any finite-length signal can be periodized
    • Conclusion: We will think of finite-length signals and periodic signals interchangeably




  • Shifting infinite-length signals
    • Given an infinite-length signal $x[n]$, we can shift back and forth in time via $x[n-m]$
    • When $m>0, x[n-m]$ shifts to the right (forward in time, delay)
    • When $m<0, x[n-m]$ shifts to the left (back in time, advance)




  • Shifting periodic signals
    • Periodic signals can also be shifted; consider $y[n]=x[(n)_N]$
    • Shift one sample into the future: $y[n-1] = x[(n-1)_N]$




  • Shifting finite-length signals
    • Consider finite-length signals $x$ and $y$ defined for $0 \leq n \leq N-1$ and suppose $y[n] = x[n-1]$

      $$ \begin{align*} y[0] &= \;?\\ y[1] &= x[0]\\ y[2] &= x[1]\\ y[3] &= x[2]\\ &\vdots\\ y[N-1] &= x[N-2]\\ ?\; &= x[N-1]\\ \end{align*} $$
    • What to put in $y[0]?$ What to do with $x[N-1]$? We do not want to invent/lose information
    • Elegant solution: Assume $x$ and $y$ are both periodic with period $N$; then $y[n]=x[(n-1)_N]$
    • This is called a periodic or circular shift
  • Circular time reversal
    $$y[n]= x[(-n)_N]$$
    • Example with $N = 8$
$$ \begin{align*} y[0] &= x[0]\\ y[1] &= x[7]\\ y[2] &= x[6]\\ y[3] &= x[5]\\ &\vdots\\ y[7] &= x[1] \end{align*} $$




3. Key Discrete Signals

3.1. Delta Function (aks Unit Impulse)


$$\delta[n] = \begin{cases}1 & n=0\\ 0 &\text{otherwise}\end{cases}$$




  • The shifted delta function $\delta[n-m]$ peaks up at $n=m$, (here $m=5$)




  • Delta functions sample
    • Multiplying a signal by a shifted delta function picks out one sample of the signal and sets all other samples to zero

      $$y[n]=x[n]\delta[n-m]=x[m]\delta[n-m]$$
    • Important: $m$ is a fixed constant, and so $x[m]$ is a constant (and not a signal)




Delta function: $\delta[n]$

$$x[n]=\delta[n-n_0] \quad n_1 \leq n \leq n_2$$

impseq(n0,n1,n2):

function [x,n] = impseq(n0,n1,n2)

% Generates x(n) = delta(n-n0); n1 <= n,n0 <= n2
% [x,n] = impseq(n0,n1,n2)

if ((n0 < n1) | (n0 > n2) | (n1 > n2))
    error('arguments must satisfy n1 <= n0 <= n2')
end

n = [n1:n2];
% x = [zeros(1,(n0-n1)), 1, zeros(1,(n2-n0))];
x = [(n-n0) == 0];
$$x[n] = 2\delta[n+2] - \delta[n-4]$$
In [6]:
%plot -s 560,400

% delta function

n = [-5:5];
x1 = impseq(0,-5,5);
x2 = 2*impseq(-2,-5,5)-impseq(4,-5,5);

subplot(2,1,1), stem(n,x1,'filled'), axis([-5,5,-1.5,2.5]), ylabel('x_1[n]');
subplot(2,1,2), stem(n,x2,'filled'), axis([-5,5,-1.5,2.5]), xlabel('n'), ylabel('x_2[n]');

3.2. Unit Step Function


$$u[n]= \begin{cases}1 & n \geq 0\\ 0 & n<0\end{cases}$$




  • The shifted unit step $u[n-m]$ jumps from $0$ to $1$ at $n=m$, (here $m=4$)




  • Unit step selects part of a signal

    • Multiplying a signal by a shifted unit step function zeros out its entries for $n<m$

      $$y[n] = x[n]u[n-m]$$




Step function: $u[n]$

$$x[n]=u[n-n_0] \quad n_1 \leq n \leq n_2$$

stepseq(n0,n1,n2):

function [x,n] = stepseq(n0,n1,n2)
% Generates x(n) = u(n-n0); n1 <= n,n0 <= n2
% [x,n] = stepseq(n0,n1,n2)

if ((n0 < n1) | (n0 > n2) | (n1 > n2))
    error('arguments must satisfy n1 <= n0 <= n2')
end

n = [n1:n2];
% x = [zeros(1,(n0-n1)), ones(1,(n2-n0+1))];
x = [(n-n0) >= 0];
$$ \begin{align*} x_1[n] &= u[n] - u[n-10] \\\\ x_2[n] &= 0.9^n u[n] \end{align*} $$
In [7]:
%plot -s 560,400

% step function

n = -5:30;
x1 = stepseq(0,-5,30) - stepseq(10,-5,30);

x2 = 0.9.^n.*stepseq(0,-5,30);

subplot(2,1,1), stem(n,x1,'filled'), axis tight, ylim([-0.1, 1.1]), yticks([0,1]), ylabel('x_1[n]') 
subplot(2,1,2), stem(n,x2,'filled'), axis tight, ylim([-0.1, 1.1]), yticks([0,1]), ylabel('x_2[n]')

3.3. Real Exponential


$$x[n] = a^n, \quad n \in \mathbb{R}$$
  • For $a>1$, $x[n]$ grows to the right




  • For $0<a<1$, $x[n]$ shrinks to the right




3.4. Sinusoid Signals

There are two natural real-valued sinusoids: $\cos (\omega n + \phi)$ and $\sin(\omega n + \phi)$

  • Frequency: $\omega$ (units: radians/sample)

  • Phase: $\phi$ (units: radians)

  • $\cos (\omega n)$




  • $\sin (\omega n)$




3.4.1. Frequency of Sinusoid

  • $\cos (0 n)$




  • $\cos \left(\frac{2\pi}{10} n \right)$




  • $\cos \left(\frac{4\pi}{10} n \right)$




  • $\cos \left(\frac{6\pi}{10} n \right)$




  • $\cos \left(\frac{10\pi}{10} n \right)=\cos(\pi n)$




3.4.2. Phase of Sinusoid

$\phi$ is a (frequency independent) shift that is referenced to one period of oscillation

  • $\cos \left( \frac{2\pi}{10}\right)$




  • $\cos \left( \frac{2\pi}{10} - \frac{\pi}{2}\right)$




  • $\cos \left( \frac{2\pi}{10} - \frac{2\pi}{2}\right)$




  • $\cos \left( \frac{2\pi}{10} - \frac{3\pi}{2}\right)$




  • $\cos \left( \frac{2\pi}{10} - \frac{4\pi}{2}\right) = \cos \left( \frac{2\pi}{10}\right)$




4. Discrete Signal Synthesis

4.1. Key Functions for Signal Synthesis


function [y,n] = sigshift(x,m,n0)
% implements y(n) = x(n-n0)
% [y,n] = sigshift(x,m,n0)

n = m + n0;
y = x;
function [y,n] = sigfold(x,n)

% implements y(n) = x(-n)
% [y,n] = sigfold(x,n)

y = fliplr(x); 
n = -fliplr(n);
function [y,n] = sigadd(x1,n1,x2,n2)

% implements y(n) = x1(n)+x2(n)
% [y,n] = sigadd(x1,n1,x2,n2)
%   y = sum sequence over n, which includes n1 and n2
%  x1 = first sequence over n1
%  x2 = second sequence over n2 (n2 can be different from n1)

n = min(min(n1),min(n2)):max(max(n1),max(n2));           % duration of y(n)

y1 = zeros(1,length(n)); y2 = y1;                        % initialization
y1(find((n >= min(n1)) & (n <= max(n1)) == 1)) = x1;     % x1 with duration of y
y2(find((n >= min(n2)) & (n <= max(n2)) == 1)) = x2;     % x2 with duration of y
y = y1 + y2;                                             % sequence addition
function [y,n] = sigmult(x1,n1,x2,n2)
% implements y(n) = x1(n)*x2(n)
% [y,n] = sigmult(x1,n1,x2,n2)
%   y = product sequence over n, which includes n1 and n2
%  x1 = first sequence over n1
%  x2 = second sequence over n2 (n2 can be different from n1)

n = min(min(n1),min(n2)):max(max(n1),max(n2));           % duration of y(n)

y1 = zeros(1,length(n)); y2 = y1;               
y1(find(( n>= min(n1)) & (n <= max(n1)) == 1)) = x1;     % x1 with duration of y
y2(find(( n>= min(n2)) & (n <= max(n2)) == 1)) = x2;     % x2 with duration of y
y = y1 .* y2;                                            % sequence multiplication
$$ \begin{align*} x[n]=\{1,2,&\;3,4,5,6,7,6,5,4,3,2,1\}\\ &\uparrow \end{align*} $$


$$x_1[n]=2x[n-5]-3x[n+4]$$
In [8]:
%plot -s 560,400

n = -2:10; 
x = [1:7,6:-1:1];

[x11,n11] = sigshift(x,n,5); 
[x12,n12] = sigshift(x,n,-4);
[x1,n1] = sigadd(2*x11,n11,-3*x12,n12);

subplot(2,1,1), stem(n,x,'filled'), xlim([-6,15]), ylim([-21,14])
subplot(2,1,2), stem(n1,x1,'filled'), axis tight
xlabel('n'), ylabel('x_1(n)')

$$\begin{align*} x[n]=\{1,2,&\;3,4,5,6,7,6,5,4,3,2,1\}\\ &\uparrow \end{align*}$$


$$x_2[n]=x[3-n]+x[n]x[n-2]$$
In [9]:
%plot -s 560,200

[x21,n21] = sigfold(x,n); 
[x21,n21] = sigshift(x21,n21,3);

[x22,n22] = sigshift(x,n,2); 
[x22,n22] = sigmult(x,n,x22,n22);

[x2,n2] = sigadd(x21,n21,x22,n22);

stem(n2,x2,'filled'), axis tight
xlabel('n'), ylabel('x_2(n)')

4.2. Think of $x[k-n]=x[-n+k]$

Given

$$\begin{align*} x[n]=\{&\;0,1,2,3,0,0,0\}\\ &\uparrow \end{align*}$$
In [10]:
%plot -s 560,200

N = 7;
x = [0 1 2 3 0 0 0];
n = 0:N-1;

stem(n,x,'filled')

$$x_1[n] = x[-n]$$
In [11]:
%plot -s 560,400
[x1,n1] = sigfold(x,n);

subplot(2,1,1), stem(n,x,'filled')
ylabel('x[n]'), axis([-6.5 6.5 -1 4])
subplot(2,1,2), stem(n1,x1,'filled')
ylabel('x[-n]'), axis([-6.5 6.5 -1 4])

$$x_2[n] = x[n-2]$$
In [12]:
%plot -s 560,400
[x2,n2] = sigshift(x,n,2);

subplot(2,1,1), stem(n,x,'filled')
ylabel('x[n]'), axis([-0.5 8.5 -1 4])
subplot(2,1,2), stem(n2,x2,'filled')
ylabel('x[n-2]'), axis([-0.5 8.5 -1 4])

$$x_3[n] = x[-n+2] ~?$$


$$x_4[n] = x[-n+2] ~?$$


$$x[n] \quad \rightarrow \quad x[-n] \quad \rightarrow \quad x[-(n-k)]$$
In [13]:
%plot -s 560,460

[x2,n2] = sigshift(x,n,2);
[x3,n3] = sigfold(x2,n2);

[x1,n1] = sigfold(x,n);
[x4,n4] = sigshift(x1,n1,2);

subplot(3,1,1), stem(n,x,'filled')
ylabel('x[n]'), axis([-8.5 8.5 -1 4])
subplot(3,1,2), stem(n3,x3,'filled')
ylabel('x_3[n]'), axis([-8.5 8.5 -1 4])
subplot(3,1,3), stem(n4,x4,'filled')
ylabel('x_4[n]'), axis([-8.5 8.5 -1 4])

5. Complex Sinusoid

5.1. Complex Numbers

$$z_1 = a_1 + b_1i, \quad \vec{z}_1 = \begin{bmatrix} a_1 \\ b_1 \end{bmatrix} $$


$$z_2 = a_2 + b_2i, \quad \vec{z}_2 = \begin{bmatrix} a_2 \\ b_2 \end{bmatrix} $$

  • Addition
$$ \begin{align*} z &= z_1 + z_2 = (a_1 + a_2) + (b_1 + b_2)i \\ \\ \vec{z} &= \vec{z}_1 + \vec{z}_2 = \begin{bmatrix} a_1 \\ b_1 \end{bmatrix}+ \begin{bmatrix} a_2 \\ b_2 \end{bmatrix} = \begin{bmatrix} a_1 + a_2 \\ b_1 + b_2 \end{bmatrix} \end{align*} $$




  • Multiplication
$$\begin{cases} z_1=r_1e^{i\theta_1}\\ \\ z_2=r_2e^{i\theta_2} \end{cases} \quad\Longrightarrow\quad \begin{cases} z_1\centerdot z_2=r_1r_2e^{i(\theta_1+\theta_2)} \\ \\ {z_1 \over z_2}={r_1 \over r_2}e^{i(\theta_1-\theta_2)} \end{cases} $$



  • Euler's Formula:
$$ e^{i\theta} = \text{cos}\theta + i\text{sin}{\theta}$$
  • Complex number in complex exponential
$$ \begin{align*} \vec{z} &= r \, \text{cos}\theta + i\,r\,\text{sin}\theta \\ &= r\,(\text{cos}\theta + i\text{sin}\theta) \\ &= re^{i\theta}\\ \\ r &: \text{magnitude (length)} \\ \theta &: \text{phase (angle)} \end{align*} $$




  • When $x[n] \in \mathbb{C}$, we can use two signal plots


$$ \begin{align*} x[n] &= \text{Re}\{x[n]\} + j \text{Im} \{x[n]\} & \text{Rectangular form}\\\\ x[n] &= \lvert x[n] \rvert e^{j \angle x[n]} & \text{Polar form} \end{align*} $$


  • For $e^{j \omega t}$




5.2. Geometrical Meaning of $e^{i\theta}$

  • $e^{i\theta}: \text{point on the unit circle with angle of } \theta$


  • $\theta = \omega t$
  • $e^{i\omega t}: \text{rotating on an unit circle with angular velocity of } \omega$.


  • Question: what is the physical meaning of $e^{-i\omega t}$?
  • Frequency $\omega$ determines rotation speed and direction of a circular motion
    • $\omega > 0 \implies$ counterclockwise rotation
    • $\omega < 0 \implies$ clockwise rotation

5.3. Sinusoidal Functions from Circular Motions



  • A complex sinusoid is a helix
    • Real part ($\cos$ term) is the projection onto the $\text{Re}$ axis.
    • Imaginary part ($\sin$ term) is the projection onto the $\text{Im}$ axis.



$$\text{cos}\;\omega t = \large{e^{i\omega t } + e^{-i\omega t} \over 2}$$

6. Discrete Sinusoids

Discrete Sinusoids


$$ \begin{align*}x[n] &= A\cos(\omega_0 n + \phi)\quad \text{or}\\ \\ x[n] &= Ae^{j (\omega_0 n + \phi)} \qquad \text{where} \;\; \omega_0 = \frac{2\pi}{N}k\end{align*}$$


6.1. Aliasing of Sinusoids

Consider two sinusoids with two different frequencies


$$ \begin{align*} \omega \quad &\implies \quad x_1[n] = e^{j(\omega n + \phi)}\\ \omega + 2 \pi \quad &\implies \quad x_2[n]= e^{j((\omega+2\pi) n + \phi)}=e^{j(\omega n + \phi)}e^{j2\pi n} \end{align*} $$
  • But note that
$$x_2[n] = x_1[n]$$
  • The signal $x_1$ and $x_2$ have different frequencies but are identical
  • We say that $x_1$ and $x_2$ are aliases; this phenomenon is called aliasing
In [14]:
% plot -s 560,400

N = 15;
n = 0:N-1;

x1 = cos(2*pi/N*n);
x2 = cos((2*pi/N + 2*pi)*n);

subplot(2,1,1), stem(n,x1,'filled'), yticks([-1,0,1]), ylabel('x_1[n]')
subplot(2,1,2), stem(n,x2,'filled'), yticks([-1,0,1])
xlabel('n'), ylabel('x_2[n]')

Alias-free frequencies

  • The only frequencies that lead to unique (distinct) sinusoids lie in an interval of length $2\pi$

  • Two intervals are typically used in the signal processing

$$ \begin{align*} 0 \leq & \; \omega < 2\pi \\ -\pi < & \; \omega \leq \pi \end{align*}$$
In [15]:
%plot -s 560,600

N = 8;
n = 0:N-1;

xn1 = cos(pi*n);
xn2 = cos(3/2*pi*n);

t = 0:0.1:N-1;

x1 = cos(pi*t);
x2 = cos(3/2*pi*t);
x3 = cos(1/2*pi*t);

subplot(3,1,1), 
stem(n,xn1,'filled'), hold on
plot(t,x1,'--','color',[0, 0.4470, 0.7410]), hold off
axis([0,7,-1.5 1.5])
ylabel('x_1[n]', 'fontsize', 12)

subplot(3,1,2), 
stem(n,xn2,'filled'), hold on
plot(t,x2,'--','color',[0, 0.4470, 0.7410]), hold off
axis([0,7,-1.5 1.5])
ylabel('x_2[n]', 'fontsize', 12)

subplot(3,1,3), 
stem(n,xn2,'filled'), hold on
plot(t,x2,'--','color',[0, 0.4470, 0.7410])
plot(t,x3,'color','r'), hold off
axis([0,7,-1.5 1.5])
ylabel('x_2[n]', 'fontsize', 12)

6.2. Low and High Frequencies


$$e^{j(\omega n + \phi)}$$
  • Low frequencies: $\omega$ closed to $0$ and $2\pi$, (here $\omega = \frac{ 2 \pi \cdot 1}{20} = \frac{2\pi}{20}$)



  • High frequencies: $\omega$ closed to $\pi$ and $-\pi$, (here $\omega = \frac{2 \pi \cdot 9}{20} = \frac{18\pi}{20}$)



Key question: which one is a higher frequency?

$$\omega_0 = \pi ~~~ \text{or} ~~~ \omega_0 = \frac{3\pi}{2}$$
In [16]:
%plot -s 560,400

N = 8;
n = 0:N-1;

x1 = cos(pi*n);
x2 = cos(3/2*pi*n);

subplot(2,1,1), stem(n,x1,'filled'), axis([0,7,-1.5 1.5]), ylabel('x_1')
subplot(2,1,2), stem(n,x2,'filled'), axis([0,7,-1.5 1.5]), ylabel('x_2')

6.3. Frequency in Discrete Sinusoids


$$0 \; \rightarrow \; \frac{1}{8}\pi \; \rightarrow \; \frac{2}{8}\pi \; \rightarrow \; \frac{8}{8}\pi$$
In [17]:
%plot -s 560,600

N = 32;
n = 0:N-1;
x1 = cos(0*pi*n);
x2 = cos(1/8*pi*n);
x3 = cos(2/8*pi*n);
x4 = cos(1*pi*n);

subplot(4,1,1), stem(n,x1,'filled'), axis([0,31,-1.5 1.5])
subplot(4,1,2), stem(n,x2,'filled'), axis([0,31,-1.5 1.5])
subplot(4,1,3), stem(n,x3,'filled'), axis([0,31,-1.5 1.5])
subplot(4,1,4), stem(n,x4,'filled'), axis([0,31,-1.5 1.5])

$$2\pi \; \rightarrow \; \frac{15}{8}\pi \; \rightarrow \; \frac{14}{8}\pi \; \rightarrow \; \frac{8}{8}\pi$$
In [18]:
%plot -s 560,600

N = 32;
n = 0:N-1;
x5 = cos(2*pi*n);
x6 = cos(15/8*pi*n);
x7 = cos(14/8*pi*n);
x8 = cos(1*pi*n);

subplot(4,1,1), stem(n,x5,'filled'), axis([0,31,-1.5 1.5])
subplot(4,1,2), stem(n,x6,'filled'), axis([0,31,-1.5 1.5])
subplot(4,1,3), stem(n,x7,'filled'), axis([0,31,-1.5 1.5])
subplot(4,1,4), stem(n,x8,'filled'), axis([0,31,-1.5 1.5])

6.4. Aliasing

In [19]:
%plot -s 560,400

t = linspace(0,10*2*pi,100);
x = sin(t);
y = cos(t);

ts = linspace(0,10*2*pi,10);
xs = sin(ts);
ys = cos(ts);

tc = linspace(0,10*2*pi,100);
xc = sin(1/10*tc);
yc = cos(1/10*tc);

subplot(2,1,1), plot(t,x,'--'), hold on
plot(ts,xs,'o','markerfacecolor','r'), 
plot(tc,xc,'r-'), hold off
title('sin(t)')
yticks([-1,0,1])
xlim([0,10*2*pi])
subplot(2,1,2), plot(t,y,'--'), hold on
plot(ts,ys,'o','markerfacecolor','red'), 
plot(tc,yc,'r'), hold off
xlabel('sec'), title('cos(t)')
yticks([-1,0,1])
xlim([0,10*2*pi])

In [20]:
%plot -s 560,400

t = linspace(0,10*2*pi,100);
x = sin(t);
y = cos(t);

ts = linspace(0,10*2*pi,5);
xs = sin(ts);
ys = cos(ts);

tc = linspace(0,10*2*pi,100);
xc = sin(1/5*tc);
yc = cos(1/5*tc);

subplot(2,1,1), plot(t,x,'--'), hold on
plot(ts,xs,'o','markerfacecolor','r'), 
plot(tc,xc,'r-'), hold off
title('sin(t)')
yticks([-1,0,1])
xlim([0,10*2*pi])
subplot(2,1,2), plot(t,y,'--'), hold on
plot(ts,ys,'o','markerfacecolor','red'), 
plot(tc,yc,'r'), hold off
xlabel('sec'), title('cos(t)')
yticks([-1,0,1])
xlim([0,10*2*pi])

In [21]:
%%html
<center><iframe 
width="560" height="315" src="https://www.youtube.com/embed/jHS9JGkEOmA?rel=0" frameborder="0" allowfullscreen>
</iframe></center>

7. Signal Visualization

Periodicity of Sinusoids

  • Consider $x_1[n] = e^{j(\omega n + \phi)}$ with frequency $\omega = \frac{2\pi k}{N}$ (harmonic frequency)
  • It is easy to show that $x_1$ is periodic with period $N$
$$x_n[n+N] = e^{j(\omega (n+N) + \phi)} = e^{j(\omega n + \omega N+ \phi)}= e^{j(\omega n + \phi)}e^{j(\omega N)}= e^{j(\omega n + \phi)}e^{j(\frac{2\pi k}{N} N)} = x_1[n]$$

Harmonic Sinusoids

$$e^{j(\omega n + \phi)}$$
  • Semi-amazing fact: The only periodic discrete-time sinusoids are those with harmonic frequencies
$$\omega = \frac{2\pi k}{N}$$
  • The harmonic sinusoids are somehow magical (they play a starring role later in the DFT)

7.1. Visualize the Harmonic Sinusoidals


$$x[n] = e^{j \omega n }, \qquad \omega = \frac{2 \pi}{N}k$$
In [22]:
%plot -s 560,420

N = 8;
k = 1;
w = 2*pi/N*k;
z1 = exp(1j*w);

n = 0:N-1;
z = (z1.^n).';

zplane(z)
title(['$z~{\rm in~the~complex~plane}$'],'interpreter','LaTeX','fontsize',12);

In [23]:
%plot -s 560,420

k = 3;

N = 8;
n = 0:N-1;

xp = exp(1j*2*pi/N*k*n);
x = exp(1j*2*pi/N*k*0);

plot(real(xp),imag(xp),'o'), hold on
plot(real(x),imag(x),'o', 'MarkerFaceColor','b', 'MarkerEdgeColor','b'), hold off
grid on
axis equal; axis([-1.5, 1.5,-1.4 1.4])

In [24]:
%plot -s 560,420

x = exp(1j*2*pi/N*k*1);

plot(real(xp),imag(xp),'o'), hold on
plot(real(x),imag(x),'o', 'MarkerFaceColor','b', 'MarkerEdgeColor','b'), hold off
grid on
axis equal; axis([-1.5, 1.5,-1.4 1.4])

In [25]:
%plot -s 560,420

x = exp(1j*2*pi/N*k*2);

plot(real(xp),imag(xp),'o'), hold on
plot(real(x),imag(x),'o', 'MarkerFaceColor','b', 'MarkerEdgeColor','b'), hold off
grid on
axis equal; axis([-1.5, 1.5,-1.4 1.4])

In [26]:
%plot -s 560,420

x = exp(1j*2*pi/N*k*3);

plot(real(xp),imag(xp),'o'), hold on
plot(real(x),imag(x),'o', 'MarkerFaceColor','b', 'MarkerEdgeColor','b'), hold off
grid on
axis equal; axis([-1.5, 1.5,-1.4 1.4])

In [27]:
%plot -s 560,420

x = exp(1j*2*pi/N*k*4);

plot(real(xp),imag(xp),'o'), hold on
plot(real(x),imag(x),'o', 'MarkerFaceColor','b', 'MarkerEdgeColor','b'), hold off
grid on
axis equal; axis([-1.5, 1.5,-1.4 1.4])

In [28]:
%plot -s 560,420

x = exp(1j*2*pi/N*k*5);

plot(real(xp),imag(xp),'o'), hold on
plot(real(x),imag(x),'o', 'MarkerFaceColor','b', 'MarkerEdgeColor','b'), hold off
grid on
axis equal; axis([-1.5, 1.5,-1.4 1.4])

In [29]:
%plot -s 560,420

x = exp(1j*2*pi/N*k*6);

plot(real(xp),imag(xp),'o'), hold on
plot(real(x),imag(x),'o', 'MarkerFaceColor','b', 'MarkerEdgeColor','b'), hold off
grid on
axis equal; axis([-1.5, 1.5,-1.4 1.4])

In [30]:
%plot -s 560,420

x = exp(1j*2*pi/N*k*7);

plot(real(xp),imag(xp),'o'), hold on
plot(real(x),imag(x),'o', 'MarkerFaceColor','b', 'MarkerEdgeColor','b'), hold off
grid on
axis equal; axis([-1.5, 1.5,-1.4 1.4])

7.2. Visual Matrix of Harmonic Sinusoids


$$x[n] = e^{j \omega n }, \qquad \omega = \frac{2 \pi}{N}k$$
In [31]:
%plot -s 800,600

N = 8;
n = 0:N-1;

for k = 0:N-1;
    x = exp(1j*(2*pi/N)*k*n);
    
    subplot(8,2,2*k+1)
    stem(n,real(x),'b','filled'); 
    xticks([])
    ylabel(['k = ',num2str(k)],'fontsize',10);
    axis([0, 7, -1, 1]);
    
    subplot(8,2,2*k+2)
    stem(n,imag(x),'r','filled'); 
    xticks([])
    axis([0, 7, -1, 1]);
end

subplot(821)
title(['${\rm Re}(e^{j \frac{2\pi}{8}kn}) = \cos(\frac{2\' ...
       'pi}{8}kn)$'],'interpreter','LaTeX','fontsize',12);

subplot(822)
title(['${\rm Im}(e^{j \frac{2\pi}{8}kn}) = \sin(\frac{2\' ...
       'pi}{8}kn)$'],'interpreter','LaTeX','fontsize',12);
       
subplot(8,2,15), xticks([0,1,2,3,4,5,6,7]), xlabel('n')       
subplot(8,2,16), xticks([0,1,2,3,4,5,6,7]), xlabel('n')

In [32]:
%plot -s 900,400

N = 8;
n = 0:N-1;
for k = 0:N-1
    D(:,k+1) = exp(1j*(2*pi/N)*k*n).';
end

subplot(121), imagesc(n,n,real(D)), colormap('jet'), axis square
xlabel('$k$','interpreter','LaTeX','fontsize',12);
ylabel('$n$','interpreter','LaTeX','fontsize',12);
title('${\rm Re}(e^{j\frac{2\pi}{N}kn})=\cos(\frac{2\pi}{N}kn)$',...
'interpreter','LaTeX','fontsize',12);
colorbar

subplot(122), imagesc(n,n,imag(D)), colormap('jet'), axis square
xlabel('$k$','interpreter','LaTeX','fontsize',12);
ylabel('$n$','interpreter','LaTeX','fontsize',12);
title('${\rm Im}(e^{j\frac{2\pi}{N}kn})=\sin(\frac{2\pi}{N}kn)$',...
'interpreter','LaTeX','fontsize',12);
colorbar

8. Complex Exponential Signals with Damping


  • Consider the general complex number $z = \lvert z\rvert e^{j\omega}, \quad z \in \mathbb{C}$
    • $\lvert z\rvert = $ magnitude of $z$
    • $\omega = \angle z$, phase angle of $z$
    • Can visualize $z \in \mathbb{C}$ as a point in the complex plane
  • Complex exponential is a spiral

    $$z^n = \left( \lvert z\rvert e^{j\omega}\right)^n = \lvert z\rvert^n e^{j\omega n}$$
    • $\lvert z\rvert^n$ is a real exponential envelope
    • $e^{j\omega n}$ is a complex sinusoid
    • $z^n$ is a helix
In [33]:
%%html
<center><iframe src="https://www.youtube.com/embed/vDulP6vTa9g?rel=0" 
width="560" height="315" frameborder="0" allowfullscreen></iframe></center>



$$x[n]=\gamma^n e^{j\frac{2\pi}{N} n}$$

In [34]:
%% real and imag parts

r = 0.95;
N = 20;
n = 0:2*N-1;
x = (r.^n).*exp(1j*2*pi/N*n);

1) retangular form

In [35]:
%plot -s 560,400

subplot(2,1,1)
stem(n,real(x),'filled'), hold on
plot(n, [1;-1]*r.^n,'k--'), hold off
ylabel('Re')

subplot(2,1,2)
stem(n,imag(x),'filled'), hold on
plot(n, [1;-1]*r.^n,'k--'), hold off
ylabel('Im'), xlabel('n')

In [36]:
%plot -s 560,520

c = [0, 0.4470, 0.7410];

plot3(n,real(x),imag(x),'o','MarkerFaceColor',c,'MarkerEdgeColor',c), hold on
plot3(n,zeros(size(n)),zeros(size(n)),'k--'), hold off
xlabel('n'), ylabel('Re'), zlabel('Im')
grid on
ylim([-1,1])
zlim([-1,1])
view([20,30])

2) polar form

$$ \begin{align*} x[n] &=\gamma^n e^{j\frac{2\pi}{N} n}\\ &= \lvert x[n]\lvert \, e^{j\angle x[n]} \end{align*} $$
In [37]:
%% polar coordinate

fig = polar(angle(x),abs(x),'o');      % theta in radian
set(fig,'MarkerFaceColor',[0, 0.4470, 0.7410],'MarkerEdgeColor',[0, 0.4470, 0.7410]);

In [38]:
%% polar coordinate

subplot(3,1,1)
stem(n,abs(x),'filled')
ylabel('|x[n]|','fontsize',12)

subplot(3,1,2)
stem(n,phase(x),'filled')
ylabel('\angle x[n] in phase','fontsize',12)

subplot(3,1,3)
stem(n,angle(x),'filled')
ylabel('\angle x[n] in angle','fontsize',12), xlabel('n')

9. Signals are Vectors

  • Vectors in $\mathbb{R}^N$ or $\mathbb{C}^N$
$$x=\begin{bmatrix} x[0] \\ x[1] \\ \vdots \\ x[N-1]\end{bmatrix}$$

9.1. Transpose of a Vector

  • the transpose operation $T$ converts a column vector to a row vector (and vice versa)


$$x=\begin{bmatrix} x[0] \\ x[1] \\ \vdots \\ x[N-1]\end{bmatrix}^T = \begin{bmatrix}x[0] & x[1] & \cdots & x[N-1]\end{bmatrix}$$


  • In addition to transposition, the conjugate transpose (aka Hermitian transpose) operation H takes the complex conjugate


$$x=\begin{bmatrix} x[0] \\ x[1] \\ \vdots \\ x[N-1]\end{bmatrix}^H = \begin{bmatrix}x[0]^* & x[1]^* & \cdots & x[N-1]^*\end{bmatrix}$$
In [39]:
% be careful with ' in MATLAB

a = [2 + 1j, 1 - 2j];
a'
a.'
ans =

   2.0000 - 1.0000i
   1.0000 + 2.0000i


ans =

   2.0000 + 1.0000i
   1.0000 - 2.0000i


9.2. Matrix Multiplication as Linear Combination

Linear Combination = Matrix Multiplication

  • Given a collection of $M$ vectors $x_0, x_1, \cdots, x_{M-1}$ and $M$ scalars $\alpha_0, \alpha_1, \cdots, \alpha_{M-1}$, the linear combination of the vectors is given by


$$y=\alpha_0 x_0 + \alpha_1 x_1 + \cdots + \alpha_{M-1}x_{M-1} = \sum_{m=0}^{M-1}\alpha_m x_m$$


  • Step 1: stack the vectors $x_m$ as column vectors into an $N \times M$ matrix


$$X = [x_0 \mid x_1 \mid \cdots \mid x_{M-1}]$$


  • Step 2: stack the scalars $\alpha_m$ into an $M \times 1$ column vector


$$\alpha = \begin{bmatrix}\alpha_0 \\ \alpha_1 \\ \vdots \\\alpha_{M-1} \end{bmatrix}$$


  • Step 3: we can now write a linear combination as the matrix/vector product


$$y=\alpha_0 x_0 + \alpha_1 x_1 + \cdots + \alpha_{M-1}x_{M-1} = \sum_{m=0}^{M-1}\alpha_m x_m = [x_0 \mid x_1 \mid \cdots \mid x_{M-1}] \begin{bmatrix}\alpha_0 \\ \alpha_1 \\ \vdots \\\alpha_{M-1} \end{bmatrix} = X \alpha$$


  • Note: the row-$n$, column-$m$ element of the matrix $[X]_{n,m} = x_m[n]$

9.3. Inner Product

  • The inner product (or dot product) between two vectors $x, y \in \mathbb{C}^N$ is given by


$$\langle x, y \rangle = y^H x = \sum_{n=0}^{N-1} x[n]y[n]^*$$


  • The inner product takes two signals (vectors in $\mathbb{C}^N$) and produces a single (complex) number
  • Inner product of a signal with itself


$$\langle x,x \rangle = \sum \limits_{n=0}^{N-1} x[n]\, x[n]^* = \sum \limits_{n=0}^{N-1}{\lvert x[n] \rvert}^2 = \lVert x \rVert_2^2$$


  • Two vectors $x,y \in \mathbb{C}^N$ are orthogonal if


$$\langle x,y \rangle = 0$$


  • Two sets of orthogonal signals



9.4. Harmonic Sinusoids are Orthogonal


$$d_k[n] = e^{j{2\pi k \over N}n}, \quad n, k, N \in \mathbb{Z}, 0 \leq n \leq N - 1, 0 \leq k \leq N - 1 $$


  • Claim : $\langle d_k , d_l \rangle = 0, \quad k \neq l$


$$ \begin{align*} \langle d_k , d_l \rangle &= \sum\limits^{N-1}_{n=0}d_k[n]d^*_l[n] = \sum\limits^{N-1}_{n=0} e^{j{2\pi k \over N}n}\left(e^{j{2 \pi l \over N}n}\right)^* = \sum\limits^{N-1}_{n=0} e^{j{2\pi k \over N}n}e^{-j{2 \pi l \over N}n} \\\\ &= \sum\limits^{N-1}_{n=0}e^{j{2\pi \over N}(k-l)n} \quad \text{let } r = k - l \in \mathbb{Z}, r \neq 0 \\\\ &= \sum\limits^{N-1}_{n=0}e^{j{2\pi \over N} rn} = \sum\limits^{N-1}_{n=0} a^n \quad \text{with }\; a = e^{j{2\pi \over N}r}, \text{then use} \sum\limits^{N-1}_{n=0} a^n = {1-a^N \over 1-a} \\\\ &= {1 - e^{j{2\pi rN \over N}} \over 1 - e^{j{2\pi r \over N}}} = 0 \end{align*} $$
In [40]:
%plot -s 560,400

N = 32;
n = 0:N-1;

k = 1;
d1 = cos(2*pi/N*k*n)';

k = 2;
d2 = cos(2*pi/N*k*n)';

subplot(211)
stem(n,d1,'filled'), ylabel('d_1[n]'), axis tight
subplot(212)
stem(n,d2,'filled'), ylabel('d_2[n]'), axis tight

% Note: in Matlab, the operation ' performs complex conjugate transpose
innerproduct = d2'*d1
innerproduct =

  -2.2572e-15


In [41]:
%plot -s 560,400

N = 32;
n = 0:N-1;

k = 1;
d1 = exp(1j*2*pi/N*k*n).';

k = 3;
d2 = exp(1j*2*pi/N*k*n).';

subplot(211)
stem(n,real(d1),'b','marker','none'); hold on, ylabel('d_1[n]')
stem(n,imag(d1),'r','marker','none'); hold off
title('Real part = Blue, Imaginary part = Red','fontsize',10)

subplot(212)
stem(n,real(d2),'b','marker','none'); hold on, ylabel('d_2[n]')
stem(n,imag(d2),'r','marker','none'); hold off

% Note: in Matlab, the operation ' performs complex conjugate transpose
innerproduct = d2'*d1
innerproduct =

  -1.8965e-15 + 8.7512e-16i


$$d_k[n] = \frac{1}{\sqrt{N}} e^{j{2\pi k \over N}n}$$
In [42]:
% to check two complex signals are orthonormal

N = 16;
n = 0:N-1;

k = 3;
s_3 = 1/sqrt(N)*exp(1j*2*pi/N*k*n).';

k = 5;
s_5 = 1/sqrt(N)*exp(1j*2*pi/N*k*n).';

% ': complex conjugate transpose
s_3'*s_5    % to see they are orthogonal
s_3'*s_3    % to see it is normalized
s_5'*s_5    % to see it is normalized
ans =

  -4.1633e-16 + 8.1780e-17i


ans =

     1


ans =

     1


9.5. Matrix Multiplication as a Sequence of Inner Products of Rows

  • Consider the matrix multiplication $y = X\alpha$
  • The row-$n$, column-$m$ element of the matrix $[X]_{n,m} = x_m[n]$
  • We can compute each element $y[n]$ in $y$ as the inner product of the $n$-th row of $X$ with the vector $\alpha$


$$y= \begin{bmatrix} \vdots \\ y[n] \\ \vdots \end{bmatrix} = \begin{bmatrix} \vdots & \vdots && \vdots\\x_0[n] & x_1[n] & \cdots & x_{M-1}[n]\\\vdots & \vdots && \vdots\end{bmatrix} \begin{bmatrix}\alpha_0 \\ \alpha_1 \\ \vdots \\\alpha_{M-1} \end{bmatrix} = X \alpha$$


  • Can write $y[n]$


$$y[n]= \sum_{m=0}^{M-1}\alpha_m x_m[n] = \langle \text{row} \; n \;\text{of}\; X, \alpha \rangle$$
In [43]:
%%javascript
$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')