1
$\begingroup$

This question already has an answer here:

I am trying to understand the difference between FFT magnitude and PSD (Power spectral density) with pwelch function of Matlab. In my example, Val1 and Val2 will output the same thing?

% N = 94144

% fs = 44100

segmentLength = N; % window size

[pxx,f] = pwelch(signal,segmentLength,[],segmentLength,fs);

%pwelch(data,segmentLength,overlappedSamples,segmentLength,fs);

Y = fft(signal);

Y_mag = abs(Y);

Val1 = 20*log10(Y_mag);

Val2 = 10*log10(pxx);

PS: I have already seen the other posts and I understand very well the difference between PSD and FFT but here I am interested in the diffeeence in code. Thanks

$\endgroup$

marked as duplicate by MBaz, Peter K. May 22 '17 at 14:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1
$\begingroup$

Pwelch does not just use one fft, it applies several ffts , windowing, scaling and averaging.If you do all that you may get equality.  Here is example equality of fft & pwelch:

N = 94144;
x = randn(1,N);
pwr1 = pwelch(x,ones(1,N),0,N,1,'twosided');
y = fft(x);
pwr2 = abs(y).^2;
plot(pwr1);
hold
plot(pwr2*max(pwr1)/max(pwr2),'r--');
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.