Presentation is loading. Please wait.

Presentation is loading. Please wait.

Elec 484 Final Project: Phase Vocoder Matt Pierce.

Similar presentations


Presentation on theme: "Elec 484 Final Project: Phase Vocoder Matt Pierce."— Presentation transcript:

1 Elec 484 Final Project: Phase Vocoder Matt Pierce

2 Initialization: % Zero pad the input signal for hopsize numWindows = ceil(length(x)/(ra_hop)); numSamples = numWindows*(ra_hop); x = [x zeros(1, (numSamples - length(x)))]; % Create the raised cosine function rcos_win = 1/2*(1-cos(2*pi*(1:win)/win)); % Create matrices to store fft windows (mag and phase) over time fft_mag_matrix = zeros(numWindows, win); fft_phase_matrix = zeros(numWindows, win); % Initialize output signal y = zeros(1, ceil(length(x)*(rs_hop/ra_hop))+win); % A variable to keep track of the rs_hop index (n keeps track of the ra_hop index) m = 1; * Magnitude and Phase Matrices * Raised Cosine Function * Output Signal (Length is equal to the input times the rs/ra hopsize ratio)

3 Analysis: * Partition signal, window segment, circular shift (time domain), take FFT, and store matrix values for n=1:ra_hop:length(x)-win % Partition the signal into size win x_i = x(n:n+win-1); % Piecewise multiply the input segment with the cosine function x_rcos = x_i.* rcos_win; % Perform a circular shift on the time domain segment x_rcos_shft = circshift(x_rcos, [0, win/2]); % Take the fft of the windowed input Y_rcos_shft = fft(x_rcos_shft); % Store the magnitude and phase of this fft window in matrices mag = abs(Y_rcos_shft); fft_mag_matrix(floor(n/ra_hop)+1, 1:win) = mag; phase = angle(Y_rcos_shft); fft_phase_matrix(floor(n/ra_hop)+1, 1:win) = phase;...

4 Resynthesis: * Take IFFT, circular shift back, and overlap-add the output... % Find the time domain output (still shifted) using ifft y_rcos_shft = ifft(Y_rcos_shft); % “Unshift” the segment y_rcos = circshift(y_rcos_shft, [0, -win/2]); % Get the length value len = length(y_rcos); % Overlap add the output y(m:m+len-1) = y(m:m+len-1) + y_rcos; % Increment the resynthesis hopsize index m = m + rs_hop; end

5 Time Stretching: % Time-Stretch the phase using the phase matrix windows if(n>1) % Find the omega-phase values phase_hat = omega*(floor(n/ra_hop)+1) + phase; % Create the princarg difference vector argument princarg_vector = phase_hat - target_phase - omega*n; % Allocate space for each new princarg_out vector princarg_out = zeros(1, length(princarg_vector)); % Determine the princarg output value for i=1:length(princarg_vector) princarg_out(i) = mod(princarg_vector(i)+pi, -2*pi) + pi; end * Set variables for phase unwrapping / difference vector % Create the omega value for unwrapping the phase omega = 2*pi*(0:win-1)/win; if(n==1) % Set the initial phase window vectors for the first pass last_phase_win = phase; target_phase = phase + omega*n; end * Find the difference vector by taking princarg of the phase slope

6 % Get the new, unwrapped phase difference values unwrapped_phase_diff = (omega*n + princarg_out).*(rs_hop/ra_hop); new_phase_win = unwrapped_phase_diff + last_phase_win; % Set the updated target_phase and last_phase_win values target_phase = phase + omega*n; last_phase_win = new_phase_win; * Add unwrapped phase difference to the previous phase window % Get the altered frequency domain window segment Y_rcos_shft = mag.* exp(j*new_phase_win); % Add the altered vector back into the phase matrix fft_phase_matrix(floor(n/ra_hop)+1, 1:win) = angle(Y_rcos_shft); end * Reconstruct the signal using the complex exponential * Audio example 1: expanded (x 1.3) and compressed (x 0.7)

7 Pitch Shifting: % Create a vector with the proper resampling length as given by the % resampling factor (zero pad if necessary) if( ra_hop <= rs_hop ) Y_rcos_shft = Y_rcos_shft(1:ceil(win*(ra_hop/rs_hop))); elseif( ra_hop > rs_hop ) pad_len = ceil(win*(ra_hop/rs_hop)) - win; Y_rcos_shft = [Y_rcos_shft, zeros(1, pad_len)]; end * IFFT length then gets scaled by Ra/Rs. * First, time-stretch using previous algorithm * Finally, “resample” by using the analysis hop-size (n) to reconstruct the signal % Overlap add the output y(n:n+len-1) = y(n:n+len-1) + y_rcos; * Audio example 2: pitch shift up (x 1.5) and down (x 0.5)

8 Robotization: % Set all phase values to zero to create Robotization effect phase = zeros(1, length(Y_rcos_shft)); fft_phase_matrix(floor(n/ra_hop)+1, 1:win) = phase; % Recombine the fft with the zeroed phase values Y_rcos_shft = mag.* exp(j*phase); * Set each windowed phase vector to zero and reconstruct * Audio example 3: robotization of drum beat Whisperization: % Set the phase to random values to create the whisperization effect phase = rand(1, length(Y_rcos_shft)); fft_phase_matrix(floor(n/ra_hop)+1, 1:win) = phase; % Get the altered frequency domain window segment Y_rcos_shft = mag.* exp(j*phase); * Set the phase to a random vector and reconstruct. * Audio example 4: whisperization of a flute tone

9 Denoising: % Create a noise gate threshold from the maximum magnitude r = max(abs(Y_rcos_shft)); NT = r/(r+0.1); % Remove frequency bins with magnitudes below the noise gate threshold Y_rcos_shft(abs(Y_rcos_shft)<NT) = 0; * Only use frequency bins with magnitudes above the noise gate threshold (found using maximum window values) * Audio example 5: denoised flute passage

10 Stable/Transient Component Separation?: % Create an angle range value for determing whether to keep phase bins df = 0.001; * Set “stability” range, then check phase difference values % Get the new, unwrapped phase difference valuesunwrapped_phase_diff = (omega*n + princarg_out).*(rs_hop/ra_hop); new_phase_win = unwrapped_phase_diff + last_phase_win; if(n>1+win) if(sep_flag==1) % Before reconstructing the signal, dispose of any unstable % phase values (those not in the df range) for k=1:length(new_phase_win) if(abs(new_phase_win(k)-2*last_phase_win(k)+two_back(k))>df) new_phase_win(k) = 0; end end else % Before reconstructing the signal, dispose of any stable % phase values (those in the df range) for k=1:length(new_phase_win) if(abs(new_phase_win(k)-2*last_phase_win(k)+two_back(k))<df) new_phase_win(k) = 0; end end end end * Audio example 6: transient separation and isolation


Download ppt "Elec 484 Final Project: Phase Vocoder Matt Pierce."

Similar presentations


Ads by Google