function [out1]=fDecandRec()

%% Read the SOI from a wavefile
desiredspeaker =1;

if desiredspeaker==1
    [SOI,Fs]=wavread('data\speech_dft.wav'); %SOI from wave files
else
    [SOI,Fs]=wavread('data\LoopyMusic.wav'); %SOI from wave files
end
soundsc(SOI,Fs); %play the sound so we can hear it
pause(3)
array_sig=SOI.'; %Transpose so it is a row vector (later each array signal will be  in a row vector)
siglength = size(array_sig,2);

%% All positive frequency bins (1/2 of all bins)
FFT_len=256;
%freq_bins=(0:FFT_len/2-1)/FFT_len*Fs; %Half of the FFT bins. This is for positive freqs.

%% Perform overlapping windows
overlapFlag=1;
if overlapFlag==1
    frame_len=FFT_len;
    overlap=frame_len/2; %Overlap at 50%!!
    total_num=fix(siglength/(frame_len-overlap)); %Number of frames with overlap
else
    frame_len=FFT_len; %No overlap
    total_num=fix(siglength/frame_len); %Number of frames
end

%% Hamming window
N_array_els = 1; %We are processing a single signal
ham_win=ones(N_array_els,1)*hamming(frame_len)';

out1=zeros(1,total_num*(frame_len-overlap));%vector store beamformer output.

%% For all frames in the file
  for i_frame=1:total_num-1 %Loop for all frames
      %short frame processing
      cur_data=zeros(N_array_els,FFT_len);%matrix store current frame data
      if overlapFlag==1 %Overlap and hamming window!!
         framestart_circ=(i_frame-1)*(frame_len-overlap)+1;
         frameend_circ  =(i_frame-1)*(frame_len-overlap)+frame_len;

         cur_data(:,1:frame_len)=ham_win.*array_sig(:,framestart_circ:frameend_circ);
      else %No overlap and no hamming window!!
         framestart=(i_frame-1)*frame_len+1;
         frameend  =i_frame*frame_len;
         cur_data=array_sig(:,framestart:frameend);
      end

      %Frequency data of current frame, row:elements, col:freq_bins
      F_cur_data=(fft(cur_data.',FFT_len)).';%note, in Matlab FFT is done to the column vector.

      F_out1=zeros(1,FFT_len);

      %Perform narrow-band beamforming at each positive frequency bin except the first (DC)
      v1 = zeros(1,FFT_len/2);
      %% For all positive frequency bins in a single frame
      for m=2:FFT_len/2
          v1(m)=1; %Do nothing with the fbin signal
          F_out1(m)=v1(:,m)'*F_cur_data(:,m); %DS beamformer
      end

      for m=1:FFT_len/2
          F_out1(FFT_len-m+1)=conj(F_out1(m+1));%make its IFFT real
      end

      %% Assemble the output.
      temp1=ifft(F_out1,FFT_len);
      temp1=real(temp1);
      if overlapFlag==1 %Overlap and hamming window!!
          out1(framestart_circ:frameend_circ)=out1(framestart_circ:frameend_circ)+temp1(1:frame_len);
      else
          disp('Not implemented for not overlap');
          keyboard;
      end
  end %for i_frame=1:total_num-1 %For all the frames do
soundsc(out1,Fs); 
pause(1)

%% Not implemented
%for i_freqbins=minfbinsindx:length(freq_bins) %For each frequency bin (why starting at i_freqbins=2?>>No DC)
%end%for
%% Write wave
wavwrite(out1,Fs,32,'data\out1.wav');

end %function