Skip to content

Instantly share code, notes, and snippets.

@robodhruv
Created March 26, 2018 15:55
Show Gist options
  • Save robodhruv/ea2847947bacbb67fb643b90db8717a5 to your computer and use it in GitHub Desktop.
Save robodhruv/ea2847947bacbb67fb643b90db8717a5 to your computer and use it in GitHub Desktop.
Generate the DTFT of Window Functions in FIR Filter Design
%% Discrete time Fourier Transform of FIR filters
% Generate the DTFT of Window Functions in FIR Filter Design. For a custom
% window, define the window function and use the following snippets as is.
% Written by Dhruv Ilesh Shah (dhruv.shah@iitb.ac.in)
clear all; close all;
N = 100;
k = -N:N;
hamming_window = 0.54 + (0.46 * cos(2*pi*k / (2 * N)));
bartlett_window = 1 - (abs(k) / N);
window = hamming_window;
L = 1000;
freq = pi * [-(L-1):L-1] / L;
dtft_win = zeros(size(freq, 2), 1);
for f = 1:size(freq, 2)
dtft_win(f) = window * get_dtft_vec(freq(f), N);
end
figure('Position', [100, 100, 1000, 500]);
subplot(1, 2, 1), plot(window);
title('Hamming Window');
subplot(1, 2, 2), plot(20 * log(abs(dtft_win)));
title('DTFT of Hamming Window');
ylabel('decibels'); set(gca, 'xtick', [])
window = bartlett_window;
L = 1000;
freq = pi * [-(L-1):L-1] / L;
dtft_win = zeros(size(freq, 2), 1);
for f = 1:size(freq, 2)
dtft_win(f) = window * get_dtft_vec(freq(f), N);
end
figure('Position', [100, 100, 1000, 500]);
subplot(1, 2, 1), plot(window);
title('Bartlett Window');
subplot(1, 2, 2), plot(20 * log(abs(dtft_win)));
title('DTFT of Bartlett Window');
ylabel('decibels'); set(gca, 'xtick', [])
function [dtft_vec] = get_dtft_vec(omega, n)
l = [-n:n]';
dtft_vec = exp(-1 * j * omega * l);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment