How to plot a semilogx stairs function with x values in the center

9 Ansichten (letzte 30 Tage)
Ozan Oguz
Ozan Oguz am 6 Sep. 2013
Kommentiert: Ruud Vermeulen am 20 Jun. 2022
  • I have some acoustic test data.I could'nt find a simple solution for my plotting needs.Here it goes...
  • X axis have frequency values. Each X value shows a center frequency of measured octave interval. Each Y shows the overal sound pressure level at a center freq. for that interval.
  • Assume
Center frequencies as: 32,64,125,250,500 in Hz.
Respectively, sound pressure values are: 90,95,100,93,82 in dBP.
  • Example:
Y value at 125 Hz is 100 dBP, and the stair step centered at 125 Hz must extend from half octave below to half octave above 125 Hz (in this case, we'll also need a value before 32Hz and an other after 500Hz).
(X axis must show center frequencies).
  • So... How to plot this?

Antworten (1)

Stephan
Stephan am 12 Dez. 2016
Bearbeitet: Stephan am 13 Dez. 2016
I know it is an old question, but just for documentation purposes, here is my solution:
%center frequencies of the one third octaves
fc = [160 200 250 315 400 500 630 800 1000 1250 1600 2000 2500 3150 4000 5000];
%sound pressure level
level = [10 20 30 40 30 20 10 20 40 50 20 10 20 30 40 20];
%calculate new frequency values, i.e. one half of a one third octave -> 2^(-1/6)
%also: last value has to be doubled to get a proper line
f_low = [fc .* 2^(-1/6), fc(end) * 2^(1/6)];
level = [level, level(end)];
figure;
stairs(f_low, level);
ax = gca;
ax.XScale = 'log'; %make x-axis logarithmic
ax.XTick = fc; %set the tick values to be the center frequencies
ax.XTickLabelRotation = 90; %rotate the x-labels for better visibility
ax.XLim = [fc(1), fc(end)]; %set the limits for the x-axis
xlabel('Frequency in Hz');
ylabel('Sound pressure level in dB(A)');

Kategorien

Mehr zu Audio Processing Algorithm Design finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by