filter awgn from pure sin in matlab in matlab

To filter AWGN (Additive White Gaussian Noise) from a pure sine wave in MATLAB, you can use a combination of filtering techniques such as low-pass filtering or statistical methods. Here is an example of how to perform this filtering:

main.m
% Generate a pure sine wave signal
fs = 1000; % Sampling frequency
t = 0:1/fs:1; % Time vector
f = 50; % Frequency of the pure sine wave
x = sin(2*pi*f*t); % Pure sine wave signal

% Add AWGN to the pure sine wave
snr = 10; % Signal-to-Noise Ratio (in dB)
y = awgn(x, snr); % Signal with AWGN

% Filter the signal to remove the AWGN
fc = 100; % Cut-off frequency of the low-pass filter
normalized_fc = fc / (fs/2); % Normalize the cut-off frequency
[b, a] = butter(4, normalized_fc); % Butterworth filter coefficients
filtered_y = filtfilt(b, a, y); % Apply the filter to the signal

% Plot the original, noisy, and filtered signals
figure;
subplot(3,1,1);
plot(t, x);
title('Original Pure Sine Wave');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(3,1,2);
plot(t, y);
title('Signal with AWGN');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(3,1,3);
plot(t, filtered_y);
title('Filtered Signal');
xlabel('Time (s)');
ylabel('Amplitude');
944 chars
34 lines

In this example, we first generate a pure sine wave signal with a frequency of 50 Hz. We then add AWGN to the pure sine wave using the awgn function, which takes the signal and the desired Signal-to-Noise Ratio (SNR) as input parameters.

Next, we filter the noisy signal to remove the AWGN using a low-pass Butterworth filter. The butter function is used to design the filter and it returns the filter coefficients b and a. Then, we use the filtfilt function to apply the filter to the noisy signal.

Finally, we plot the original pure sine wave, the noisy signal with AWGN, and the filtered signal to visualize the effect of filtering.

Note that you may need to change the values of the parameters such as the sampling frequency, the frequency of the pure sine wave, the SNR, and the cut-off frequency of the filter according to your specific requirements.

gistlibby LogSnag