cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
SDF1
Super User

How to get peak position values in spectrogram using JSL

Hi All,

 

  I have some data that I'm performing a time series analysis on where I'd like to get the positions of the peaks from the Periodogram (Time Series > Save Spectral Density). You can for example do this with the Air.jmp sample data table, putting in only a Y column variable. You can put the X, Time ID variable in, but it's not necessary.

 

  Anyway, once you save the Spectral Density, there are several columns, :Spectral Density, :Periodogram, and :Frequency that are of interest, see screenshot below.

SDF1_0-1692213254668.png

  What I'm trying to do is find the row numbers of maybe the top 3 or 4 peaks in the :Periodogram column -- it's a bit easier to work with than the :Spectral Density column (see yellow highlighted areas). Once I have those row numbers, then I can find the corresponding values in the :Period and :Frequency columns to report back as a result.

 

  The problem I have is being able to get those other values that aren't the Col Max(:Periodogram) result. I can get that just fine, but it's harder to pick out the other columns of interest. I'd like to do this with JSL so that the task is automated rather than having to use the lasso tool or something like that.

 

  Any ideas or suggestions are much appreciated.

 

Thanks!,

DS

 

Edit: Another thought would be to have JMP search for peak values within a certain range. I'm really not very interested in the extremely large period values that can show up (conversely, the very low frequency data also isn't very important). Also, sometimes the Spectral Density is easier than Periodogram, and vice versa. Anyway, some way to select the peaks in either of these two columns would be great. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to get peak position values in spectrogram using JSL

Here is other option using Dif()

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Time Series/Air.jmp");

ts = dt << Time Series(Y(:Ozone Concentration));

dt1 = ts << Save Spectral Density;
ts << Close Window;
Close(dt, no save);

dt1 << Sort(By(:Period), Replace Table, Order(Ascending));

dt1 << New Column("PeriodogramPeaks", Numeric, Nominal, Formula(
	Dif(:Periodogram) > 0 & Dif(:Periodogram, -1) > 0
));

dt1 << New Column("PeakRank", Numeric, Ordinal, Formula(
	Col Number(:Periodogram, :PeriodogramPeaks) - Col Rank(:Periodogram, :PeriodogramPeaks) + 1
));

peak_rows = dt1 << Get Rows Where(:PeakRank <= 4 & :PeriodogramPeaks == 1);
dt1 << Select Rows(peak_rows);
dt1 << Markers(16);

gb = dt1 << Graph Builder(
	Size(534, 456),
	Show Control Panel(0),
	Variables(X(:Period), X(:Frequency), Y(:Spectral Density), Y(:Periodogram)),
	Elements(Position(1, 1), Line(X, Y, Legend(7)), Points(X, Y, Legend(8))),
	Elements(Position(1, 2), Line(X, Y, Legend(5)), Points(X, Y, Legend(6))),
	Elements(Position(2, 1), Line(X, Y, Legend(9)), Points(X, Y, Legend(10))),
	Elements(Position(2, 2), Line(X, Y, Legend(11)), Points(X, Y, Legend(12)))
);
-Jarmo

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: How to get peak position values in spectrogram using JSL

Here is an example of one way of finding the peaks.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/blood pressure.jmp" );
dt << select where(
	Try( :bp 8m[Row() - 1], 999 ) < :bp 8m[Row()] & :bp 8m[Row()] > Try( :bp 8m[Row() + 1], 0 )
);
Jim
jthi
Super User

Re: How to get peak position values in spectrogram using JSL

Here is other option using Dif()

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Time Series/Air.jmp");

ts = dt << Time Series(Y(:Ozone Concentration));

dt1 = ts << Save Spectral Density;
ts << Close Window;
Close(dt, no save);

dt1 << Sort(By(:Period), Replace Table, Order(Ascending));

dt1 << New Column("PeriodogramPeaks", Numeric, Nominal, Formula(
	Dif(:Periodogram) > 0 & Dif(:Periodogram, -1) > 0
));

dt1 << New Column("PeakRank", Numeric, Ordinal, Formula(
	Col Number(:Periodogram, :PeriodogramPeaks) - Col Rank(:Periodogram, :PeriodogramPeaks) + 1
));

peak_rows = dt1 << Get Rows Where(:PeakRank <= 4 & :PeriodogramPeaks == 1);
dt1 << Select Rows(peak_rows);
dt1 << Markers(16);

gb = dt1 << Graph Builder(
	Size(534, 456),
	Show Control Panel(0),
	Variables(X(:Period), X(:Frequency), Y(:Spectral Density), Y(:Periodogram)),
	Elements(Position(1, 1), Line(X, Y, Legend(7)), Points(X, Y, Legend(8))),
	Elements(Position(1, 2), Line(X, Y, Legend(5)), Points(X, Y, Legend(6))),
	Elements(Position(2, 1), Line(X, Y, Legend(9)), Points(X, Y, Legend(10))),
	Elements(Position(2, 2), Line(X, Y, Legend(11)), Points(X, Y, Legend(12)))
);
-Jarmo
SDF1
Super User

Re: How to get peak position values in spectrogram using JSL

Hi @jthi and @txnelson ,

 

  Thank you both for your input. I ended up going with @jthi 's solution because it seemed to work better for the kind of data I am dealing with, using the spectral density graphs/data tables. I really appreciate both of your input on this, thanks again for another helpful solution!

 

DS