% 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; % t(i) = i*tau, i=0,...,N-1
y = sin(2*pi*t*freq + phase); % Data set is sine wave
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); % f(i) = i/(N*tau), i=0,...,N-1
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); Imag(dash)');
ylabel('Fourier transform')
xlabel('Frequency')
subplot(111)