| MATLAB COM Builder | ![]() |
Building the Component
Your component will have one class with two methods, computefft and plotfft. The computefft method computes the FFT and power spectral density of the input data and computes a vector of frequency points based on the length of the data entered and the sampling interval. The plotfft method performs the same operations as computefft, but also plots the input data and the power spectral density in a MATLAB figure window. The MATLAB code for these two methods resides in two M-files, computefft.m and plotfft.m.
computefft.m: function [fftdata, freq, powerspect] = computefft(data, interval) if (isempty(data)) fftdata = []; freq = []; powerspect = []; return; end if (interval <= 0) error('Sampling interval must be greater then zero'); return; end fftdata = fft(data); freq = (0:length(fftdata)-1)/(length(fftdata)*interval); powerspect = abs(fftdata)/(sqrt(length(fftdata))); plotfft.m: function [fftdata, freq, powerspect] = plotfft(data, interval) [fftdata, freq, powerspect] = computefft(data, interval); len = length(fftdata); if (len <= 0) return; end t = 0:interval:(len-1)*interval; subplot(2,1,1), plot(t, data) xlabel('Time'), grid on title('Time domain signal') subplot(2,1,2), plot(freq(1:len/2), powerspect(1:len/2)) xlabel('Frequency (Hz)'), grid on title('Power spectral density')
To proceed with the actual building of the component, follow these steps:
comtool. See Graphical User Interface Menus for a discussion of using comtool to build a COM component from a collection of MATLAB M-files.
Check Use Handle Graphics library.
See Project Settings for a description of new project settings.
computefft.m and plotfft.m M-files to the project.
| Spectral Analysis Example | Integrating the Component with Visual Basic for Applications | ![]() |