Discrete Signal Processing (DSP):
Discrete Signals
Table of Contents
A discrete-time signal is a function defined over an integer-valued independent variable. We denote such a signal as:
That is, the independent variable $n$ takes values in the set of integers $\mathbb{Z}$, and the signal value $x[n]$ is a real or complex number.
In MATLAB, different functions are used to visualize continuous-time and discrete-time signals:
Continuous-Time Signals: Use the plot
function to display continuous waveforms. This function connects data points with lines to approximate the appearance of a continuous signal.
Discrete-Time Signals: Use the stem
function to display discrete signals. This function emphasizes the fact that the signal is only defined at integer time indices.
MATLAB Code
%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)');
%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])
In practice, most physical signals are of finite duration, although infinite-length signals are often used in theory and analysis.
A discrete-time signal $x[n]$ is said to be periodic with period $N \in \mathbb{Z}^+$ if it satisfies the following condition for all $n \in \mathbb{Z}$ and all integers $m$:
That is, the signal repeats itself every $N$ samples. Note the following important points:
Infinite-length and finite-length signals can be converted into one another through windowing and extension:
Windowing (Truncation): An infinite-length signal $x[n]$ can be truncated to a finite-length signal $y[n]$ as follows:
Extension by Zero-Padding: A finite-length signal can be extended to infinite length by zero-padding:
Extension by Periodization: Alternatively, a finite-length signal can be periodically extended to infinite length:
This operation is referred to as periodization and is central to the analysis of discrete Fourier transforms.
Modular Arithmetic
Modular arithmetic with modulus $N$ effectively wraps the number line into a circular structure with $N$ distinct values:
This arithmetic is inherently periodic and forms the basis for circular operations on signals.
Periodization Using Modular Indexing
Let $x[n]$ be defined for $0 \leq n < N$. Then the periodic extension of $x[n]$ with period $N$ can be written compactly as:
This expresses the idea that periodic signals live on a circle, in contrast to infinite-length signals which live on the infinite integer line.
%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')
%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')
Finite-length and periodic signals are conceptually distinct, yet closely related:
Shifting Infinite-Length Signals
Given an infinite-length signal $x[n]$, a shift by $m$ samples is defined as:
Shifting Periodic Signals
For a periodic signal $x[n]$ with period $N$, the shift operation must use modular arithmetic:
This is known as a circular shift by $m$ samples.
Shifting Finite-Length Signals
Consider two finite-length signals $x[n]$ and $y[n]$ defined for $0 \leq n < N$, and define:
This operation leads to ambiguity at the boundaries:
To avoid information loss or invention, we assume that both signals are periodic with period $N$, leading to:
This defines a circular shift in the finite-length context.
Circular Time Reversal
For a periodic signal $x[n]$ of period $N$, the circular time reversal is defined as:
For example, with $N = 8$, the reversal yields:
This operation mirrors the signal around index $n = 0$ on a periodic domain.
This section introduces fundamental discrete-time signals that are widely used in analysis, modeling, and implementation of digital systems.
The unit impulse or delta function is defined as:
(MATLAB)
Delta function: $\delta[n]$
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];
The delta function acts as a sampling operator. It isolates individual values from a signal.
Sampling Property:
Let $x[n]$ be a discrete-time signal. Then:
This identity expresses a fundamental property:
The product $x[n] \delta[n - m]$ is nonzero only when $n = m$.
At $n = m$, the value of the output is $x[m]$.
Here, $x[m]$ is a constant scalar, and not a function of $n$.
This operation effectively picks out the value of $x[n]$ at index $n = m$ while setting all other values to zero.
MATLAB code: A signal composed of delta functions:
%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]');
The unit step function is defined as:
Gating a Signal:
The product of a signal and a unit step function truncates part of the signal:
This sets all values of $x[n]$ to zero for $n < m$
(MATLAB)
Step function: $u[n]$
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];
Examples:
%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]')
A real exponential signal is defined as:
The shape of the signal depends on the value of $a$:
Discrete-time sinusoids are typically of the form:
where:
Example
The frequency $\omega$ controls the rate of oscillation:
Example:
The phase $\phi$ introduces a horizontal shift in the sinusoid
Example
The following functions are commonly used to manipulate discrete-time signals in a modular and reusable way:
sigshift(x, m, n0)
Time-shifts the signal $x[n]$ by $n_0$ samples
Input:
x: Signal samples
m: Time indices corresponding to x
n0: Shift amount (positive for delay, negative for advance)
Output: Shifted signal and its new time indices
function [y,n] = sigshift(x,m,n0)
% implements y(n) = x(n-n0)
% [y,n] = sigshift(x,m,n0)
n = m + n0;
y = x;
sigfold(x, n)
This operation reflects the signal about the vertical axis at $n = 0$.
function [y, n_folded] = sigfold(x, n)
%SIGFOLD Time-reverses a discrete-time signal
% [y, n_folded] = sigfold(x, n) reflects the signal x(n) about n = 0
% such that y(n) = x(-n)
%
% Inputs:
% x - input signal vector
% n - time index vector corresponding to x
%
% Outputs:
% y - time-reversed signal
% n_folded - time index vector for y
y = fliplr(x); % reverse signal values
n_folded = -fliplr(n); % reverse and negate time indices
end
sigadd(x1, n1, x2, n2)
Works even when signals are defined over different ranges.
Properly aligns the signals to a common index vector before summing.
function [y, n] = sigadd(x1, n1, x2, n2)
%SIGADD Adds two discrete-time signals with possibly different index ranges
%
% [y, n] = sigadd(x1, n1, x2, n2) computes the sum y(n) = x1(n) + x2(n)
% over the union of the index ranges n1 and n2.
%
% Inputs:
% x1, n1 - first signal and its time indices
% x2, n2 - second signal and its time indices
%
% Outputs:
% y - resulting summed signal
% n - time index vector corresponding to y
% Determine the full range of output indices
n_start = min([min(n1), min(n2)]);
n_end = max([max(n1), max(n2)]);
n = n_start:n_end;
% Initialize zero-padded signals
y1 = zeros(1, length(n));
y2 = zeros(1, length(n));
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
sigmult(x1, n1, x2, n2)
where the two signals are first aligned to a common time index vector, zero-padded if needed, and then multiplied element by element.
function [y, n] = sigmult(x1, n1, x2, n2)
%SIGMULT Multiplies two discrete-time signals with possibly different index ranges
%
% [y, n] = sigmult(x1, n1, x2, n2) computes the pointwise product
% y(n) = x1(n) * x2(n) over the union of the index ranges n1 and n2.
%
% Inputs:
% x1, n1 - first signal and its time indices
% x2, n2 - second signal and its time indices
%
% Outputs:
% y - resulting product signal
% n - time index vector corresponding to y
% Define the full range of time indices
n_start = min([min(n1), min(n2)]);
n_end = max([max(n1), max(n2)]);
n = n_start:n_end;
% Initialize zero-padded signals
y1 = zeros(1, length(n));
y2 = zeros(1, length(n));
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
(MATLAB) Example
%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)')
(MATLAB) Example
%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)')
In discrete-time signal processing, time-reversal and shifting are two fundamental operations. Combinations like $x[-n + k]$ can be understood by decomposing the operations step-by-step.
Original Signal
Let the signal $x[n]$ be defined as:
This means:
%plot -s 560,200
N = 7;
x = [0 1 2 3 0 0 0];
n = 0:N-1;
stem(n,x,'filled')
Time Reversal
This operation reflects the signal around $n = 0$. The time indices are reversed:
%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])
Time Shift
This shifts the signal to the right by 2 samples (delay):
%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])
Combined Reversal and Shift
(1) A right shift by $k$ followed by a time-reversal
(2) A time-reversal followed by a right shift by $k$
(MATLAB) Example
%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])
A complex number can be expressed in rectangular form as:
Addition
Addition of complex numbers is performed component-wise:
Multiplication and Division
When written in polar form, complex numbers take the form:
Their product and quotient are given by:
Euler’s Formula
A fundamental identity that connects exponential and trigonometric functions is Euler’s formula:
Using Euler’s formula, any complex number can be expressed as:
where:
Signal Representations in $\mathbb{C}$
When the signal $x[n]$ is complex-valued ($x[n] \in \mathbb{C}$), it can be expressed in two equivalent forms:
Rectangular form:
$$ x[n] = \text{Re}\{x[n]\} + j\,\text{Im}\{x[n]\} $$Polar form:
$$ x[n] = |x[n]| e^{j \angle x[n]} $$These two views give complementary insights:
Example for $e^{j \omega t}$
The complex exponential $e^{i\theta}$ has a clear geometric meaning:
This expression represents a point on the unit circle in the complex plane, located at an angle $\theta$ (radians) measured counterclockwise from the positive real axis.
Rotation in Time
Let $\theta = \omega t$, where $\omega$ is angular frequency (in radians per second) and $t$ is time. Then:
represents a point that rotates counterclockwise on the unit circle with angular velocity $\omega$.
Direction of Rotation: $e^{-i\omega t}$
The negative exponent $e^{-i\omega t}$ has a similar form:
This corresponds to clockwise rotation on the unit circle with angular velocity $\omega$.
If $\omega > 0$:
Thus, the sign of $\omega$ determines both the speed and the direction of rotation.
A complex exponential traces out a helix in time. When plotted in the complex plane, the signal:
corresponds to a circular motion with constant angular velocity. The real and imaginary parts give sinusoidal signals:
From Euler's formula, we can express real-valued sinusoids using complex exponentials:
Similarly:
These identities allow us to express real signals as linear combinations of complex exponentials, which is fundamental in Fourier analysis.
A discrete-time sinusoid is a function of the form:
or equivalently,
where:
In many applications, the frequency is expressed as:
for some integer $k$, especially when working with signals of length $N$.
Let us consider two complex sinusoids with different angular frequencies:
Note that $e^{j 2\pi n} = 1$ for all integer $n$. Therefore:
Thus, even though $\omega$ and $\omega + 2\pi$ are different, the signals $x_1[n]$ and $x_2[n]$ are identical. This is called aliasing.
% 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
Therefore, we only need to consider a fundamental frequency interval of length $2\pi$
Common choices for the alias-free frequency interval:
Any frequency outside this interval is an alias of one within it.
%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_3[n]', 'fontsize', 12)
Consider the discrete complex sinusoid:
Note: The maximum frequency in discrete-time signals occurs when
This corresponds to the fastest possible oscillation in a discrete signal, where the samples alternate every step:
Frequencies beyond $\pi$ radians/sample are aliases of frequencies within the interval $[-\pi, \pi]$ due to the $2\pi$-periodicity of discrete-time sinusoids.
Example:
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 signal has higher frequency?
Check which one oscillates faster.
m%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')
As $\omega$ increases:
The signal completes more cycles in the same number of samples.
Oscillation rate increases.
%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])
As $\omega$ decreases from $2\pi$ to $\pi$, the sinusoids become higher in frequency because their aliased equivalents approach $-\pi$.
%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])
In discrete-time signal processing, aliasing is the phenomenon where distinct continuous-time frequencies become indistinguishable after sampling. This is due to the periodic nature of complex exponentials in the discrete-time domain.
If you continue increasing frequency beyond $\pi$, the waveform begins to slow down, as it wraps back around due to periodicity.
%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])
%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])
The wagon wheel effect refers to the phenomenon where a wheel (e.g., on a wagon or car) appears to rotate slowly, stand still, or even spin backwards when filmed or viewed under discrete sampling.
from IPython.display import YouTubeVideo
YouTubeVideo('jHS9JGkEOmA', width = "560", height = "315")
Harmonic Sinusoids
The harmonic sinusoids are complex exponentials of the form:
where:
These sinusoids are called harmonic because their frequencies are integer multiples of a fundamental frequency:
Periodicity of Harmonic Sinusoids
Let
This is a harmonic sinusoid, where:
We can show that $x[n]$ is periodic with period $N$:
Since $e^{j\cdot 2\pi k} = 1$, the signal repeats every $N$ samples.
%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);
%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])
%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])
%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])
%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])
%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])
%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])
%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])
%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])
%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')
Matrix Visualization of Harmonic Sinusoids
We define a time-frequency matrix of size $N \times N$:
where:
%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
A natural generalization of the complex exponential signal is to consider exponentials of the form $z^n$, where the base $z$ is a complex number. Let:
This is the polar form of a complex number, where:
The complex number $z$ can be interpreted geometrically as a point or vector in the complex plane with polar coordinates $(|z|, \omega)$.
When a complex number $z$ is raised to an integer power $n$, the result is:
This separates naturally into two components:
Spiral Behavior
The signal $z^n = |z|^n e^{j\omega n}$ traces a spiral trajectory in the complex plane:
This structure is often referred to as a damped (or growing) complex sinusoid.
Note that the phase angle increases linearly with $n$, since:
Hence, the term $e^{j\omega n}$ traces a circle (or rotates) with constant angular velocity $\omega$.
from IPython.display import YouTubeVideo
YouTubeVideo('vDulP6vTa9g', width = "560", height = "315")
$$x[n]=\gamma^n e^{j\frac{2\pi}{N} n}$$
%% 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
%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')
%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*} $$%% 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]);
%% 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')
Discrete-time signals of finite length can be naturally represented as vectors in a vector space.
Let $x[n]$ be a signal defined for $n = 0, 1, \dots, N-1$. Then the vector representation of $x[n]$ is:
In linear algebra, we frequently use transposition and conjugate transposition when working with vectors and matrices.
Transpose (denoted by $T$)
The transpose of a column vector is a row vector:
This operation does not affect the numerical values—it only changes the shape (orientation) of the vector.
Conjugate Transpose (denoted by $H$)
Also known as the Hermitian transpose, this operation both transposes the vector and applies the complex conjugate to each element:
This is especially important when working in $\mathbb{C}^N$, as inner products and orthogonality are defined using conjugate transposition.
% be careful with ' in MATLAB
a = [2 + 1j, 1 - 2j];
a'
a.'
Matrix-vector multiplication can be interpreted as a linear combination of vectors.
Let:
Then the linear combination of the vectors is:
Step-by-Step: Representing as Matrix Multiplication
Step 1: Form a matrix by stacking the vectors
Let $X$ be the $N \times M$ matrix whose columns are the vectors $x_m$:
Each column of $X$ is one of the vectors being combined.
Step 2: Stack the scalar weights into a column vector
Let $\alpha$ be the $M \times 1$ vector of coefficients:
Step 3: Matrix-vector product expresses the linear combination
This result $y \in \mathbb{R}^N$ (or $\mathbb{C}^N$) is a linear combination of the columns of $X$, weighted by the entries of $\alpha$.
The inner product (also called the dot product) is a fundamental operation for comparing two vectors. For discrete-time signals interpreted as vectors in $\mathbb{C}^N$, the inner product is defined as:
Here, $y^H$ denotes the conjugate transpose of $y$, and $x[n], y[n]^*$ multiplies the $n$-th entry of $x$ by the complex conjugate of the $n$-th entry of $y$.
The inner product takes two signals and returns a single complex number. It quantifies both alignment and magnitude similarity between the signals.
Inner Product with Itself
When a signal is compared with itself, the result is the sum of squared magnitudes:
This is the squared $\ell_2$ norm (Euclidean energy) of the signal.
Orthogonality
Two signals $x, y \in \mathbb{C}^N$ are said to be orthogonal if their inner product is zero:
Orthogonality means the signals are completely uncorrelated in the vector space sense. This concept is foundational in constructing orthonormal bases, such as those used in the discrete Fourier transform.
Example: Two sets of orthogonal signals
Consider the set of discrete complex exponentials (harmonic sinusoids) defined by
where $k$, $n$, and $N$ are integers.
We claim that these harmonic sinusoids are mutually orthogonal over $n = 0, 1, \cdots, N-1$. That is,
This can be shown as follows:
Let $r = k - l \in \mathbb{Z}$. For $r \ne 0$, define $a = e^{j\frac{2\pi}{N}r}$, and observe that $a \ne 1$. Then:
Since $a^N = e^{j2\pi r} = 1$, the numerator becomes zero, and we have:
This confirms that the harmonic sinusoids ${d_k[n]}$ form an orthogonal set over $n = 0, \cdots, N-1$.
This property underpins many results in Fourier analysis and digital signal processing, especially in the context of the Discrete Fourier Transform (DFT).
%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
%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
% 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
Let $X$ be an $N \times M$ matrix and $\alpha$ an $M \times 1$ column vector. The product
produces an $N \times 1$ output vector $y$.
Each entry $y[n]$ in the result can be interpreted as the inner product of the $n$-th row of $X$ with the vector $\alpha$.
The matrix $X$ can be written as
where the $n$-th row consists of the values $x_m[n]$ for $m = 0, 1, \cdots, M-1$.
Then the output vector is
Each component of $y$ is computed as
This shows that matrix-vector multiplication can also be interpreted row-wise as a sequence of inner products, in contrast to the earlier column-wise interpretation as a linear combination of vectors.
%%javascript
$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')