clear all; clc; % Define number of bands numBands = 8; % Read in the sample %filename = 'NordwindSonne'; filename = 'aem2f010'; %[sample, sr] = audioread(filename); [sample, sr] = wavread([filename '.wav']); % Normalize sample = sample ./ (max(abs(sample))*1.1); %sound(sample, sr); % Time vector dt = 1/sr; t = 0:dt:(length(sample)*dt) - dt; % Setup 3x2 subplots ha = tight_subplot(3,2,0.1); % Plot input signal %figure(4) axes(ha(1)); plot(t, sample(:,1)); % xlabel('Time (s)'); ylabel('Amplitude'); title('Original Signal'); % Build an array of filtered samples filterOrder = 6; [bank, centralFreqs] = createFilterBank(sr, numBands, filterOrder); % Perform the Filtering for i = 1:numBands filteredSamples(:,i) = filter(bank(i), sample); end % Plot the largest and smallest bands % Low axes(ha(2)); plot(t, filteredSamples(:,1)); %xlabel('Time (s)'); ylabel('Amplitude'); title('Filtered Signal - Low'); % High axes(ha(3)); plot(t, filteredSamples(:,numBands)); % xlabel('Time (s)'); ylabel('Amplitude'); title('Filtered Signal - High'); % Rectify signal array filteredSamples = abs(filteredSamples); % Create Envelope Array by Running Filtered Samples through LP lpInit = fdesign.lowpass('N,F3db', 5, 400/(sr/2)); lpFilter = design(lpInit, 'butter'); for i = 1:numBands sampleEnvelopes(:,i) = filter(lpFilter, filteredSamples(:,i)); end % Plot Envelopes of largest and smallest bands % Low axes(ha(4)); plot(t, sampleEnvelopes(:,1)); % xlabel('Time (s)'); ylabel('Amplitude'); title(' Filtered Signal Envelope - Low'); % High axes(ha(5)); plot(t, sampleEnvelopes(:,numBands)); %xlabel('Time (s)'); ylabel('Amplitude'); title(' Filtered Signal Envelope - High'); % Generate Cosine waves for each band in the filter bank; for i = 1:numBands cosineBank(:,i) = cos(2*pi*centralFreqs(i)*t); end % Scramble bands scrambledBands = [ 1 2 3 4 5 6 7 8 ]; %scrambledBands = [ 1 2 6 5 4 3 7 8 ]; %scrambledBands = [ 8 7 6 5 4 3 2 1 ]; %amplifyBands = [ 1 1 1 1 1 1 1 1 ]; amplifyBands = [ 0 0 1 1 0 0 0 0 ]; % Amplitude modulate the samples using the cosine wave from scrambleBands for i = 1:numBands j = scrambledBands(i); modulatedSignals(:,i) = modulate(amplifyBands(i).*sampleEnvelopes(:,i), centralFreqs(j), sr); end % Add all the signals together to generate output signal %disp(size(modulatedSignals, 1)); %disp(size(modulatedSignals, 2)); %clear sum; outputSignal = sum(modulatedSignals, 2); axes(ha(6)); plot(t, outputSignal); title('Output Signal'); % Normalize the output signal %outputSignal = outputSignal * sqrt(max(outputSignal)) / sqrt(sum(outputSignal.^2)); outputSignal = outputSignal ./ (max(abs(outputSignal))*1.1); %disp(outputSignal); % Play the output signal (and boost volume back up) sound(outputSignal, sr); % Write the altered signal to a wav file %audiowrite('Cermh014Filtered.wav', outputSignal, sr); wavwrite(outputSignal, sr, [filename '_sim.wav']);