# Plot amplitude vs freqency in DB

I have C++ App which wich plot 3 plot

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.

• 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?
– Jdip
Nov 16, 2023 at 7:17
• 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. Nov 16, 2023 at 7:58
• @Haris but then the plot is wrong? Nov 16, 2023 at 11:34
• Which plot?. Can explain, I did not understand your question. Nov 16, 2023 at 16:07
• @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”. Nov 16, 2023 at 17:33

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!

• Thanks for the help, I will look in to it. Nov 16, 2023 at 18:33
• 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. Nov 16, 2023 at 18:37
• 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}|)$.
– Jdip
Nov 16, 2023 at 19:17

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