% ex92.m fn = input('Enter WAV filename : ','s'); [x,fs,nb] = wavread(fn); nx = length(x); % length of waveform w = hamming(1024); % hamming window nw = 1024; % length of window Ymean = zeros(1024,1); % vector to hold mean pos=1; cnt=0; while ((pos+nw) < nx) % while signal left y = x(pos:(pos+nw-1)).*w; % cut out window Y = fft(y,1024); % calculate FFT Ymean = Ymean + abs(Y); % update mean cnt = cnt+1; pos = pos+nw/2; % move to next window end fprintf('Found %d windows\n',cnt); if (cnt > 0) Ymean = 20*log10(Ymean/cnt+eps); % calculate mean Ymean = Ymean(1:512); % get lower Fs/2 f = (0:511)*fs/1024; % frequencies plot(f,Ymean); % plot average spectrum end