How to determine sampling frequency of wgn?
9 次查看(过去 30 天)
显示 更早的评论
Hello there,
I'm trying to understand noise analysis and the concept of power spectral density. I've found this article:
Which was really helpful and interesting, but I've encountered some problems while trying to put it in practise.
For convenience I wanted to generate white noise (mainly because of its flat spectral density) via wgn funtion and then calculate its PSD. If i understood it correctly, wgn creates discrete samples, which completely lack any relatationship to time.
And here comes my problem - while normalizing the results, equivalent noise bandwidth is dependent on sampling rate and so is PSD:
,
where w are window function values, S are complex results from fft function.
By experimenting with code I came upon sampling rate of 2 samples/s, when mean power of PSD was getting close to 5 dB. Unfortunatelly, I still cannot confidently explain this.
Is there please any way to obtain "realistic" white noise samples in MATLAB? Or do I have to add white noise to (co)sine signal with known sampling? If I'm missing something, please let me know.
Thank you in advance,
Jan
CODE:
% Size parameters
L = pow2(16);
iterations = 100;
% ??? (Guessed value)
fs = 2;
% Frequency resolution
f_res = fs/L;
% Create noise with power of 5 dBW
data = wgn(L,iterations, 5);
% Apply Hann window
h = hann(L);
w = ones(L,iterations) .* h;
data = data .* w;
% Calculate normalizing factor S2
S2 = sum(h.^2);
% Calculate fft
S = fft(data,L,1);
S = S .* conj(S);
% Average power spectrum
for i = 1:L
PSD(i) = mean(S(i,:));
end
% Normalize results
PSD = 2 * PSD / (fs * S2);
% Discard symmectric part
PSD = PSD(1:(L/2+1));
% PSD in dB(W)
PSD = 10*log10(PSD);
% Mean value of PSD
display("Power = " + mean(PSD) + " dB");
% Calculate frequency
f = (0:(L/2)) * f_res;
% Plot data
figure
plot(f,PSD)
xlabel("f [Hz]")
ylabel("PSD [dB/Hz]")
2 个评论
采纳的回答
William Rose
2024-7-4
编辑:William Rose
2024-7-5
@Jan,
[Edit: Re-ran the script because the plot below was wrong, probably from an earlier version of the script. Thanks to @Paul for catching it. Plot looks right now.]
You wrote "I just need to find a way to create white noise dependent on sampling rate, so when changes, the mean value of normalized PSD reamains at the approximately same level."
The expected power spectral density (PSD) associated with discretely sampled Gaussian white noise is
where fs=sampling rate, and Var(x)=variance of the time domain signal. Note that this is expected PSD. The actual PSD will have random fluctuation, To check if the formula above is correct, let's compute the PSD of an N point signal, M times, and average the M PSDs.
M=1000; N=256;
s=1; % standard deviation of the noise
fs=10; % sampling rate (Hz)
Pxx=zeros(M,N/2+1); % allocate array to hold the PSD results
for i=1:M
x=s*randn(1,N);
[Pxx(i,:),f]=periodogram(x,[],N,fs);
end
Pxxmn=mean(Pxx);
plot(f,Pxxmn,'-r.');
grid on; xlabel('Frequency (Hz)'); ylabel('Power/Hz'); title('P.S.D.')
The equation above predicts that the expected PSD should be 2*(1^2)/10=0.2. This is what we observe in the plot above.
Therefore, if you want to add noise so that its PSD is independent of the sampling rate, you need to scale the variance of the noise in proportion to the sampling rate. For example, if you increase fs by a factor of 2, then you should increase the standard deviation of the added noise by sqrt(2).
5 个评论
William Rose
2024-7-5
@Paul, Thank you for your attention to detail. Of course you are correct that the frequency axis should stop at fs/2, since periodogram returns the one-sided spectrum by default.
I suspect that I ran the script with fs=20 Hz, then changed fs to 10 Hz in the script, but forgot to re-run the script.
The plot with two PSDs, in my comment, shows the one-sided spectra extending up to frequency=fs/2, as expected.
William Rose
2024-7-5
@Jan,
You're welcome. You wrote "I didn't know about such a relation for expected power."
To be honest, I did not know anbout that relationship either, at least not in that exact form, until I worked it out from Parseval's theorem.
You wrote "I believe it solves all my problems..." I like your sense of humor.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parametric Spectral Estimation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!