        clear;
         clc;
        echo on;
%****************************************************************************
%*  DSP  student number1 : xxxxxxxx      name : xxxxxxxx         *
%*       student number2 : xxxxxxxx      name : xxxxxxxx                    *
%****************************************************************************
%
%
%                     Homework 2             DFT
%
               
%
%                       Project 2: Difficult DFTs
%
        pause;      % press any key continue.....
       

%
%               Exercise 2.1     Aliased Sinc Sequence
%

        pause;         %   press  any  key  continue
        clc

%
%                           Exercise 2.1.a
%               Generate a 7-point pulse width  and
%                                   compute its 16-point DFT
%

        pause;         %   press  any  key  continue
        echo off;
        %*** N=16 ***
        N=1:16;
        temp1=boxcar(7);
        temp0=zeros(1,9);
        xi=[temp1',temp0];
        n=N-1;
        DD=(fft(xi));

%       subplot(221),stem (n,abs(xi)),title('pulse_7 N=16')
%       subplot(222),stem (n,abs(DD)),title('DFT magnitude')
%       subplot(223),stem (n,abs(real(DD))),title('real')
%       subplot(224),stem (n,abs(imag(DD))),title('imag'),pause;

        pause;         %   press  any  key  continue

        echo off;
        subplot(221),stem (n,abs(xi)),title('pulse_7 N=16')
        subplot(222),stem (n,abs(DD)),title('DFT magnitude')
        subplot(223),stem (n,abs(real(DD))),title('real')
        subplot(224),stem (n,abs(imag(DD))),title('imag'),pause;
        echo on

        pause;         %   press  any  key  continue
        
        clc;

%
%                              Exercise 2.1.a
%               Generate a 7-point pulse width  and
%                                  computer its 21-point DFT   ( L = 9 )
%
        pause;         %   press  any  key  continue
        echo   off;
        %*** N=21 ***
        N=1:21;
        x1=boxcar(7);
        x2=zeros(1,14);
        xi=[x1',x2];
        n=N-1;
        XX=(fft(xi));

%       subplot(221),stem (n,abs(xi)),title('pulse_7 N=21')
%       subplot(222),stem (n,abs(XX)),title('DFT magnitude')
%       subplot(223),stem (n,abs(real(XX))),title('real')
%       subplot(224),stem (n,abs(imag(XX))),title('imag'),pause;

        pause;         %   press  any  key  continue

        echo off;
        subplot(221),stem (n,abs(xi)),title('pulse_7 N=21')
        subplot(222),stem (n,abs(XX)),title('DFT magnitude')
        subplot(223),stem (n,abs(real(XX))),title('real')
        subplot(224),stem (n,abs(imag(XX))),title('imag'),pause;
        echo on

        pause;         %   press  any  key  continue
     
        clc;
%
%                       Exercise 2.1.b
%            a0[n]=sin(9*pi*n/N)/sin(pi*n/N)
%                 Calculus N = 16 and N = 21 DFT              ( L = 9 )
%

        pause;         %   press  any  key  continue
        echo   off;

        %----------
        % part(b)
        %----------
        n=0:15;
        aa=asinc(2*pi*n/16,9);
        DD=(fft(aa));

%       subplot(221),stem (n,abs(aa)),title('asinc N=16')
%       subplot(222),stem (n,abs(DD)),title('DFT magnitude')
%       subplot(223),stem (n,abs(real(DD))),title('real')
%       subplot(224),stem (n,abs(imag(DD))),title('imag'),pause;

        pause;         %   press  any  key  continue

        echo off
        subplot(221),stem (n,abs(aa)),title('asinc N=16')
        subplot(222),stem (n,abs(DD)),title('DFT magnitude')
        subplot(223),stem (n,abs(real(DD))),title('real')
        subplot(224),stem (n,abs(imag(DD))),title('imag'),pause;
        echo on
        pause;
     
        clc;

%
%                       Exercise 2.1.c
%            a1[n]=sin(9*pi*(n+1)/N)/sin(pi*(n+1)/N)
%                 Calculus N = 16 and N = 21 DFT                ( L = 10 )
%

        pause;         %   press  any  key  continue
        echo   off;

        %-------------------
        %     part (c)
        %-------------------
        n=0:15;
        a1=asinc(2*pi*(n+1)/16,9);
        DD=(fft(a1));

%       subplot(221),stem (n,abs(a1)),title('Shifed asinc N=16')
%       subplot(222),stem (n,abs(DD)),title('DFT magnitude')
%       subplot(223),stem (n,abs(real(DD))),title('real')
%       subplot(224),stem (n,abs(imag(DD))),title('imag')

        pause;         %   press  any  key  continue

        echo off
        subplot(221),stem (n,abs(a1)),title('Shifed asinc N=16')
        subplot(222),stem (n,abs(DD)),title('DFT magnitude')
        subplot(223),stem (n,abs(real(DD))),title('real')
        subplot(224),stem (n,abs(imag(DD))),title('imag'),pause;
        echo on
        pause;

    
        clc;
        echo on;

%
%                         Exercise 2.1.d
%        When L = 10
%             Calculus the a0[n] and a1[n]
%                 a0[n]=sin(9*pi*n/N)/sin(pi*n/N)
%                 a1[n]=sin(9*pi*(n+1)/N)/sin(pi*(n+1)/N)
%

        pause;         %   press  any  key  continue
        echo  off, clc;

        %------------
        % part (d).
        %------------
        n=0:15;
        a0=asinc(2*pi*n/16,10);
        DD=(fft(a0));

%       subplot(221),stem (n,abs(a0)),title('asinc L=10')
%       subplot(222),stem (n,abs(DD)),title('DFT magnitude')
%       subplot(223),stem (n,abs(real(DD))),title('real')
%       subplot(224),stem (n,abs(imag(DD))),title('imag'), pause

        pause;         %   press  any  key  continue

        echo off;
        subplot(221),stem (n,abs(a0)),title('asinc L=10')
        subplot(222),stem (n,abs(DD)),title('DFT magnitude')
        subplot(223),stem (n,abs(real(DD))),title('real')
        subplot(224),stem (n,abs(imag(DD))),title('imag'), pause
        echo on
        pause;
       
        clc;

        n=0:15;
        a1=asinc(2*pi*(n+1)/16,10);
        DD=(fft(a1));

%       subplot(221),stem (n,abs(a1)),title('shifted asinc L=10')
%       subplot(222),stem (n,abs(DD)),title('DFT magnitude')
%       subplot(223),stem (n,abs(real(DD))),title('real')
%       subplot(224),stem (n,abs(imag(DD))),title('imag'), pause

        pause;         %   press  any  key  continue

        echo off;
        subplot(221),stem (n,abs(a1)),title('shifted asinc L=10')
        subplot(222),stem (n,abs(DD)),title('DFT magnitude')
        subplot(223),stem (n,abs(real(DD))),title('real')
        subplot(224),stem (n,abs(imag(DD))),title('imag'), pause
        echo on
        pause;         %   press  any  key  continue
        clc

%
%              Exercise 2.2     Impulse Train
%
        pause;         %   press  any  key  continue

        clc;
%
%       Exercise 2.2.a,b
%                A impulse there should be 22 zeros,
%                          expand it to 207 samples
%                              compute the 207-point DFT .
%
        pause;         %   press  any  key  continue
        clc;
        %--------------------------
        %  EXE 2.2   a.b
        %
        %  10000000000000000000000
        %---------------------------
        tmp0= zeros(22,1);
        tmp1 = [1];
        tmp_p = [tmp1 tmp0'];
        p = [];
        for i = 1:1:9;
           p = [p tmp_p];
        end
        n=1:207;
        DD=(fft(p));

%       subplot(211);stem(n,abs(p)),title(' 1 one 22 zeros')
%       subplot(212);stem(n,abs(DD)),title('FFT'),pause

        pause;         %   press  any  key  continue

        echo off
        subplot(211);stem(n,abs(p)),title(' 1 one 22 zeros')
        subplot(212);stem(n,abs(DD)),title('FFT'),pause
        echo on;
        pause;
      

%       subplot(212);stem(abs(DD(1:30))),title('detail of upper'), pause

        pause;         %   press  any  key  continue

        echo off
        subplot(212);stem(abs(DD(1:30))),title('detail of upper'), pause
        echo on;
        pause;         %   press  any  key  continue
        clc;

%
%       Exercise 2.2.c
%

        pause;         %   press  any  key  continue
        clc;
        %-----------------
        %    EXE 2.2 c
        %
        %    100000000
        %-----------------
        tmp0 = zeros(8,1);
        tmp1 = [1];
        tmp_p = [tmp1 tmp0'];
        p1= [];
        for i = 1:1:23;
           p1 = [p1 tmp_p];
        end
        % get 23 points from p1

        p1 = p1(1:23);

        DD=(fft(p1));

%       subplot(211);stem(abs(p1)),title(' 1 one 8 zeros')
%       subplot(212);stem(abs(real(DD))),title('FFT only show 30 points '), pause

        pause;         %   press  any  key  continue

        echo off;
        subplot(211);stem(abs(p1)),title(' 1 one 8 zeros')
        subplot(212);stem(abs(real(DD))),title('FFT only show 30 points '), pause
        echo on;
        pause;         %   press  any  key  continue
        clc;

%
%       Exercise 2.2.d
%                200 point DFT.
%

        pause;         %   press  any  key  continue
        clc;
        %------------------------------
        %      EXE 2.2  d
        % p2= get 200 points of 'p'
        %------------------------------

        p2=p(1:200);
        DD=(fft(p2));

%       subplot(211);stem(abs(p2)),title('200 points FFT')
%       subplot(212);stem(abs(DD)),title('FFT  '), pause

        pause;         %   press  any  key  continue

        echo off;
        subplot(211);stem(abs(p2)),title('200 points FFT')
        subplot(212);stem(abs(DD)),title('FFT  '), pause
        echo on;

        pause;
        
 %      subplot(212);stem(abs(DD(1:30))),title('detail of upper'),  pause

        pause;         %   press  any  key  continue

        echo off;
        subplot(212);stem(abs(DD(1:30))),title('detail of upper'), pause
        echo on;
        pause;         %   press  any  key  continue
        clc;
%
%       Exercise 2.2.e
%                414 and 621 point DFT
%
        pause;         %   press  any  key  continue
        clc;

        %----------------------
        %   EXE 2.2 e
        %  double the length
        %  207-> 414 and 621
        %----------------------

        DD = (fft(p,414));
%       subplot(211);stem(abs(real(DD))),title('414 points FFT');
%       subplot(212);stem(abs(DD(1:30))),title('detail of upper')

        pause;         %   press  any  key  continue

        echo off
        subplot(211);stem(abs(real(DD))),title('414 points FFT');
        subplot(212);stem(abs(DD(1:30))),title('detail of upper'), pause
        echo on

        pause;
       
        DD = (fft(p,621));

%       subplot(211);stem(abs(real(DD))),title('621 points FFT');
%       subplot(212);stem(abs(DD(1:30))),title('detail of upper')

        pause;         %   press  any  key  continue

        echo off
        subplot(211);stem(abs(real(DD))),title('621 points FFT');
        subplot(212);stem(abs(DD(1:30))),title('detail of upper'),pause
        echo on
        pause;
      
        clc

%
%       Exercise 2.2.f
%                1024 point DFT
%
        pause;         %   press  any  key  continue
        clc;
        %-------------------
        %  1024 point
        %-------------------
        DD = (fft(p,1024));

%       subplot(211);stem(abs(real(DD))),title('1024 points FFT');
%       subplot(212);stem(abs(DD(1:30))),title('detail of upper')

        pause;         %   press  any  key  continue

        echo off
        subplot(211);stem(abs(real(DD))),title('1024 points FFT');
        subplot(212);stem(abs(DD(1:30))),title('detail of upper'), pause
        echo on;
        pause;         %   press  any  key  continue
        clc, echo on;
%
%               Exercise 2.3     A Gaussian
%
        pause;         %   press  any  key  continue
        clc;
%
%       Exercise 2.3.a,b,c,d
%                Gaussian function and its DFT.
%
        pause;         %   press  any  key  continue
        clc;

        %------------
        % EXE 2.3
        %------------

        a = 0.5;
        L = floor(sqrt(100/a));

          for i = 1:1:(2*L+1);
            g(i) = exp(-1*a*((i-(L+1))^2));
          end;

        h1=g(1:14);
        h2=g(15:29);
        h=[h2, h1];


        DD=(fft(h,((2*L)+1)));

        n=-L:L;

%       subplot(221);stem(n,abs(h)),xlabel('N=29'),title(' Gaussian Signal a=0.5 ');
%       subplot(222);stem(n,abs(imag(DD))),title('        Image of N point DFT '),xlabel('N=29');
%       subplot(223);stem(n,abs(real(DD))),title('Real of N point DFT '),xlabel('N=29');
%       subplot(224);stem(n,abs(fftshift(DD))),title('FFTShift of N point DFT '),xlabel('N=29');

        pause;         %   press  any  key  continue

        echo off
        subplot(221);stem(n,abs(h)),title(' Gaussian Signal a=0.5 '),xlabel('N=29');
        %subplot(211);stem(n,abs(h)),title(' Gaussian Signal a=0.5 '),xlabel('N=29');
        %c
        subplot(222);stem(n,abs(imag(DD))),title('        Image of N point DFT '),xlabel('N=29');
        %subplot(212);stem(n,abs(imag(DD))),title('Image of N point DFT '),xlabel('N=29');
        %d
        subplot(223);stem(n,abs(real(DD))),title('Real of N point DFT '),xlabel('N=29');
        %subplot(211);stem(n,abs(real(DD))),title('Real of N point DFT '),xlabel('N=29');
        subplot(224);stem(n,abs(fftshift(DD))),title('FFTShift of N point DFT '),xlabel('N=29'), pause
        %subplot(212));stem(n,abs(fftshift(DD))),title('FFTShift of N point DFT ',xlabel('N=29');
        echo on
        pause;
       
        clc, echo on;
%
%       Exercise 2.3.e
%                Gaussian function with other a(alpha) value.
%
        pause;         %   press  any  key  continue
        clc;

        %------------------ a=0.2 -------------------------------
        a = 0.2;
        L = 14;
        for i = 1:1:(2*L+1);
          g(i) = exp(-1*a*((i-(L+1))^2));
        end;
        n=-L:L;
        DD=(fft(g));
%       subplot(211);stem(n,abs(g)),title(' Gaussian Signal a=0.2 ');
%       subplot(212);stem(n,abs(fftshift(DD))),title('FFTSHIFT the Real port of DFT ');

        pause;         %   press  any  key  continue

        echo off;
        subplot(211);stem(n,abs(g)),title(' Gaussian Signal a=0.2 ');
        subplot(212);stem(n,abs(fftshift(DD))),title('FFTSHIFT the Real port of DFT '), pause
        echo on;
        pause;
       
        %------------------- a=0.02 --------------------------------
        a = 0.02;

        for i = 1:1:(2*L+1);
          g(i) = exp(-1*a*((i-(L+1))^2));
        end;
        n=-L:L;
        DD=(fft(g));
%       subplot(211);stem(n,abs(g)),title(' Gaussian Signal a=0.02 ');
%       subplot(212);stem(n,abs(fftshift(DD))),title('FFTSHIFT the Real port of DFT ');

        pause;         %   press  any  key  continue

        echo off
        subplot(211);stem(n,abs(g)),title(' Gaussian Signal a=0.02 ');
        subplot(212);stem(n,abs(fftshift(DD))),title('FFTSHIFT the Real port of DFT '), pause
        echo on
        pause;
       

%컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴?
        echo on;
        clc;
%
%                                  Bye Bye
%
        pause  %          ...  Press any key continue ...
        clc, clear, echo on;
