filter awgn from sin sequence in matlab in matlab

To filter AWGN (Additive White Gaussian Noise) from a sinusoidal sequence in MATLAB, you can use a filter design and implementation approach.

First, create a sinusoidal signal with AWGN:

main.m
% Parameters
fs = 1000; % Sampling frequency (Hz)
f = 10; % Frequency of the sinusoid (Hz)
t = 0:1/fs:1-1/fs; % Time vector

% Create sinusoidal signal with AWGN
signal = sin(2*pi*f*t) + randn(size(t));
203 chars
8 lines

Next, design a filter to remove the noise. A common approach is to use a low-pass filter to selectively attenuate the high-frequency noise while preserving the sinusoidal component. Here's an example using a Butterworth filter:

main.m
% Filter design parameters
cutoff_freq = 100; % Cut-off frequency of the filter (Hz)
order = 4; % Order of the filter

% Normalize the cut-off frequency
normalized_freq = cutoff_freq / (fs/2);

% Design the Butterworth filter
[b, a] = butter(order, normalized_freq, 'low');

% Apply the filter
filtered_signal = filtfilt(b, a, signal);
336 chars
13 lines

In the above code, we first calculate the normalized cut-off frequency by dividing the desired cut-off frequency by half of the sampling frequency. Then, we design a low-pass Butterworth filter using the butter function. Finally, we apply the filter to the signal using the filtfilt function, which performs zero-phase filtering.

The filtered_signal will contain the sinusoidal component with the AWGN filtered out.

Note: The order and cut-off frequency values used in the filter design should be chosen based on your specific requirements.

gistlibby LogSnag