%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  Code for DSP Lecture of Dec. 29, 2007
%
%  Different parts are separated by "pause"
%   You need to press a key to proceed
%   to following part
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%% Hilbert Transform  Sec. 11.4
n= (0:127)*5e-3;
asig= 10.*exp(j*2*pi*30*n);
rsig= real(asig);
frsig= fftshift(fft(rsig));
figure(6);
subplot(2,2,1); plot(n, rsig);
subplot(2,2,2); plot(n, abs(frsig));
hsig= hilbert(rsig);
fhsig= fftshift(fft(hsig));
subplot(2,2,3); plot(n, real(hsig),'b', n, imag(hsig),'r');  
subplot(2,2,4); plot(n, abs(fhsig));
pause

%%%%%%% Time dependent Fourier Transform - Spectrogram Example
T= 5e-5;                % Sampling Step
N= 4096;
freq= 0:(N-1);           %Instantaneous frequency 
freq(1000:2000)=0;          %% done in lecture - we made the frequency of the middle part = 0
n= (0:(N-1))*T;          % Sampling points
sig= cos(2*pi*freq.*n);  % signal with time dependent frequency content
%sig(1000:1500)=1;
figure(5);
subplot(3,1,1); plot(sig);
fsig= fftshift(fft(sig));
subplot(3,1,2); plot(abs(fsig));
L= 128;
spectrogram= zeros(L*4,N-L);
for k1=1:N-L-1 
  s1= sig(k1:k1+L-1);    
  fs1= fftshift(fft(s1,L*4));
  spectrogram(:,k1)= abs(fs1);
end
subplot(3,1,3); imagesc(spectrogram); colormap(gray);xlabel('Time'); ylabel('Frequency');title('Spectrogram');
pause












