Guide Pwelch Usage - 2020-UQ-Communication-Systems/public GitHub Wiki

Matlab/Octave

If you are using older than 2013 MATLAB, or just want to customise your spectrum plots, you can get the output of pwelch as follows:

[fxx, f]=pwelch(z, [],[],[], 2.048e6);
plot(f-(mean(f)), fftshift(10*log10(fxx)))

Note that this spectrum is for a two sided (complex time domain) signal. In Octave or MATLAB 2013+ you can use some additional arguments to the standard pwelch function

pwelch(z, [], [], [], 2.048e6, 'shift', 'db'); % Octave pwelch with centred spectrum
pwelch(z, [], [], [], 2.048e6, 'centered', 'db'); % MATLAB 2013+ pwelch with centred spectrum

If you are using a real* signal, then you should use

[fxx, f]=pwelch(z, [],[],[], FS);
plot(f, 20*log10(fxx)) % note: assuming z is a 'voltage' signal, therefore to get power need to use 20

NOTE: real signal means has no imaginary components.

Python

f, Pxx = signal.welch(z, 2048000, nperseg=1024)
plt.plot(np.fft.fftshift(f), np.fft.fftshift(20*np.log10(Pxx)))

Using fftshift will make sure that you don't get a line across your graph.