%% listing 5.13
sr = 44100;
d = 1; % the duration of the noise (in sec)
noise = (rand(1, sr*d)*2)-1;
cutoff = 5000;
cutoffinsamples = cutoff * d;
filter = zeros(1, length(noise));
filter (1:cutoffinsamples)=1;
filter (end-cutoffinsamples:end)=1;
figure; subplot(2,1,1);
plot (filter);
axis([1 length(filter) -0.1 1.1]);
fnoise = noise .* filter;
subplot(2,1,2);
plot(20*log10(abs(fnoise)))

% play the listing
sound(noise, sr)
pause(2)

%% remaining command lines
fnoise = ifft(fnoise);
fnoise = real(fnoise);
fnoise = fnoise/max(abs(fnoise));
sound(fnoise, sr)