


     echo on
     clc

     %******************************************************
     %*         Student number: xxxxxxxx                   *
     %*         Student name  : xxxxxxxx xxxx              *
     %*         DSP homework2 : DFT properties             *
     %*         Due  day      :                            *
     %******************************************************


                          % Press any key to begin..........

     pause
     clc


    %*****************************************************
    %*   EXERCISE 3.3: DFT of a Real Sequence            *
    %*****************************************************

    %******** part(a) ********

     clg
     n=1:15;
     v=exp(-n/3);
     jv=j*exp(-n/3);
     V=fft(v);
     JV=fft(jv);
     pause
     clc


    %******** part(b) ********

     subplot(221)
     stem(n,real(v))
     title('REAL PART of v[n]'),xlabel('INDEX (n)')
     subplot(222)
     stem(n,imag(v))
     title('IMAG PART of v[n]'),xlabel('INDEX (n)')
     subplot(223)
     stem(n,real(V))
     title('REAL PART of DFT '),xlabel('INDEX (k)')
     subplot(224)
     stem(n,imag(V))
     title('IMAG PART of DFT '),xlabel('INDEX (k)'),pause
     clg
     mag_V=abs(V);
     pha_V=angle(V);
     subplot(211)
     stem(n,mag_V)
     title('magnitude of the DFT '),xlabel('INDEX (k)')
     subplot(212)
     stem(n,pha_V)
     title('phase of the DFT '),xlabel('INDEX (k)'),pause
     pause
     clc
     clg
     subplot(221)
     stem(n,real(jv))
     title('REAL PART of v[n]'),xlabel('INDEX (n)')
     subplot(222)
     stem(n,imag(jv))
     title('IMAG PART of v[n]'),xlabel('INDEX (n)')
     subplot(223)
     stem(n,real(JV))
     title('REAL PART of DFT '),xlabel('INDEX (k)')
     subplot(224)
     stem(n,imag(JV))
     title('IMAG PART of DFT '),xlabel('INDEX (k)'),pause
     clg
     mag_JV=abs(JV);
     pha_JV=angle(JV);
     subplot(211)
     stem(n,mag_JV)
     title('magnitude of the DFT '),xlabel('INDEX (k)')
     subplot(212)
     stem(n,pha_JV)
     title('phase of the DFT '),xlabel('INDEX (k)'),pause
     pause
     clc


    %******** part(c) ********

     iv=j*imag(v);
     IV=fft(iv);
     clg
     subplot(211)
     stem(n,V)
     title('The DFT of v[n]: V[k] '),xlabel('INDEX (k)')
     subplot(212)
     stem(n,IV)
     title('conjugate-antisymmetric of V[k] '),xlabel('INDEX (k)'),pause
     pause
     clc

    %******** part(d) ********

     m=-1:-1:-15;
     re_V=real(fft(v));
     re_jV=real(fft(conj(v)));
     Im_V=imag(fft(v));
     Im_jV=imag(conj(fft(conj(v))));

     clg
     subplot(122)
     stem(n,re_V)
     title(' Re{V[k]} '),xlabel('INDEX (k)')
     subplot(121)
     stem(m,re_jV)
     title(' Re{V[-k]} '),xlabel('INDEX (k)'),pause
     pause
     clc
     clg
     subplot(122)
     stem(n,Im_V)
     title(' Im{V[k]} '),xlabel('INDEX (k)')
     subplot(121)
     stem(m,Im_jV)
     title(' Im{V[-k]} '),xlabel('INDEX (k)'),pause
     pause
     clc

     Odd_re_V=(1/2)*(re_V-re_jV);
     Even_re_V=(1/2)*(re_V+re_jV);
     Odd_Im_V=(1/2)*(Im_V-Im_jV);
     Even_Im_V=(1/2)*(Im_V+Im_jV);
     clg
     subplot(211)
     stem(n,Odd_re_V)
     title(' Odd part of Re{V[k]} '),xlabel('INDEX (k)')
     subplot(212)
     stem(n,Even_re_V)
     title(' Even part of Re{V[k]} '),xlabel('INDEX (k)'),pause
     pause
     clc
     clg
     subplot(211)
     stem(n,Odd_Im_V)
     title(' Odd part of Im{V[k]} '),xlabel('INDEX (k)')
     subplot(212)
     stem(n,Even_Im_V)
     title(' Even part of Im{V[k]} '),xlabel('INDEX (k)'),pause
     pause
     clc


    %*****************************************************
    %*   EXERCISE 5.3: Stretch-Intersperse Zeros         *
    %*****************************************************

     t=1:40;
     u=1:10;
     x_40=zeros(size(t));
     x_10=rand(size(u));
     for k=0:1:9
         x_40(:,4*k+1)=x_10(:,k+1);
     end
     X_10=fft(x_10,10);
     X_40=fft(x_40,40);
     clg
     subplot(211)
     stem(u,X_10)
     title('The DFT of 10-point signal '),xlabel('INDEX (k)')
     subplot(212)
     stem(t,X_40)
     title('The DFT of 40-point signal '),xlabel('INDEX (k)'),pause
     pause
     clc


    %*****************************************************
    %*   EXERCISE 5.4: Decimation                        *
    %*****************************************************

    %******** part(a) ********

     v=1:1:60;
     w=1:1:30;
     for k=1:1:60
         x_60(:,k)=sin(((2*pi)/5)*k);
     end
     for k=1:1:30
         x_30(:,k)=x_60(:,2*k-1);
     end
     X_60=fft(x_60,60);
     X_30=fft(x_30,30);
     clg
     subplot(211)
     stem(v,X_60)
     title(' DFT of 60-point signal '),xlabel('INDEX (k)')
     subplot(212)
     stem(w,X_30)
     title(' DFT of 30-point signal '),xlabel('INDEX (k)'),pause
     pause
     clc

    %******** part(b) ********

     s=1:1:20;
     for k=1:1:20
         x_20(:,k)=x_60(:,2*k-1);
     end
     X_20=fft(x_20,20);
     clg
     subplot(211)
     stem(v,X_60)
     title(' DFT of 60-point signal '),xlabel('INDEX (k)')
     subplot(212)
     stem(s,X_20)
     title(' DFT of 20-point signal '),xlabel('INDEX (k)'),pause
     pause
     clc


    %******** part(c) ********

     r=1:1:9;
     for k=1:1:9
         x_9(:,k)=x_60(:,7*k-6);
     end
     X_9=fft(x_9,9);
     clg
     subplot(211)
     stem(v,X_60)
     title(' DFT of 60-point signal '),xlabel('INDEX (k)')
     subplot(212)
     stem(r,X_9)
     title(' DFT of 9-point signal '),xlabel('INDEX (k)'),pause
     pause
     clc
     clg
     subplot(221)
     stem(v,X_60)
     title(' DFT of 60-point signal '),xlabel('INDEX (k)')
     subplot(222)
     stem(w,X_30)
     title(' DFT of 30-point signal '),xlabel('INDEX (k)')
     subplot(223)
     stem(s,X_20)
     title(' DFT of 20-point signal '),xlabel('INDEX (k)')
     subplot(224)
     stem(r,X_9)
     title(' DFT of  9-point signal '),xlabel('INDEX (k)'),pause
     pause
     clc

     clg
     subplot(221)
     stem(v,real(X_60))
     title(' 60-point signal:Real part '),xlabel('INDEX (k)')
     subplot(222)
     stem(w,real(X_30))
     title(' 30-point signal:Real part '),xlabel('INDEX (k)')
     subplot(223)
     stem(s,real(X_20))
     title(' 20-point signal:Real part '),xlabel('INDEX (k)')
     subplot(224)
     stem(r,real(X_9))
     title(' 9-point signal:Real part '),xlabel('INDEX (k)'),pause
     pause
     clc
     clg
     subplot(221)
     stem(v,imag(X_60))
     title(' 60-point signal:Imag part '),xlabel('INDEX (k)')
     subplot(222)
     stem(w,imag(X_30))
     title(' 30-point signal:Imag part '),xlabel('INDEX (k)')
     subplot(223)
     stem(s,imag(X_20))
     title(' 20-point signal:Imag part '),xlabel('INDEX (k)')
     subplot(224)
     stem(r,imag(X_9))
     title(' 9-point signal:Imag part '),xlabel('INDEX (k)'),pause
     pause
     end

