필터 지우기
필터 지우기

How to determine sampling frequency of wgn?

조회 수: 73 (최근 30일)
Jan
Jan 2024년 7월 3일 22:24
댓글: William Rose 2024년 7월 5일 1:47
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:
Sum of squared window values. , PSD normalization
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");
"Power = 4.9725 dB"
% Calculate frequency
f = (0:(L/2)) * f_res;
% Plot data
figure
plot(f,PSD)
xlabel("f [Hz]")
ylabel("PSD [dB/Hz]")
  댓글 수: 2
Paul
Paul 2024년 7월 4일 2:45
편집: Paul 2024년 7월 4일 2:45
Hi Jan,
Can you clarify what the question? What exactly are you not confident in explaining and what is mean by "realistic" white noise?
Jan
Jan 2024년 7월 4일 10:34
Hi @Paul,
I apologize for the confusion I've made. When measuring noise in real-life scenarion, each iteration would result in two vectors - first containing signal magnitude and the second one time stamps. Or just a magnitude vector and value of sampling rate. Either way, I would be able to normalize PSD correctly, since I could calculate/would know the .
So, my question was, if there is a way to simulate such a measurement in MATLAB, that would keep its relationship to time or sampling? Something like:
[mag, time] = wgn(L, iterations, power, fs);
but as I said before, I know wgn creates discrete samples. 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.

댓글을 달려면 로그인하십시오.

채택된 답변

William Rose
William Rose 2024년 7월 4일 15:15
편집: William Rose 2024년 7월 5일 0:58
[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
William Rose 2024년 7월 5일 0:53
@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
William Rose 2024년 7월 5일 1:47
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 CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by