How to add noise to sine signal and filter it?

8 次查看(过去 30 天)
Hi. I have two questions. 1) How to add noise with specific frequency (for example 2kHz-4kHz) to sine signal? 2) How to filter that signal (for example by using a bandpass filter) Please help me!

回答(1 个)

matico
matico 2015-8-25
编辑:matico 2015-8-25
Here I didn't use bandpass filters, but I just remove some harmonics from a signal using FFT and IFFT. The signal has got high 5th harmonics, which I want to include. Higher than that I want to remove. You can play with this in line: yFFT(7:end-7) = 0;
If you write:
yFFT(2:end-2) = 0;
Then you include only 0th harmonics -> this is offset (1.5 in my case).
yFFT(3:end-3) = 0;
You include offset + 1st harmonics. ...
yFFT(7:end-7) = 0;
Here are included offset and first 5 harmonics.
%%Create signal
clear; clc;
fSampling = 5000; % Hz
tSample = 1/fSampling;
T = 0:tSample:1-tSample; % 1s
Offset = 1.5;
F1 = 5; A1 = 3;
NoiseAmp = 0.5;
Sig = Offset + A1*sin(2*pi*F1*T) + NoiseAmp*(rand(1,length(T))-0.5);
%%FFT -> choose harmonics -> IFFT
yFFT = fft(Sig);
yFFT(7:end-7) = 0; % Play with numbers. Both must be the same
yFiltFFT = real(ifft(yFFT));
plot(T,Sig, T, yFiltFFT); grid;
Edit: Upps, now I see that you have specified frequency for a noise.

类别

Help CenterFile Exchange 中查找有关 Single-Rate Filters 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by