%% dftdemo1
%% show a signal and dft pair

% define signal, sample rate, sample domain
N = 128;
t = (0:1:(N-1))/N;
I = sqrt(-1);
%sig = 2*cos(5*2*pi*t)+0.5*sin(24*2*pi*t);
k = 96; sig = [ones(1,k),zeros(1,N-k)]*(N/k);
%sig = rand(1,N);
%sig = 2*rand(1,N)-1;
%sig = 2*cos(5*2*pi*t)+ I*0.5*sin(24*2*pi*t);
SD = 0:(N-1);

% get dft and frequency domain
fsig = fft(sig); 
FD = 0:(N-1);

% display results 
figure(1)
subplot(2,1,1)
plot(SD,real(sig),'r',SD,imag(sig),'g')
title('sampled signal');
axis tight
subplot(2,1,2)
plot(FD, real(fsig),'r-',FD,imag(fsig),'g-')
title('DFT of signal')
axis tight
figure(2)
subplot(2,1,1)
plot(FD, abs(fsig),'r-' )
title('magnitude of DFT')
subplot(2,1,2)
plot(FD, angle(fsig),'g-' )
title('phase of DFT')



