0
$\begingroup$

I have C++ App which wich plot 3 plot

enter image description here

  1. amplituede vs sample
  2. amplitude vs frequncey(used FFT for calculation)
  3. amplitude(in dB) vs frequncey

I want plot 2 with y axis lable represent in DB, without chaning the y value of the plot. That is the plot shape will stay same but the y axis lable need to convert to dB. Is this possible, or is it the right way to represent the data like that.

The plot 3 is actually used the same data of plot 2, but the y value convert to DB. What I want is the plot 2 with y axis lable changed to dB.

$\endgroup$
7
  • 3
    $\begingroup$ Well you need to modify the y axis so that the tick labels are converted to dB. But I don’t know what “app” you’re using so I can’t really help you. Did you code this yourself? What plotting tool are you using? $\endgroup$
    – Jdip
    Nov 16, 2023 at 7:17
  • $\begingroup$ Thanks for the response, I used the code from here svenssonjoel.github.io/pages/qt-audio-fft/index.html, you see the bottom plot in given link, the Freq vs Amp, My doubt is can I change the label of y axis directly without converting the y-axis sample value. That is instead of amp value I need the dB in y axis, but the plot should be same. $\endgroup$
    – Haris
    Nov 16, 2023 at 7:58
  • 1
    $\begingroup$ @Haris but then the plot is wrong? $\endgroup$ Nov 16, 2023 at 11:34
  • $\begingroup$ Which plot?. Can explain, I did not understand your question. $\endgroup$
    – Haris
    Nov 16, 2023 at 16:07
  • $\begingroup$ @Haris, Marcus Müller is right. If you change the label to say “Amplitude in dB” then it will be wrong as the $y$ values at the plot will not represent deciBels. I think you should clarify your problem here and tell us exactly what you are trying to achieve because as the problem is stated looks more like “I want to change the label of my axis” rather than “I want to calculate something - dB values for example - from my data”. $\endgroup$
    – ZaellixA
    Nov 16, 2023 at 17:33

2 Answers 2

2
$\begingroup$

To add to Hilmar’s answer and chew some of the work for you:

You need to modify the y-axis tick values. I went through the documentation of your plotting tool for you, and found this. Look in the “Controlling the axes” section, particularly you’ll be interested in the setTicker property

Good luck!

$\endgroup$
3
  • $\begingroup$ Thanks for the help, I will look in to it. $\endgroup$
    – Haris
    Nov 16, 2023 at 18:33
  • $\begingroup$ And so while I convert the y-axis ticks to DB, I have to use the equation "amplitude_dB = 20 * log10((apmlitude) / refAmplitude);" So do you have any suggession regarding choosing refAmplitude. $\endgroup$
    – Haris
    Nov 16, 2023 at 18:37
  • 1
    $\begingroup$ That depends. In most audio applications you want dBFS, so if you're working with data limited to the range $-1$ to $1$, which seems the case for you, ref = 1. Be careful though: positive and negative ticks should have the same value after conversion to $\tt{dB}$ . For example you want the tick at $0.5$ to be converted to $-6\tt{dB}$, but you also want the tick at $-0.5$ to be converted to $-6\tt{dB}$. So you need to take the absolute value: $y_{tick-in-dB} = 20 \log_{10} (|y_{tick-linear}|)$. $\endgroup$
    – Jdip
    Nov 16, 2023 at 19:17
2
$\begingroup$

You have two choices. You either maintain a linear grid and just replace the amplitude grid numbers with their respective dB values, or you can use a logarithmic grid with constant dB spacing. The graph below show both options

enter image description here

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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