Power Spectral density plot in a certain frequency range

Hi guys,
I want to do a Power Spectral density spectrum of a given txt file (170619pulser1_1_trace.txt). The code that I use is the following:
A = load('170619pulser1_1_trace.txt');
rawData = length(A);
% Power Spectral density of raw data %
Fs = 25e6; % Sampling frequency
Ts = 1/Fs;
N = rawData;
tmax=(N-1)*Ts;
t = 0:Ts:tmax;
nfft = 2^nextpow2(length(A));
Pxx = abs(fft(A,nfft)).^2/length(A)/Fs;
Hpsd = dspdata.psd(Pxx(1:length(Pxx)/2),'Fs',Fs);
h1 = plot(Hpsd);
set(h1,'Color','b')
This gaves me the following plot which is esentially fine:
Now the point is the following: is there any way to make the same plot but just in a certain frequency range, and not in the whole Fs/2 range?. Let´s say that I´m just interested in the region [0, 10 KHz], is there any way to make the dsp in this range?. I mean, apart from using the "zoom in" tool :-).
Many thanks, Jose Manuel.

Risposte (1)

Use the axis (link) function:
h1 = plot(Hpsd);
set(h1,'Color','b')
axis([0 1E+4 ylim])

2 Commenti

Hi Star, thanks for the reply. However, this is the same as using the zoom in tool. What I want is the following: lets say that dspdata.psd contains 1000 individual points (frequencies) when you use the whole Fs range to plot it. What I wanto to do is to have those same 1000 individual points in my desired frequency range (say [0 10 KHz]. If I do what you suggest I get this:
Where it is clear that I have lost resolution.
Cheers, Jose Manuel.
Your data are what they are. If you have 1000 points between 0 and 1.2E+7 Hz, and they are evenly spaced, the points are 1.2E+4 Hz apart. A window of 1.0E+4 Hz does not have the resolution to show anything other than the straight line that you got.
You can increase the frequency resolution by increasing ‘nfft’, and perhaps using resample to increase the sampling frequency. I leave you to experiment with those options.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by