%% L11_Windowing %% ===================== %% Script to illustrate application of windows to reduce %% effect of frequency leakage in spectrum. %% %% Created : 19 Aug 2005 %% Modified : 19 Aug 2005 %% %% Copyright (c) 2005 Salman Durrani. %% ------------------------------------------------------------ clc clear all close all %% N-point DFT: Change value of N here N=64; %% periodic signal n = [0:1:N-1]; x = cos(2*pi.*n./6); %% Hamming window w = 0.5.*(1- cos(2*pi.*n./N)); %% modified periodic signal x_mod = x.*w; %% Calculate DFT X = fft(x_mod,N); magX = abs(X) %% Plot w[n] figure stem(n,w,'filled') xlabel('Sample n') ylabel('w[n]') title('Hamming Window') %% Plot x[n] and x_mod[n] figure stem(n,x,'filled') xlabel('Sample n') ylabel('x[n]') title('Original Signal: Fundamental Period') figure stem(n,x_mod,'filled') xlabel('Sample n') ylabel('x[n]') title('Windowed Signal: Fundamental Period') %% Plot DFT magnitude figure stem(n,magX,'filled') xlabel('Sample k') ylabel('|X[k]|') title('DFT Magnitude')