Adding noise to a sine wave signal and filtering that noise ?

43 次查看(过去 30 天)
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

回答(1 个)

Ayush
Ayush 2023-7-7
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!

类别

Help CenterFile Exchange 中查找有关 Digital Filter Analysis 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by