adding noise to a sine wave

5 次查看(过去 30 天)
mariam alsaid
mariam alsaid 2020-11-4
回答: Samya 2023-7-7
how can i Add a colored noise centered around 4.5kHz to a sinewave, and then plot noisy and filtered sine wave ?

回答(1 个)

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

Translated by