No BSD License  

Highlights from
Numerical Methods for Physics

from Numerical Methods for Physics by Alejandro Garcia
Companion Software

sftdemo.m
% sftdemo - Discrete Fourier transform demonstration program
% This version uses the slow way of computing the tranform
clear; help sftdemo; % Clear memory and print header
N = input('Enter the number of points N - ');
freq = input('Enter frequency of the sine wave - ');
phase = input('Enter phase of the sine wave - ');
tau = 1;  % Time increment
% Build the data set
t = (0:(N-1))*tau;
y = sin(2*pi*t*freq + phase);
flops(0);  % Reset the flops counter to zero
% Compute discrete Fourier transform
yt = sft(y);
fprintf('Total number of flops = %g\n',flops);
% Compute frequency vector
f = (0:(N-1))/(N*tau);
subplot(121)
  plot(t,y);
  title('Original data set');
  ylabel('Amplitude');
  xlabel('Time')
subplot(122)
  plot(f,real(yt),'-',f,imag(yt),'--');
  title('Real (solid) and Imag (dash)');
  ylabel('Transform')
  xlabel('Frequency')
subplot(111)

  

Contact us at files@mathworks.com