clear all
N =512; % N/2 is sindow width: long window good frequncy detail
                             % short window good time detail   
                             % try N=32 and N=512 
M=N; 
w = .42 - .5*cos(2*pi*(0:M-1)/(M-1)) ...
       + .08*cos(4*pi*(0:M-1)/(M-1));  %blackman window i.e. tight frame
   
w=w';

x=exp(i*(0:10000)/1.8)'/6;
L= length(x);
x=frft(x,-4.5) %Fractional Fourier
nframes=(L-M);

Xtwz = zeros(N,nframes);   %  STFT output array
M = length(w);       % M = window length, N = FFT length
zp =zeros(N-M,1) ;      % zero padding (to be inserted)
R=1;                    % translation: careul changing
M1=M/2;
xoff = 0;               %STARTING POINT


for m=1:nframes
  xt = x(xoff+1:xoff+M);% frame =chunk of signal length M
  xtw = w .* xt;         % multiply window by current frame
  xtwz = [xtw(M1+1:M); zp; xtw(1:M1)]; % windowed, z-padded
 Xtwz(:,m) = fft(xtwz); % STFT for frame m
  xoff = xoff +R;       % advance  by R
end;
colormap(hot)
figure(3)
clf
colormap(hot)
subplot(311);plot(w);xlabel('Blackman window')
subplot(312);plot(x);xlabel('noisy signal')
subplot(313);
imagesc(abs(Xtwz(3*N/4:N,:))); xlabel('noisy spectrogram')
Xtwzf(N/8:29*N/32,:)=0; % filter out tone may need to change for differen window lengths
figure(4)
clf
colormap(hot)
imagesc(abs(Xtwz(3*N/4:N,:))); xlabel('noisy Spectrogram')

wavwrite(x/2,11000,'armstrong.wav')


