You are on page 1of 2

% Program 3_1 % Discrete-Time Fourier Transform Computation % % Read in the desired length of DFT k = input('Number of frequency points = ');

% Read in the numerator and denominator coefficients num = input('Numerator coefficients = '); den = input('Denominator coefficients = '); % Compute the frequency response w = 0:pi/k:pi; h = freqz(num, den, w); % Plot the frequency response subplot(2,2,1) plot(w/pi,real(h));grid title('Real part') xlabel('\omega/\pi'); ylabel('Amplitude') subplot(2,2,2) plot(w/pi,imag(h));grid title('Imaginary part') xlabel('\omega/\pi'); ylabel('Amplitude') subplot(2,2,3) plot(w/pi,abs(h));grid title('Magnitude Spectrum') xlabel('\omega/\pi'); ylabel('Magnitude') subplot(2,2,4) plot(w/pi,angle(h));grid title('Phase Spectrum') xlabel('\omega/\pi'); ylabel('Phase, radians')

% Program 3_2 % Illustration of DFT Computation % % Read in the length N of sequence and the desired % length M of the DFT N = input('Type in the length of the sequence = '); M = input('Type in the length of the DFT = '); % Generate the length-N time-domain sequence u = [ones(1,N)]; % Compute its M-point DFT U = fft(u,M); % Plot the time-domain sequence and its DFT t = 0:1:N-1; stem(t,u) title('Original time-domain sequence') xlabel('Time index n'); ylabel('Amplitude') pause subplot(2,1,1) k = 0:1:M-1; stem(k,abs(U)) title('Magnitude of the DFT samples') xlabel('Frequency index k'); ylabel('Magnitude') subplot(2,1,2) stem(k,angle(U)) title('Phase of the DFT samples') xlabel('Frequency index k'); ylabel('Phase')

% Program 3_3 % Illustration of IDFT Computation % % Read in the length K of the DFT and the desired % length N of the IDFT K = input('Type in the length of the DFT = '); N = input('Type in the length of the IDFT = '); % Generate the length-K DFT sequence k = 1:K; U = (k-1)/K; % Compute its N-point IDFT u = ifft(U,N); % Plot the DFT and its IDFT k=1:K; stem(k-1,U) xlabel('Frequency index k'); ylabel('Amplitude') title('Original DFT samples') pause subplot(2,1,1) n = 0:1:N-1; stem(n,real(u)) title('Real part of the time-domain samples') xlabel('Time index n'); ylabel('Amplitude') subplot(2,1,2) stem(n,imag(u)) title('Imaginary part of the time-domain samples') xlabel('Time index n'); ylabel('Amplitude')

You might also like