How to add noise to sine signal and filter it?
7 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
matico
on 25 Aug 2015
Edited: matico
on 25 Aug 2015
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.
0 Comments
See Also
Categories
Find more on Fourier Analysis and Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!