Lesson 15-Digital Signal Processing Fundamentals and Filter Design

Introduction

Welcome to the fifteenth and final article in our assigned writing series. In the previous two articles, we explored control systems—modeling, time-domain analysis, frequency-domain analysis, and root locus design. Now we’re going to shift gears and dive into another enormously important application of MATLAB: Digital Signal Processing (DSP).

If control systems are about making machines behave as desired, then signal processing is about extracting meaning from data. Every time you make a phone call, your voice is digitized, compressed, transmitted, and reconstructed—all using DSP techniques. Every time you listen to music on your phone, the audio is processed with digital filters to equalize the sound, reduce noise, and enhance the experience. Every time you use speech recognition (like Siri or Google Assistant), DSP algorithms are working behind the scenes to analyze and interpret your voice.

MATLAB and its Signal Processing Toolbox provide an incredibly powerful environment for analyzing, designing, and implementating digital filters and signal processing algorithms. Whether you’re working with audio signals, biomedical signals (like ECG or EEG), communications signals, image processing, or any other type of digital signal, MATLAB has the tools you need.

In this article, we’re going to explore the fundamentals of digital signal processing: sampling theory (the Nyquist criterion), the Discrete Fourier Transform (DFT) and Fast Fourier Transform (FFT), spectral analysis (power spectral density, periodograms, spectrograms), and digital filter design (FIR and IIR filters). We’ll learn how to design filters using MATLAB’s powerful filter design functions, how to apply filters to signals, and how to analyze filter performance.

By the end of this article, you’ll have a solid foundation in digital signal processing with MATLAB. You’ll understand the fundamental concepts (sampling, the FFT, filter design), you’ll know how to design and apply digital filters, and you’ll be able to analyze signals in both the time domain and the frequency domain. This knowledge is essential for anyone working with signals—engineers, scientists, researchers, and data analysts alike. Let’s begin our journey into the fascinating world of digital signal processing.

DSP in MATLAB: The Signal Processing Toolbox

The Signal Processing Toolbox is a MATLAB toolbox that provides algorithms and tools for systematically analyzing, designing, and processing signals. It’s the go-to toolbox for signal processing engineers, audio engineers, communications engineers, and biomedical researchers working in MATLAB.

What’s in the Signal Processing Toolbox?

The Signal Processing Toolbox includes functions for:

  1. Signal analysis: fft(), ifft(), fftshift(), pwelch(), periodogram(), spectrogram().
  2. Filter design: fir1(), fir2(), butter(), cheby1(), cheby2(), ellip(), designfilt().
  3. Filter analysis: freqz(), impz(), zplane(), fvtool().
  4. Filter application: filter(), filtfilt(), dftfilt().
  5. Window functions: hamming(), hann(), blackman(), kaiser().
  6. Signal measurement: findpeaks(), envelope(), rms(), peak2rms().
  7. Resampling and interpolation: resample(), interp(), decimate().
  8. Signal generation: chirp(), pulstran(), rectpuls(), tripuls().

We’ll cover many of these functions in this article. For a complete list, type doc signal in the MATLAB Command Window.

Checking for the Signal Processing Toolbox

Before we begin, let’s verify that you have the Signal Processing Toolbox installed. In the MATLAB Command Window, type:

ver signal

If you see “Signal Processing Toolbox” in the list, you’re good to go. If not, you’ll need to install it (or use a campus or workplace license that includes it).

Discrete Signals: Sampling Theorem (Nyquist), Aliasing Demonstration

We live in a continuous-time world. Sound waves are continuous; voltage signals are continuous; light intensity is continuous. But digital computers can only process discrete-time signals—signals that are sampled at specific time instants.

The process of converting a continuous-time signal to a discrete-time signal is called sampling. The reverse process (reconstructing the continuous-time signal from samples) is called reconstruction (or interpolation).

The fundamental question of sampling theory: how often do you need to sample a signal to perfectly reconstruct it?

The Nyquist-Shannon Sampling Theorem

The Nyquist-Shannon sampling theorem (named after Harry Nyquist and Claude Shannon) provides the answer. It states:

If a continuous-time signal x(t) is bandlimited (its Fourier transform X(f) = 0 for |f| > B, where B is the bandwidth), then x(t) can be perfectly reconstructed from its samples x[n] = x(nT) if the sampling rate fₛ = 1/T satisfies:

fₛ > 2B

The minimum sampling rate 2B is called the Nyquist rate.

In other words: to perfectly reconstruct a bandlimited signal, you must sample at more than twice its bandwidth.

Why Twice the Bandwidth?

The intuition: sampling creates images (copies) of the signal’s spectrum in the frequency domain, spaced at multiples of the sampling frequency fₛ. If fₛ is too small, these images overlap (a phenomenon called aliasing), and you can’t separate them to recover the original signal.

If fₛ > 2B, the images don’t overlap, and you can use an ideal low-pass filter to recover the original signal.

Aliasing: When Sampling Fails

Aliasing is what happens when you sample below the Nyquist rate. High-frequency components “fold back” into the low-frequency range, corrupting the signal. Once aliasing occurs, it’s irreversible—you can’t recover the original signal.

Aliasing is why:

  • You need to use an anti-aliasing filter (a low-pass filter) before sampling. The filter removes frequencies above fₛ/2 (the Nyquist frequency) to prevent aliasing.
  • Audio CDs sample at 44.1 kHz (to capture frequencies up to 20 kHz, the limit of human hearing, with a margin for the anti-aliasing filter).
  • Digital cameras have anti-aliasing filters (or use software techniques) to prevent moiré patterns (a visual manifestation of aliasing).

Demonstrating Aliasing in MATLAB

Let’s demonstrate aliasing in MATLAB. We’ll create a continuous-time sine wave at frequency f₀, sample it at rate fₛ, and show what happens when fₛ < 2f₀ (aliasing) vs. when fₛ > 2f₀ (no aliasing).

Example: Aliasing Demonstration

% Parameters
f0 = 100;       % signal frequency (Hz)
fs1 = 800;      % sampling rate 1: above Nyquist (OK)
fs2 = 150;      % sampling rate 2: below Nyquist (aliasing!)

% Time vectors
t_continuous = 0:0.0001:0.05;   % "continuous-time" (fine sampling)
t_discrete1 = 0:1/fs1:0.05;       % discrete-time samples (above Nyquist)
t_discrete2 = 0:1/fs2:0.05;       % discrete-time samples (below Nyquist)

% Signal
x_continuous = sin(2*pi*f0*t_continuous);
x_discrete1 = sin(2*pi*f0*t_discrete1);
x_discrete2 = sin(2*pi*f0*t_discrete2);

% Plot
figure;

% Continuous-time signal
subplot(3,1,1);
plot(t_continuous, x_continuous, 'b-', 'LineWidth', 2);
hold on;
plot(t_discrete1, x_discrete1, 'ro', 'MarkerSize', 8, 'MarkerFaceColor', 'r');
hold off;
grid on;
xlabel('Time (s)');
ylabel('Amplitude');
title(sprintf('Sampling at f_s = %d Hz (Above Nyquist: f_s > 2f_0 = %d Hz)', fs1, 2*f0));
legend('Continuous', 'Samples', 'Location', 'best');

% Discrete-time signal (above Nyquist) - reconstructed
subplot(3,1,2);
% Reconstruct using interpolation (ideal: use low-pass filter)
x_recon1 = interp1(t_discrete1, x_discrete1, t_continuous, 'spline');
plot(t_continuous, x_continuous, 'b-', 'LineWidth', 2);
hold on;
plot(t_continuous, x_recon1, 'r--', 'LineWidth', 1.5);
hold off;
grid on;
xlabel('Time (s)');
ylabel('Amplitude');
title('Reconstructed Signal (Above Nyquist)');
legend('Original', 'Reconstructed', 'Location', 'best');

% Discrete-time signal (below Nyquist) - aliasing!
subplot(3,1,3);
plot(t_continuous, x_continuous, 'b-', 'LineWidth', 2);
hold on;
plot(t_discrete2, x_discrete2, 'ro', 'MarkerSize', 8, 'MarkerFaceColor', 'r');
hold off;
grid on;
xlabel('Time (s)');
ylabel('Amplitude');
title(sprintf('Sampling at f_s = %d Hz (Below Nyquist: Aliasing!)', fs2));
legend('Continuous', 'Samples', 'Location', 'best');

sgtitle('Aliasing Demonstration');

In the first subplot (above Nyquist), the samples (red circles) clearly capture the sine wave. In the third subplot (below Nyquist), the samples (red circles) don’t capture the sine wave—they appear to form a lower-frequency signal. That’s aliasing: the high-frequency sine wave (100 Hz) appears as a lower-frequency signal (50 Hz, because fₛ - f₀ = 150 - 100 = 50 Hz).

The Nyquist Frequency

The Nyquist frequency is fₛ/2—half the sampling rate. It’s the highest frequency that can be unambiguously represented in a sampled signal.

In MATLAB, when you compute the FFT (fft()), the frequency axis goes from 0 to fₛ/2 (for the positive frequencies) and -fₛ/2 to 0 (for the negative frequencies, which are the mirror image).

Always remember: if your signal has frequency content above fₛ/2, you must use an anti-aliasing filter before sampling. Otherwise, aliasing will corrupt your signal.

Membership Required

You must be a member to access this content.

View Membership Levels

Already a member? Log in here
Share your love