ploting a logaritmic-distributed data
Mostrar comentarios más antiguos
I am trying to plot data obtained from a spectrum analyzer. The x-scale of its measurements is in logaritmic. I would like to plot it as I see it in the instrument's display:

However, I obtain this:

when
freqs = linspace(startFrequency, stopFrequency, num_of_points);
semilogx(freqs, measurements)
, when
freqs = linspace(startFrequency, stopFrequency, num_of_points);
plot(freqs, measurements)
, when
freqs = logspace(log10(startFrequency), log10(stopFrequency), num_of_points);
plot(freqs, measurements)
and when
freqs = logspace(log10(startFrequency), log10(stopFrequency), num_of_points);
semilogx(freqs, measurements)
On the other hand, I obtain:

in any case of the ones above but with
set(axes, 'xscale', 'log');
How am I supposed to do it?
Many thanks.
Edit: if the data was needed, I have attached it.
1 comentario
freqs = linspace(startFrequency, stopFrequency, num_of_points);
semilogx(freqs, measurements)
xlim([150E3 30E6])
ylim([34 64])
will give the same limits. Looks like perhaps the analyzer cut off the next bin at the LH side. Try stretching the actual axis length out to match; not sure why your plotted spectrum seems more compressed towards the higher frequencies; looks like same RH upper limit if I read the scale correctly.
Respuesta aceptada
Más respuestas (2)
Star Strider
el 2 de Mayo de 2016
I’m not certain what you want the plot to look like.
This is my best guess:
D = load('Lucas Santisteban spectrum.mat');
measurements = D.spectrum;
num_of_points = length(measurements);
startFrequency = 150E+3;
stopFrequency = 30E+6;
freqs = linspace(startFrequency, stopFrequency, num_of_points);
antilogfreqs = 10.^(freqs/startFrequency);
figure(1)
semilogx(antilogfreqs, measurements)
xt = get(gca, 'XTick');
xtl = linspace(startFrequency, stopFrequency, length(xt));
xtlf = regexp(sprintf('%.1f\\cdot10^%.0f\n', [10.^rem(log10(xtl),1)' fix(log10(xtl))']'), '\n', 'split');
set(gca, 'XTick',xt, 'XTickLabel',xtlf(1:end-1), 'XMinorTick','on')
grid
This code begins by taking the antilog of the frequency vector to create the plot. The ‘xt’ assignment gets the x-tick values the plot call creates, ‘xtl’ creates a linear vector of the frequencies that simply re-samples the frequency vector, the xtlf call creates a formatted version, split into individual cells for the plot labels.
The result:

1 comentario
Lucas Santisteban
el 3 de Mayo de 2016
Editada: Lucas Santisteban
el 3 de Mayo de 2016
Lucas Santisteban
el 3 de Mayo de 2016
0 votos
Categorías
Más información sobre Blue en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!