01 /*
02 * $Id: PowerSpectral.java,v 1.20 2008/03/09 14:46:17 koga Exp $
03 *
04 * Copyright (C) 2004 Koga Laboratory. All rights reserved.
05 *
06 */
07 package matxbook.chap20;
08
09 import java.io.IOException;
10
11 import org.mklab.nfc.matrix.DoubleComplexMatrix;
12 import org.mklab.nfc.matrix.DoubleMatrix;
13 import org.mklab.nfc.matrix.IntMatrix;
14 import org.mklab.nfc.matrix.Matrix;
15 import org.mklab.nfc.util.Pause;
16 import org.mklab.tool.graph.gnuplot.Canvas;
17 import org.mklab.tool.graph.gnuplot.Gnuplot;
18
19
20 /**
21 * パワースペクトルを求めるサンプルです。
22 * @author koga
23 * @version $Revision: 1.20 $, 2004/05/07
24 */
25 public class PowerSpectral {
26
27 /**
28 * メインメソッド
29 *
30 * @param args コマンドライン引数
31 * @throws InterruptedException 強制終了された場合
32 * @throws IOException gnuplotプロセスを起動できない場合
33 */
34 @SuppressWarnings("nls")
35 public static void main(String[] args) throws InterruptedException, IOException {
36 DoubleMatrix t = DoubleMatrix.series(0, 1, 0.001);
37 DoubleMatrix y = t.multiply(2 * Math.PI * 50).sinElementWise().add((t.multiply(2 * Math.PI * 120)).sinElementWise().multiply(2));
38 DoubleMatrix yn = y.add(DoubleMatrix.normalRandom(y));
39 DoubleComplexMatrix yy = yn.fft(256);
40 Matrix pyy = yy.multiplyElementWise(yy.conjugate()).getRealPart();
41 DoubleMatrix f = IntMatrix.series(0, 127).multiply(1000 / 256.0);
42 Gnuplot gnuplot = new Gnuplot();
43 Canvas canvas = gnuplot.createCanvas();
44 canvas.plot(f, (DoubleMatrix)pyy.getSubVector(1, 128), new String[] {"power spectral density"});
45 Pause.pause();
46 gnuplot.close();
47 }
48 }
|