SS Notes
Using MATLAB for signal processing — essential functions, filter design, spectral analysis, and system simulation with the Signal Processing Toolbox.
Introduction
MATLAB (Matrix Laboratory) has been the dominant tool in signal processing education and research for decades. Its Signal Processing Toolbox provides hundreds of specialized functions for filter design, spectral analysis, statistical signal processing, and system simulation. While Python has gained ground as a free alternative, MATLAB remains the standard in many academic courses and industrial applications due to its comprehensive documentation, intuitive syntax for matrix operations, and specialized toolboxes.
This guide covers the essential MATLAB functions and workflows you need for a signals and systems course — from basic signal generation through advanced filter design and spectral analysis. Each section includes runnable code that you can paste directly into MATLAB or GNU Octave for experimentation.
Signal Generation
fs = 8000; % Sampling rate
t = 0:1/fs:1-1/fs; % Time vector (1 second)
N = length(t); % Number of samples
% Basic signals
x_sin = sin(2*pi*440*t); % 440 Hz sine (concert A)
x_cos = cos(2*pi*1000*t); % 1 kHz cosine
x_exp = exp(-5*t); % Decaying exponential
x_step = heaviside(t - 0.3); % Unit step at t=0.3
% Complex signals
x_chirp = chirp(t, 100, 1, 2000); % Linear chirp 100-2000 Hz
x_noise = randn(1, N); % White Gaussian noise
x_am = (1 + 0.5*sin(2*pi*5*t)) .* cos(2*pi*500*t); % AM signal
% Impulse train (for sampling demonstrations)
x_impulse = zeros(1, N);
x_impulse(1:100:end) = 1; % Impulse every 100 samples
% Multi-tone signal (sum of sinusoids)
x_multi = sin(2*pi*200*t) + 0.5*sin(2*pi*500*t) + 0.3*sin(2*pi*1200*t);Key points: Always define fs and t first. The time vector 0:1/fs:1-1/fs gives exactly fs samples in one second. Use .* for element-wise multiplication (not matrix multiplication).
Core Signal Processing Functions
Convolution
y = conv(x, h); % Linear convolution
y = conv(x, h, 'same'); % Same length as x (centered)
y = conv(x, h, 'valid'); % Only fully-overlapping region
% Example: Convolve exponential with rectangle
h_rect = ones(1, 50)/50; % 50-point moving average
y_smooth = conv(x_noisy, h_rect, 'same');
% Circular convolution (periodic, length N)
y_circ = ifft(fft(x, N) .* fft(h, N));Filtering
y = filter(b, a, x); % Apply IIR/FIR filter (causal, real-time)
y = filtfilt(b, a, x); % Zero-phase filtering (non-causal, stored data)The difference between filter and filtfilt is critical: filter is causal (introduces phase distortion but works in real-time), while filtfilt runs the filter forward and backward, canceling phase distortion but requiring the entire signal in memory.
Correlation
Filter Design
Filter selection guide:
- Butterworth: maximally flat magnitude, gentle rolloff — good for general use
- Chebyshev I: sharper rolloff than Butterworth at cost of passband ripple
- Elliptic: sharpest possible rolloff for a given order, has both passband and stopband ripple
- FIR (Parks-McClellan): linear phase guarantee, higher order needed for sharp transitions
Spectral Analysis
Practical note: Zero-padding the FFT does NOT increase frequency resolution — it only interpolates between existing frequency samples, producing a smoother-looking spectrum. To increase actual resolution, you need more data (longer observation time).
System Analysis
Z-Transform Analysis
Useful Workflow Patterns
Complete Analysis Pipeline
Remove 60 Hz Interference
Resampling and Interpolation
% Downsample by factor M
M = 4;
x_down = decimate(x, M); % Includes anti-aliasing filter
% Upsample by factor L
L = 3;
x_up = interp(x, L); % Includes interpolation filter
% Resample to arbitrary rate
x_new = resample(x, 16000, fs); % From fs to 16000 HzKey Takeaways
- MATLAB's Signal Processing Toolbox provides comprehensive, well-documented functions
convfor convolution,filter/filtfiltfor real-time/offline filteringbutter,cheby1,ellip,firpmfor filter design — choose based on ripple tolerancefft+ proper frequency axis for spectral analysis;pwelchfor PSD estimationtf,impulse,step,bode,pzmapfor continuous-time system analysiszplane,freqz,residuezfor Z-transform and discrete-system analysis- Zero-padding FFT interpolates but does not improve resolution
filtfiltgives zero phase distortion;filteris causal (real-time capable)- Most MATLAB code runs directly in GNU Octave with minimal modification
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for MATLAB for Signals.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Signals & Systems topic.
Search Terms
signal-systems, signals & systems, signal, systems, numerical, tools, matlab, for
Related Signals & Systems Topics