User`s guide
Spectral Analysis Example
6 W rite source code for an application that accesses the component.
The sample application for this example is in
SpectraExample\SpectraDemoJavaApp\powerspect.java.
The program listing is shown here.
powerspect.java
/* powerspect.java
* This file is used as an example for the MATLAB
* Builder for Java product.
*
* Copyright 2001-2006 The MathWorks, Inc.
*/
/* Necessary package imports */
import com.mathworks.toolbox.javabuilder.*;
import spectralanalysis.*;
/*
* powerspect class computes and plots the power
* spectral density of an input signal.
*/
class powerspect
{
public static void main(String[] args)
{
double interval = 0.01; /* Sampling interval */
int nSamples = 1001; /* Number of samples */
MWNumericArray data = null; /* Stores input data */
Object[] result = null; /* Stores result */
fourier theFourier = null; /* Fourier class instance */
try
{
/*
* Construct input data as sin(2*PI*15*t) +
* sin(2*PI*40*t) plus a random signal.
* Duration = 10
5-11