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

조회 수: 20 (최근 30일)
Abdelaziz  Elgaafary
Abdelaziz Elgaafary 2019년 4월 16일
답변: Ayush 2025년 6월 19일
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 2025년 6월 19일
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