如何创建带限 (100-640 Hz) 高斯白噪声?
How do I create band-limited (100-640 Hz) white Gaussian noise?
我想创建具有(相对)平坦频谱的 500 毫秒带限(100-640 赫兹)高斯白噪声。噪声应正态分布,平均值 = ~ 0 和 99.7% 的值在 ± 2 之间(即标准偏差 = 2/3)。我的采样率为 1280 Hz;因此,为每一帧生成一个新的振幅。
duration = 500e-3;
rate = 1280;
amplitude = 2;
npoints = duration * rate;
noise = (amplitude/3)* randn( 1, npoints );
% Gaus distributed white noise; mean = ~0; 99.7% of amplitudes between ± 2.
time = (0:npoints-1) / rate
有人可以告诉我如何过滤信号以获得所需的结果(即 100-640 Hz)吗?另外,我希望有人能告诉我如何生成一个图表来说明频谱确实是平坦的。
我打算将波形导入信号 (CED) 以作为一种经颅电刺激形式输出。
以下是 "Some Guy" 在对您的问题的评论中提到的方法的 Matlab 实现。
% In frequency domain, white noise has constant amplitude but uniformly
% distributed random phase. We generate this here. Only half of the
% samples are generated here, the rest are computed later using the complex
% conjugate symmetry property of the FFT (of real signals).
X = [1; exp(i*2*pi*rand(npoints/2-1,1)); 1]; % X(1) and X(NFFT/2) must be real
% Identify the locations of frequency bins. These will be used to zero out
% the elements of X that are not in the desired band
freqbins = (0:npoints/2)'/npoints*rate;
% Zero out the frequency components outside the desired band
X(find((freqbins < 100) | (freqbins > 640))) = 0;
% Use the complex conjugate symmetry property of the FFT (for real signals) to
% generate the other half of the frequency-domain signal
X = [X; conj(flipud(X(2:end-1)))];
% IFFT to convert to time-domain
noise = real(ifft(X));
% Normalize such that 99.7% of the times signal lies between ±2
noise = 2*noise/prctile(noise, 99.7);
对使用此方法生成的大约一百万个样本进行统计分析,得出以下光谱和分布:
首先,正如预期的那样,频谱(使用 Welch 方法)在感兴趣的频带内是平坦的:
此外,使用信号直方图估计的分布与高斯 PDF 非常匹配。
我想创建具有(相对)平坦频谱的 500 毫秒带限(100-640 赫兹)高斯白噪声。噪声应正态分布,平均值 = ~ 0 和 99.7% 的值在 ± 2 之间(即标准偏差 = 2/3)。我的采样率为 1280 Hz;因此,为每一帧生成一个新的振幅。
duration = 500e-3;
rate = 1280;
amplitude = 2;
npoints = duration * rate;
noise = (amplitude/3)* randn( 1, npoints );
% Gaus distributed white noise; mean = ~0; 99.7% of amplitudes between ± 2.
time = (0:npoints-1) / rate
有人可以告诉我如何过滤信号以获得所需的结果(即 100-640 Hz)吗?另外,我希望有人能告诉我如何生成一个图表来说明频谱确实是平坦的。
我打算将波形导入信号 (CED) 以作为一种经颅电刺激形式输出。
以下是 "Some Guy" 在对您的问题的评论中提到的方法的 Matlab 实现。
% In frequency domain, white noise has constant amplitude but uniformly
% distributed random phase. We generate this here. Only half of the
% samples are generated here, the rest are computed later using the complex
% conjugate symmetry property of the FFT (of real signals).
X = [1; exp(i*2*pi*rand(npoints/2-1,1)); 1]; % X(1) and X(NFFT/2) must be real
% Identify the locations of frequency bins. These will be used to zero out
% the elements of X that are not in the desired band
freqbins = (0:npoints/2)'/npoints*rate;
% Zero out the frequency components outside the desired band
X(find((freqbins < 100) | (freqbins > 640))) = 0;
% Use the complex conjugate symmetry property of the FFT (for real signals) to
% generate the other half of the frequency-domain signal
X = [X; conj(flipud(X(2:end-1)))];
% IFFT to convert to time-domain
noise = real(ifft(X));
% Normalize such that 99.7% of the times signal lies between ±2
noise = 2*noise/prctile(noise, 99.7);
对使用此方法生成的大约一百万个样本进行统计分析,得出以下光谱和分布:
首先,正如预期的那样,频谱(使用 Welch 方法)在感兴趣的频带内是平坦的:
此外,使用信号直方图估计的分布与高斯 PDF 非常匹配。