Adding noise to a sine wave signal and filtering that noise ?
Show older comments
Hi every one, can you help me please , i need to plot a sine wave signal without noise at first then plot it when adding noise , then filtering that noise
Answers (1)
To plot a sine wave signal without a noise and then adding a noise, follow these steps:
- Generating a sine wave signal without noise
% Generate a sine wave signal without noise
frequency = 2; % Frequency of the sine wave (in Hz)
amplitude = 1; % Amplitude of the sine wave
sampling_rate = 100; % Number of samples per second
duration = 1; % Duration of the signal (in seconds)
t = linspace(0, duration, sampling_rate * duration);
signal = amplitude * sin(2 * pi * frequency * t);
% Plot the sine wave without noise
figure;
plot(t, signal);
xlabel('Time (s)');
ylabel('Amplitude');
title('Sine Wave without Noise');
grid on;
- Generation of noise and addition of noise
% Generate random noise
noise_amplitude = 0.2; % Amplitude of the noise
noise = noise_amplitude * randn(size(t));
% Add noise to the signal
noisy_signal = signal + noise;
% Plot the sine wave with noise
figure;
plot(t, noisy_signal);
xlabel('Time (s)');
ylabel('Amplitude');
title('Sine Wave with Noise');
grid on;
Now, filtering the noise:
- Defining a low-pass filter for noise removal
% Apply low-pass filter to remove noise
cutoff_frequency = 10; % Cut-off frequency of the low-pass filter
normalized_cutoff = cutoff_frequency / (sampling_rate / 2);
[b, a] = butter(4, normalized_cutoff, 'low');
filtered_signal = filtfilt(b, a, noisy_signal);
- Plotting filtered signal
% Plot the filtered signal
figure;
plot(t, filtered_signal);
xlabel('Time (s)');
ylabel('Amplitude');
title('Filtered Sine Wave');
grid on;
Hope it helps!
Categories
Find more on Digital Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

