How can I specify the FFT length for the spectrum objects in the Signal Processing Toolbox 6.2 (R14)?

Illustration
aadisingh - 2021-03-13T13:26:20+00:00
Question: How can I specify the FFT length for the spectrum objects in the Signal Processing Toolbox 6.2 (R14)?

I am using the spectrum.welch objects, and the documentation is not clear on how to specify the FFT length. There is some mention for using "User-Defined" and the dspopts object, but there are not any examples.  

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

This bug has been fixed in Release 14 Service Pack 2 (R14SP2). For previous releases, please read below for any possible workarounds:
The  documentation on setting the FFT length for the Spectrum objects is missing from the Signal Processing Toolbox manual.
To work around this issue, use the following code as an example for changing the FFT length for the Spectrum objects:
 
% Sample test data to perform the Welch method on:

t=0:0.001:2*pi;

x=sin(t);

% Initialize the Spectrum and Options objects

Hs=spectrum.welch;

Hopts=dspopts.spectrum;

% Change the options to use user-defined FFT length and Sampling Frequency

set(Hs,'FFTLength','UserDefined');

set(Hopts,'NFFT',512);

set(Hopts,'Fs',1000);

% Display the results

psd(Hs,x,Hopts)


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!