filter awgn from pure sin using bandpass filter in matlab

To filter out the additive white Gaussian noise (AWGN) from a pure sine wave using a bandpass filter in MATLAB, you can follow these steps:

  1. Generate the pure sine wave signal:
main.m
fs = 1000; % sampling frequency (Hz)
t = 0:1/fs:1; % time vector
f = 50; % frequency of the sine wave (Hz)
A = 1; % amplitude of the sine wave

sine_wave = A * sin(2*pi*f*t); % generate the pure sine wave signal
212 chars
7 lines
  1. Add AWGN to the pure sine wave:
main.m
SNR = 10; % Signal-to-Noise Ratio in decibels
noise = awgn(zeros(size(sine_wave)), SNR); % generate AWGN signal with the desired SNR

noisy_signal = sine_wave + noise; % add AWGN to the pure sine wave
201 chars
5 lines
  1. Design a bandpass filter:
main.m
f_low = 40; % lower frequency cutoff
f_high = 60; % higher frequency cutoff

order = 4; % filter order
[b, a] = butter(order, [f_low, f_high] / (fs/2), 'bandpass'); % design the bandpass filter
194 chars
6 lines
  1. Apply the bandpass filter to the noisy signal:
main.m
filtered_signal = filter(b, a, noisy_signal); % apply the filter to the noisy signal
85 chars
2 lines

The filtered_signal should now contain the pure sine wave with the AWGN filtered out.

Note: Make sure to adjust the desired frequency cutoffs (f_low and f_high) and the filter order (order) according to your specific application and requirements.

related categories

gistlibby LogSnag