How to add noise to sine signal and filter it?

조회 수: 8 (최근 30일)
Nur Fauzira Saidin
Nur Fauzira Saidin 2015년 8월 25일
편집: matico 2015년 8월 25일
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