Perform calculations on y-axis values?

Sometimes when plotting functions, you want to do some operation on the y-axis. This comes up when you want to plot say decibels vs. frequency. It is not clear how you can do an operation like performing 10 Log10 on the y-axis values. Is there a straight forward way to do this? Incidentally, LogPlot just gives you the y-axis in log form.

Below are two methods. Here the function applied to the y data is Log, but any other will do as well. Also, have a look at LogLogPlot and LogLinearPlot.

xyData = RandomReal[{.1, 10}, {5, 2}]

(* {{3.7863585396010766`,2.0525620539014238`},{5.685398066640987`,4.\
020348266453116`},{7.6771838544964695`,9.879694699280535`},{4.\
361245849573017`,1.6275433819822656`},{7.313321495705271`,6.\
484234251087724`}} *)

(* mapping a pure function *)
oneWay = {#[[1]], Log[#[[2]]]} & /@ xyData

(* {{3.7863585396010766`,0.7190887952133352`},{5.685398066640987`,1.\
3913685323245182`},{7.6771838544964695`,2.290481610399797`},{4.\
361245849573017`,0.48707175034119526`},{7.313321495705271`,1.\
8693737307790999`}} *)

(* applying a rule *)
anotherWay = xyData /. {x_, y_} -> {x, Log[y]}

(* {{3.7863585396010766`,0.7190887952133352`},{5.685398066640987`,1.\
3913685323245182`},{7.6771838544964695`,2.290481610399797`},{4.\
361245849573017`,0.48707175034119526`},{7.313321495705271`,1.\
8693737307790999`}} *)

ScalingFunctions

I think scaling functions can be used to scale the plot, but the values indicated will be the original. In cases like dB, you really want to plot 10 Log(power). Am I wrong on this?

David’s approach is interesting, but it does not give me what I am looking for. What I ultimately want is the y-axis to be linear in decibels is 10 decibel increments. Matlab can readily do this.

Example 4.16 rev A.nb (54.4 KB)

TimeSeries are also useful for this even if the x’s are not times.

If you want the y-axis linear in dB, then convert gain to dB using the appropriate function and plot the y-axis using a linear scale. For power gain, the gain in dB is 10 Log10(gain). (For voltage or current gain, 20 Log10(gain).) For most control theory and electronics design purposes, a graph which is logarithmic in frequency and linear in dB is common. Using the Butterworth high pass in your notebook:

tfhpb = ButterworthFilterModel[{"Highpass", {1000, 4000}, {40, .1}}];

Plot[10 Log10[Abs[tfhpb[I \[Omega]]]], {\[Omega], 0, 10000}, 
 Frame -> True, PlotRange -> {-60, 10}, 
 GridLines -> {Automatic, Range[-100, 100, 20]}, 
 ScalingFunctions -> {"Log10", None}, 
 FrameLabel -> {"Frequency (Hz)", "Gain (dB)"}, LabelStyle -> 14]

You might also look at BodePlot.

Thank you for your help on this problem. Your code works great, except the x-axis is logarithmic, similar to a Bode plot. I found that if you remove the ScalingFunctions statement, you will get the x-axis linear, and the y-axis linear in 10 decibel increments.

Example 4.16 rev A.nb (87.7 KB)