%% dft1demo2 with dot plots
% show a signal and dft pair
% the dft is shifted to put low frequencies in the center 

% S. Allen Broughton - 29 Sep 10
%% define signal, sample rate, sample domain
% define sample points and parameters for signal definition
N = 128;
t = (0:1:(N-1))/N;
I = sqrt(-1);

% uncomment the desired signal
%sig = 2*cos(5*2*pi*t)+0.5*sin(24*2*pi*t);
%sig = 2*cos(3*2*pi*t)+0.5*sin(5.4*2*pi*t);
%sig = 2*cos(5*2*pi*t)+0.1*sin(30*2*pi*t);
k = round(0.1*N); sig = [ones(1,k),zeros(1,N-k)]*(N/k);
%k = 2; sig = [ones(1,k),zeros(1,N-k)]*(N/k);
%k = round(0.95*N); sig = [ones(1,k),zeros(1,N-k)]*(N/k); sig = sig - mean(sig);
%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);
%sig = cos(5*2*pi*t);
%sig = sin(50.7*2*pi*t);
%sig = t.*(1-t);
%sig  = t;
%sig  = [0:1:(N/2-1),(N/2-1):-1:0]-N/4; 

% domain for signal
SD = 0:(N-1);

% define frequency domain and get DFT
FD = 0:(N-1);
 
fsig = fft(sig); 
% shift DFT and frequency domain
sfsig = fftshift(fsig);
FD = fftshift(SD);
N1 = FD(1);
FD(1:(N-N1))=  (N1-N):(-1);


%% display shifted signal and DFT use 
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(sfsig),'r.',FD,imag(sfsig),'g.')
title('shifted DFT of signal')
axis tight

%% display shifted magnitude and phase
figure(2)
subplot(2,1,1)
plot(FD, abs(sfsig),'r.' )
title('magnitude of shifted DFT')
axis tight
subplot(2,1,2)
plot(FD, angle(sfsig),'g.' )  
title('phase of shifted DFT')
axis tight







