Signal Analysis Workflow

Signal Processingintermediate~10 min

Generate a noisy signal, analyze it with FFT, design a filter, and compare the cleaned result.

Step 1 — Generate a composite signal

Create a signal with two frequency components (10 Hz and 25 Hz) buried in noise. This mimics real-world sensor data where you must separate signal from noise.

t = linspace(0, 1, 512);
clean = sin(2*pi*10*t) + 0.5*sin(2*pi*25*t);
noisy = clean + 0.8*randn(1, 512);
plot(t, noisy);
title('Noisy signal')
▶ Run in SimLab

Expected output: A noisy waveform plot

Step 2 — Analyze with FFT

The Fast Fourier Transform reveals which frequencies dominate the signal. You should see clear peaks at 10 Hz and 25 Hz despite the noise.

N = length(noisy);
f = (0:N-1) / N * 512;
mag = abs(fft(noisy)) / N;
plot(f(1:N/2), mag(1:N/2));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Frequency Spectrum')
▶ Run in SimLab

Expected output: Spectrum with peaks near 10 Hz and 25 Hz

Step 3 — Design a low-pass filter

A 4th-order Butterworth filter with a 30 Hz cutoff (normalised to 0.117 at Fs=512 Sa/s, since fc/(Fs/2) = 30/256 ≈ 0.117) will keep the two signal tones and reject everything above.

Fs = 512;
fc = 30;
[b, a] = butter(4, fc/(Fs/2));
freqz(b, a, 256, Fs)
▶ Run in SimLab

Expected output: Filter frequency response plot

Step 4 — Apply the filter and compare

Apply the filter to the noisy signal, then overlay both to see the improvement.

filtered = filter(b, a, noisy);
subplot(2, 1, 1);
plot(t, noisy); title('Noisy');
subplot(2, 1, 2);
plot(t, filtered, 'b'); hold on;
plot(t, clean, 'r--');
legend('Filtered', 'Original clean');
title('Filtered vs. Original')
▶ Run in SimLab

Expected output: Two-panel comparison: noisy above, filtered + clean below

Related Tutorials

Try SimLab — Free MATLAB® Alternative

466 functions. Runs in your browser. No install.

Open SimLab

Stay Updated

Get notified about new simulations and tools. We send 1-2 emails per month.