Message Boards Message Boards

0
|
10026 Views
|
7 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Perform calculations on y-axis values?

Posted 6 years ago

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.

POSTED BY: Jesse Sheinwald
7 Replies
Posted 6 years ago

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`}} *)
POSTED BY: David Keith

ScalingFunctions

POSTED BY: Kapio Letto
Posted 6 years ago

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?

POSTED BY: David Keith

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.

Attachments:
POSTED BY: Jesse Sheinwald

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

POSTED BY: Gustavo Delfino
Posted 6 years ago

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]

enter image description here

You might also look at BodePlot.

POSTED BY: David Keith

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.

Attachments:
POSTED BY: Jesse Sheinwald
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract