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