3
votes

I have several data points that are plotted below and I would like to find the frequency value when the amplitude value crosses 4. I've included an example along with the data points in the example below. I've circled the answer graphically but I'm not sure how to compute it mathematically and get all the values for the frequencies I desire. How can I do this with octave / matlab? Also is there a mathematical term for what I'm trying to do?

In this example I'm trying to get 5 frequencies (but this is just an example) I know two answers are 30 and 80 but not sure how to get the rest. The full list could be thousands. I'm using octave 3.8.1

clear all,clf, clc,tic
%graphics_toolkit gnuplot %use this for now it's older but allows zoom
freq=[20,30,40,50,60,70,80];
amp_orig=[2,4,3,7,1,8,4];
amp_inv=[6,4,5,1,7,0,4];


plot(freq,amp_orig,'-bo')
hold on
plot(freq,amp_inv,'-r*')
xlabel ("Frequency");
ylabel ("Amplitude");

enter image description here

Thanks

2
To answer your other question, what you're trying to do is find the intersection of the lines. This question gives a good overview of various techniques. - MrAzzaman
@amo thanks but this function will not work with octave 3.8.1 - Rick T

2 Answers

2
votes

Should you have access to Matlabs Mapping Toolbox, your problem can be solved easily using the function polyxpoly(). It will find the intersections of two graphs. They do not even have to be lines, also polygons work. Here is an example for your case:

%graphics_toolkit gnuplot %use this for now it's older but allows zoom
freq=[20,30,40,50,60,70,80];
amp_orig=[2,4,3,7,1,8,4];
amp_inv=[6,4,5,1,7,0,4];

plot(freq,amp_orig,'-bo')
hold on
plot(freq,amp_inv,'-r*')
xlabel ('Frequency');
ylabel ('Amplitude');

%// find and add intersections
[xi,yi] = polyxpoly(freq,amp_orig,freq,amp_inv)
plot(xi, yi,'ro','markersize',20) %// draw the red circles automatically :-)

The result looks like this enter image description here

1
votes

Try this function from the File Exchange, it seems to work just fine in Octave. x0 are the frequencies of interest:

>> [x0,y0,iout,jout] = intersections(freq,amp_orig,freq,amp_inv)
x0 =

   30.000
   30.000
   42.500
   55.000
   64.286
   80.000

y0 =

   4.0000
   4.0000
   4.0000
   4.0000
   4.0000
   4.0000

iout =

   2.0000
   2.0000
   3.2500
   4.5000
   5.4286
   7.0000

jout =

   2.0000
   2.0000
   3.2500
   4.5000
   5.4286
   7.0000