% This script illustrates basic plotting functions for examining % windows used in DFT and spectral estimation. This script uses % the Tukey window as an example. Different windows have % may have other types of parameters, so code adjustments must be % made when inserting other window function into this script. % % written by Kevin D. Donohue (donohue@engr.uky.edu) Sept. 2007 % General window parameters wlen = 128; % Window length tind = (0:wlen-1)/wlen; % Normalized x-axis for plotting % Effective sampling frequency fs = wlen; % Tukey window parameters r1 = .2; % Percentage of taper to flat region r2 = .8; % Percentage of taper to flat region w1 = tukeywin(wlen,r1); w2 = tukeywin(wlen,r2); % Plot window in time figure(1) plot(tind,w1,'k--',tind,w2,'r:') legend({'r=.2', 'r=.8'}) xlabel('Normalized time index') ylabel('Amplitude') title('Comparison of windows in time') % Compute windowed spectra pd1 = fft(w1,8*wlen); % Take DFT pd2 = fft(w2,8*wlen); magpd1 = abs(pd1(1:4*wlen)*fs/wlen); % Take magnitude of postive frequencies (first half) magpd2 = abs(pd2(1:4*wlen)*fs/wlen); faxis = (0:4*wlen-1)/(4*wlen); % Normalized frequency axis (1 = Nyquist frequency) % Plot spectra on linear amplitude scale figure(2) plot(faxis,magpd1,'k--',faxis,magpd2,'r:') legend({'r=.2', 'r=.8'}) xlabel('Normalized frequency') ylabel('Linear Magnitude') title('Comparison of windows in Frequency Linear Scale') % Plot spectra on dB amplitude scale figure(3) plot(faxis,20*log10(magpd1),'k--',faxis,20*log10(magpd2),'r:') legend({'r=.2', 'r=.8'}) xlabel('Normalized frequency') ylabel('dB Magnitude') title('Comparison of windows in Frequency dB Scale')