function e = plotfft(in,sampleRate); % % This function computes the FFT of an input and plots it on a easy to read plot. The function also % provides hamming squared windowing on the input data to reduce spectral splatter at the edges of the % block of input data. % % Kreeger Research LLC % Copyright (c) 2009 % MIN_dB = -120; % minimum of 120 db below 0dB; win = hanning(length(in))'; %win = hamming(length(in))'; winsq = win.*win; bb = in.*winsq; c = fft(bb); if nargin < 2 sampleRate = 1.0; end l = floor(length(in)/2)+1; idx = [[l+1:length(in)] [1:l]]; c = c(idx); %normalize d = 10*log10(c.*conj(c)); e = d - max(d); % trim to MIN x = find(e < MIN_dB); %trim to MIN_db e(x) = MIN_dB; if(mod(length(in),2)==0) t = (1:length(in))/length(in) - 0.5; % works for even input lengths else t = linspace(-0.5,0.5,length(in));; % works for odd input lengths end plot(t*sampleRate,e); grid on; xlabel('fs'); ylabel('dB'); title(['Normalized Frequency Plot (peak= ' int2str(max(d)) 'dB)'])