User`s guide
3 Usage Examples
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:
1 If you have not already do ne so, execute the following command in
MATLAB:
mbuild -setup
Be sure to choose a supported compiler. See Supported Compile rs at
http://www.mathworks.com/support/tech-notes/1600/1601.shtml.
3-14