1 / 10

Elec 484 Final Project: Phase Vocoder

Elec 484 Final Project: Phase Vocoder. Matt Pierce. Initialization:. * Raised Cosine Function. * Magnitude and Phase Matrices. * Output Signal (Length is equal to the input times the rs/ra hopsize ratio). % Zero pad the input signal for hopsize

Download Presentation

Elec 484 Final Project: Phase Vocoder

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Elec 484 Final Project:Phase Vocoder Matt Pierce

  2. Initialization: * Raised Cosine Function * Magnitude and Phase Matrices * Output Signal (Length is equal to the input times the rs/ra hopsize ratio) % 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;

  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: * 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 % 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

  6. * Add unwrapped phase difference to the previous phase window % 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; * Reconstruct the signal using the complex exponential % 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 * Audio example 1: expanded (x 1.3) and compressed (x 0.7)

  7. Pitch Shifting: * First, time-stretch using previous algorithm * IFFT length then gets scaled by Ra/Rs. % 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 * 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 each windowed phase vector to zero and reconstruct % 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); * Audio example 3: robotization of drum beat Whisperization: * Set the phase to a random vector and reconstruct. % 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); * Audio example 4: whisperization of a flute tone

  9. Denoising: * Only use frequency bins with magnitudes above the noise gate threshold (found using maximum window values) % 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; * Audio example 5: denoised flute passage

  10. Stable/Transient Component Separation?: * Set “stability” range, then check phase difference values % Create an angle range value for determing whether to keep phase bins df = 0.001; % 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; 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

More Related