Butterworth Filter Equation
MATLAB designs the filter using the analog Butterworth magnitude response:
|H(jω)|2 = 1 / [ 1 + (ω / ωc)2n ]
Where:
- ωc = Cutoff frequency
- n = Filter order
- ω = Signal frequency
MATLAB converts this analog filter into a digital filter using the bilinear transform.
Important MATLAB Functions Used
| Function | Purpose |
|---|---|
butter() |
Designs Butterworth filter coefficients |
filtfilt() |
Performs zero-phase forward and backward filtering |
plot() |
Visualizes signals |
Example Filter Creation
[b,a] = butter(order, cutoff/(Fs/2), 'low');
Why filtfilt() is Used
filtered = filtfilt(b,a,demod);
The filtfilt() function performs:
- Forward filtering
- Reverse filtering
This removes phase distortion, producing a zero-phase filtered signal. This behavior is similar to the JavaScript forward-backward zero-phase filtering used in the simulator.
MATLAB Code
clc;
clear;
close all;
%% Parameters
fm = 5; % Message frequency (Hz)
fc = 50; % Carrier frequency (Hz)
Fs = 1000; % Sampling frequency (Hz)
Am = 1; % Amplitude
cutoff = 10; % Low pass cutoff frequency (Hz)
order = 5; % Butterworth filter order
T = 1; % Duration (seconds)
t = 0:1/Fs:T-1/Fs; % Time vector
%% Message Signal
m = Am*cos(2*pi*fm*t);
%% Carrier Signal
c = cos(2*pi*fc*t);
%% DSB-SC Modulation
dsb = m .* c;
%% Coherent Demodulation
demod = dsb .* c;
%% Butterworth Low Pass Filter Design
Wn = cutoff/(Fs/2); % Normalized cutoff frequency
[b,a] = butter(order, Wn, 'low');
%% Filtering
filtered = filtfilt(b,a,demod); % zero phase filtering
%% Amplitude Scaling
recovered = 2*filtered;
%% Plot Results
figure;
subplot(4,1,1)
plot(t,m)
title('Message Signal')
xlabel('Time (s)')
ylabel('Amplitude')
subplot(4,1,2)
plot(t,dsb)
title('DSB-SC Modulated Signal')
xlabel('Time (s)')
ylabel('Amplitude')
subplot(4,1,3)
plot(t,demod)
title('Demodulated Signal (Before Filtering)')
xlabel('Time (s)')
ylabel('Amplitude')
subplot(4,1,4)
plot(t,recovered)
title('Recovered Message after Butterworth LPF')
xlabel('Time (s)')
ylabel('Amplitude')
Output