Calculates an N point spectrum by zero padding or time aliasing.
NSPECTRUM(series, N, wintype, fixamp)
series 
 
An input series  
N 
 
Optional. An integer, the FFT length. Defaults to the length of the input series.  
wintype 
 
Optional. An integer, the windowing function.
 
ampflag 
 
Optional. An integer. Windowing amplitude correction method.

A real series or array, the N point spectrum of the input.
W1: 1..12
W2: nspectrum(w1, 20)
W3: nspectrum(w1, 4)
W4: decimate(spectrum(w1), 3)
W2 contains 11 samples of the normalized spectrum of W1 with 8 zeros appended for an input length of 20. W3 contains 3 samples of the spectrum of W1. This is numerically equivalent to decimating the full spectrum by 3 as shown in W4, but because a 3 point spectrum is calculated, the computation is performed more quickly.
W1: 1..12
W2: nspectrum(w1, 20, 3)
W3: nspectrum(w1, 4, 3)
W4: decimate(spectrum(kaiser(w1)), 3)
Same as the first example except a Kaiser window is employed.
NSPECTRUM computes N equally spaced samples of the FFT by zero padding if N is greater than the series length or by time aliasing the input series if N is less than the series length. The spectrum computes the normalized magnitude of the FFT.
For N < length(s), the result is numerically equivalent to decimating the full spectrum (where the number of samples is equal to length(s)), however, the computation is generally faster since a shorter FFT is computed.
See SPECTRUM for a discussion of the spectrum normalization.
If a windowing function is specified, the window is applied to the entire input series.
If ampflag == 1, the correction factor is the mean of the spectral window. This assures that the spectrum of a sinusoid of amplitude A has a peak of A.
If ampflag == 2, the correction is applied as follows:
w = winfun(s) * rms(s) / rms(winfun(s))
where winfun is Blackman, Blackmanharris, Flattop, Hamming, Hanning or Kaiser. This assures that:
sqrt(area(psd(w))) == rms(s) approximately
If ampflag == 3, the correction is applied as follows:
w = winfun(s) / sqrt(mean(win * win)
where win is the windowing function.
See DADiSP/FFTXL to optimize the underlying FFT computation.