Clear Filters
Clear Filters

adding noise to a sine wave

4 views (last 30 days)
mariam alsaid
mariam alsaid on 4 Nov 2020
Answered: Samya on 7 Jul 2023
how can i Add a colored noise centered around 4.5kHz to a sinewave, and then plot noisy and filtered sine wave ?

Answers (1)

Samya
Samya on 7 Jul 2023
To add colored noise centered around 4.5kHz to a sine wave and then plot the noisy and filtered sine wave, you can follow these steps in MATLAB:
  • Generate the sine wave:
fs = 44100; % Sampling frequency (adjust as needed)
t = 0:(1/fs):1; % Time vector
f = 1000; % Frequency of the sine wave (adjust as needed)
sine_wave = sin(2*pi*f*t); % Generate the sine wave
  • Generate colored noise:
noise_power = 0.2; % Adjust the noise power as needed
colored_noise = sqrt(noise_power) * randn(size(t)); % Generate Gaussian white noise
colored_noise = filter(1, [1 -0.9], colored_noise); % Filter the noise to make it colored (adjust filter coefficients as needed)
  • Add the colored noise to the sine wave:
noisy_sine_wave = sine_wave + colored_noise;
  • Plot the noisy and filtered sine wave:
filtered_sine_wave = filter(1, [1 -0.9], noisy_sine_wave); % Apply the same filter to the noisy signal
figure;
subplot(3,1,1);
plot(t, sine_wave);
xlabel('Time');
ylabel('Amplitude');
title('Sine Wave');
subplot(3,1,2);
plot(t, noisy_sine_wave);
xlabel('Time');
ylabel('Amplitude');
title('Noisy Sine Wave');
subplot(3,1,3);
plot(t, filtered_sine_wave);
xlabel('Time');
ylabel('Amplitude');
title('Filtered Sine Wave');
Hope this helps!

Community Treasure Hunt

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

Start Hunting!