Code:
x = [1, 1, 1, 1, zeros (1,4)]; N = 8; % zero-padding Operation x_dft = DFT (x,n); % DFT of x (n) magx_dft = ABS (X_DFT) phax_dft = Angle (x_dft) *180/pi% DEGREESREALX_DFT = Real (X_DFT); IMAGX_DFT = Imag (X_DFT); angx_dft = angle (X_DFT); % RADIASN = 0: (N-1); k = 0:1000; W = (pi/500) *k; % [0,2PI] axis divided into 501 points.%k = 0:500; W = (pi/500) *k; % [0,PI] axis divided into 501 points. X_DTFT = x * (exp (-j*pi/500)). ^ (n ' *k); % DTFT of x (n) magx_dtft = ABS (X_DTFT); Angx_dtft = Angle (X_DTFT); Realx_dtft = Real (X_DTFT); Imagx_dtft = Imag (X_DTFT); figure (' Numbertitle ', ' off ', ' Name ', ' Exameple5.7 × Sequence ') set (GCF, ' Color ', ' white '); Stem (n,x); Title (' x sequence '); Axis ([0,n,-0.5,1.5]); Xlabel (' N '); Ylabel (' x (n) '); Grid on;%%--------------------------------------------------------------percent START X_dtft ' s mag ang real imag%%--------------------------------------------------------------figure (' Numbertitle ', ' off ', ' Name ', ' x_dtft its Magnitude and Angle, Real and Imaginary part '); set (GCF, ' Color ', ' white '); Subplot (2,2,1); Plot (W/PI,MAGX_DTFT); Grid on; % axis ([ -2,2,0,15]); Title (' Magnitude part '), Xlabel (' Frequency in \pi units '); Ylabel (' Magnitude | X\_dtft| '); Subplot (2,2,3); Plot (W/pi, angx_dtft*180/pi); Grid on; % axis ([ -2,2,-1,1]); title (' Angle part '), Xlabel (' Frequency in \pi units '); Ylabel (' Degrees '); %axis ([ -200,200,0,2]); subplot (' 2,2,2 '); Plot (W/pi, REALX_DTFT); Grid On;title (' Real part '), Xlabel (' Frequency in \pi units '); Ylabel (' Real '); subplot (' 2,2,4 '); Plot (W/pi, IMAGX_DTFT); Grid On;title (' Imaginary part '), Xlabel (' Frequency in \pi units '); Ylabel (' imaginary '); percent--------------------------------------------------------------percent END x_dtft ' mag ang real imag%%----------------------------------------------------------------------------------------------------------------------------percent START x_dft ' s mag ang real imag%%------------------------------------------ --------------------figure (' Numbertitle ', ' off ', ' Name ', ' Example5.7 x_dft its Magnitude and Angle '); set (GCF, ' Color ', ' White '); Subplot (2,1,1); Stem (N,MAGX_DFT); Hold on; Plot (4*w/pi,magx_dtft, '--'); Hold Off;grid on; Axis ([ -0.5,8.2,-1,5]); Title (' Magnitude part of the DFT:N = 8 '); Xlabel (' K '); Ylabel (' Magnitude | X\_dft| '); Subplot (2,1,2); Stem (n, phax_dft); Hold on; Plot (4*w/pi,angx_dtft*180/pi, '--'); Hold Off;grid on; Axis ([ -0.5,8.2,-200,200]); title (' Angle part of the DFT:N = 8 '); Xlabel (' K '); Ylabel (' Degrees '); %axis ([ -200,200,0,2]);%subplot (' 2,2,2 '); Stem (n, realx_dft); Grid On;%title (' Real part '),%xlabel (' Frequency in \pi units '); Ylabel (' Real ');%subplot (' 2,2,4 '); Stem (n, imagx_dft); Grid On;%title (' Imaginary part '),%xlabel (' Frequency in \pi units '); Ylabel (' imaginary '); percent--------------------------------------------------------------% END X_dft ' sMag Ang Real imag%%--------------------------------------------------------------
Results:
12 zeros At the end of the sequence, up to 16 bits in length
Code:
x = [1, 1, 1, 1, zeros (1,12)]; % append zeros to the end of X (n) n = 16; % zero-padding Operation x_dft = DFT (x,n); % DFT of x (n) magx_dft = ABS (X_DFT) phax_dft = Angle (x_dft) *180/pi% DEGREESREALX_DFT = Real (X_DFT); IMAGX_DFT = Imag (X_DFT); angx_dft = angle (X_DFT); % RADIASN = 0: (N-1); k = 0:1000; W = (pi/500) *k; % [0,2PI] axis divided into 501 points.%k = 0:500; W = (pi/500) *k; % [0,PI] axis divided into 501 points. X_DTFT = x * (exp (-j*pi/500)). ^ (n ' *k); % DTFT of x (n) magx_dtft = ABS (X_DTFT); Angx_dtft = Angle (X_DTFT); Realx_dtft = Real (X_DTFT); Imagx_dtft = Imag (X_DTFT); figure (' Numbertitle ', ' off ', ' Name ', ' Exameple5.7 × Sequence ') set (GCF, ' Color ', ' white '); Stem (n,x); Title (' x sequence, N = 16 '); Axis ([0,n,-0.5,1.5]); Xlabel (' N '); Ylabel (' x (n) '); Grid on;%%--------------------------------------------------------------percent START X_dtft ' s mag ang real imag%%-------------- ------------------------------------------------figure (' Numbertitle ', ' off ', ' Name ', ' x_dtft its Magnitude and Angle, Real and imaginary part '); set (GCF, ' Color ', ' white '); Subplot (2,2,1); Plot (W/PI,MAGX_DTFT); Grid on; % axis ([ -2,2,0,15]); Title (' Magnitude part '), Xlabel (' Frequency in \pi units '); Ylabel (' Magnitude | X\_dtft| '); Subplot (2,2,3); Plot (W/pi, angx_dtft*180/pi); Grid on; % axis ([ -2,2,-1,1]); title (' Angle part '), Xlabel (' Frequency in \pi units '); Ylabel (' Degrees '); %axis ([ -200,200,0,2]); subplot (' 2,2,2 '); Plot (W/pi, REALX_DTFT); Grid On;title (' Real part '), Xlabel (' Frequency in \pi units '); Ylabel (' Real '); subplot (' 2,2,4 '); Plot (W/pi, IMAGX_DTFT); Grid On;title (' Imaginary part '), Xlabel (' Frequency in \pi units '); Ylabel (' imaginary '); percent--------------------------------------------------------------percent END x_dtft ' mag ang real imag%%--------------------------------------------------------------percent--------------------------------------------------------------percent START X_dft ' s mag ang real imag%%--------------------------------------------------------------figure (' Numbertitle ', ' off ', ' Name ', ' Example5.7 x_dft its Magnitude and Angle '); set (GCF, ' Color ', ' white '); Subplot (2,1,1); Stem (N,MAGX_DFT); Hold on; Plot (8*w/pi,magx_dtft, '--'); Hold Off;grid on; Axis ([ -0.5,16.2,-1,5]); Title (' Magnitude part of the DFT:N = + '); Xlabel (' K '); Ylabel (' Magnitude | X\_dft| '); Subplot (2,1,2); Stem (n, phax_dft); Hold on; Plot (8*w/pi,angx_dtft*180/pi, '--'); Hold Off;grid on; Axis ([ -0.5,16.2,-200,200]); title (' Angle part of the DFT:N = + '); Xlabel (' K '); Ylabel (' Degrees '); %axis ([ -200,200,0,2]);%subplot (' 2,2,2 '); Stem (n, realx_dft); Grid On;%title (' Real part '),%xlabel (' Frequency in \pi units '); Ylabel (' Real ');%subplot (' 2,2,4 '); Stem (n, imagx_dft); Grid On;%title (' Imaginary part '),%xlabel (' Frequency in \pi units '); Ylabel (' imaginary ');--------------------------------------------------------------percent END x_dft ' s mag ang real imag%%----------------------------- ---------------------------------
Results:
Continue to fill 0, length n=128,
Code:
x = [1, 1, 1, 1, zeros (1,124)]; % append 124 zeros to the end of X (n) n = 128; % zero-padding Operation x_dft = DFT (x,n); % DFT of x (n) magx_dft = ABS (X_DFT) phax_dft = Angle (x_dft) *180/pi% DEGREESREALX_DFT = Real (X_DFT); IMAGX_DFT = Imag (X_DFT); angx_dft = angle (X_DFT); % RADIASN = 0: (N-1); k = 0:1000; W = (pi/500) *k; % [0,2PI] axis divided into 501 points.%k = 0:500; W = (pi/500) *k; % [0,PI] axis divided into 501 points. X_DTFT = x * (exp (-j*pi/500)). ^ (n ' *k); % DTFT of x (n) magx_dtft = ABS (X_DTFT); Angx_dtft = Angle (X_DTFT); Realx_dtft = Real (X_DTFT); Imagx_dtft = Imag (X_DTFT); figure (' Numbertitle ', ' off ', ' Name ', ' Exameple5.7 × Sequence ') set (GCF, ' Color ', ' white '); Stem (n,x); Title (' x sequence, N = 128 '); Axis ([0,n,-0.5,1.5]); Xlabel (' N '); Ylabel (' x (n) '); Grid on;%%--------------------------------------------------------------percent START X_dtft ' s mag ang real imag%%------------ --------------------------------------------------figure (' Numbertitle ', ' off ', ' Name ', ' x_dtft its Magnitude and Angle, Real and Imaginary part '); set (GCF, ' Color ', ' white '); Subplot (2,2,1); Plot (W/PI,MAGX_DTFT); Grid on; % axis ([ -2,2,0,15]); Title (' Magnitude part '), Xlabel (' Frequency in \pi units '); Ylabel (' Magnitude | X\_dtft| '); Subplot (2,2,3); Plot (W/pi, angx_dtft*180/pi); Grid on; % axis ([ -2,2,-1,1]); title (' Angle part '), Xlabel (' Frequency in \pi units '); Ylabel (' Degrees '); %axis ([ -200,200,0,2]); subplot (' 2,2,2 '); Plot (W/pi, REALX_DTFT); Grid On;title (' Real part '), Xlabel (' Frequency in \pi units '); Ylabel (' Real '); subplot (' 2,2,4 '); Plot (W/pi, IMAGX_DTFT); Grid On;title (' Imaginary part '), Xlabel (' Frequency in \pi units '); Ylabel (' imaginary '); percent--------------------------------------------------------------percent END x_dtft ' mag ang real imag%%--------------------------------------------------------------percent--------------------------------------------------------------percent START X_dft ' s mag ang real imag%%--------------------------------------------------------------figure (' Numbertitle ', ' off ', ' Name ', ' Example5.7 x_dft its Magnitude and Angle '); set (GCF, ' Color ', ' white '); Subplot (2,1,1); Stem (N,MAGX_DFT); Hold on; Plot (64*w/pi,magx_dtft, '--'); Hold Off;grid on; Axis ([ -0.5,128.2,-1,5]); Title (' Magnitude part of the DFT:N = "); Xlabel (' K '); Ylabel (' Magnitude | X\_dft| '); Subplot (2,1,2); Stem (n, phax_dft); Hold on; Plot (64*w/pi,angx_dtft*180/pi, '--'); Hold Off;grid on; Axis ([ -0.5,128.2,-200,200]); title (' Angle part of the DFT:N = "); Xlabel (' K '); Ylabel (' Degrees '); %axis ([ -200,200,0,2]);%subplot (' 2,2,2 '); Stem (n, realx_dft); Grid On;%title (' Real part '),%xlabel (' Frequency in \pi units '); Ylabel (' Real ');%subplot (' 2,2,4 '); Stem (n, imagx_dft); Grid On;%title (' Imaginary part '),%xlabel (' Frequency in \pi units '); Ylabel (' imaginary ');--------------------------------------------------------------percent END x_dft ' s mag ang real imag%%--------------------- -----------------------------------------
Operation Result:
"DSP using MATLAB" Example Example5.7