% Filtering.m /digital filtering of noise lab
clear
rate = 22254; % sample rate in Hz
t = linspace(0,1,rate); % generate one seconds worth of samples
white = rand(1,rate); % one second's worth of random numbers
knee = input('Enter frequency in Hz for filtering or 0 to quit: ');
while knee ~= 0
disp('Calculating filter ...');
[B,A] = butter(4, 2*pi*knee); % low pass digital filter
[D,C] = butter(4, 2*pi*knee,'high'); % high pass digital filter
pink = filter(B,A,white);
blue = filter(D,C,white);
disp('White Noise');
sound(white,rate); % play white noise for user
pause(1);
disp('Pink Noise');
sound(pink,rate); % play pink noise for user
pause(1);
disp('Blue Noise');
sound(blue,rate); % play blue noise for user
pause(1);
knee = input('Enter frequency in Hz for filtering or 0 to quit: ');
end