shuffling phases of fft when length is odd

4 vues (au cours des 30 derniers jours)
L
L le 10 Août 2023
Réponse apportée : Dhruv le 31 Août 2023
I need to make an audio signal unrecognizable but maintain its rms value. I tought about randomizing the phases. However, my code only works when the lenght of my signal is even. I don't know how to make this work when signal length is odd.
[y,Fs] = audioread('S106.wav');
X = y';
soundsc(y,Fs); pause(1);
[ch,nfft]=size(X); % ch is channels (2 if sterio), nfft is the lenght of the signal.
Y=fft(X,nfft,2); % Get spectrum
% Add random phase shifts (negative for conjugates), preserve DC offset
rnd_theta= -pi + (2*pi).*rand(ch,nfft/2-1);
Y(:,2:nfft/2)=Y(:,2:nfft/2).*exp(1i*rnd_theta);
Y(:,nfft/2+2:nfft)=Y(:,nfft/2+2:nfft).*exp(-1i*flip(rnd_theta,2));
% return phase-randomized data
randX =ifft(Y,nfft,2);
newy = randX.';
soundsc(newy,Fs);pause(1);
error = rms(y) - rms(newy); % this error should be very small

Réponse acceptée

Dhruv
Dhruv le 31 Août 2023
When dealing with odd-length signals in the context of phase randomization using the FFT, the key is to handle the center frequency (Nyquist frequency) bin differently.
Try following these steps to effectively handle odd-length signals:
  • Split the Signal into Even and Odd Parts: If the signal length is odd ("nfft" is odd), divide it into two parts: one even-length part and one odd-length part. One can think of the even part as the original signal padded with one zero at the end.
  • Perform FFT on Each Part: Apply the FFT to both the even-length and odd-length parts separately.
  • Generate Random Phases: Generate random phase shifts for both parts, just like it’s done for even-length signals.
  • Apply Phases to FFT Bins: Apply the random phases to the frequency bins as done before. For the even-length part, apply the phases to bins 2 to "nfft"/2. For the odd-length part, apply the phases to bins 2 to ("nfft"-1)/2. Remember, for odd-length signals, the Nyquist frequency bin ("nfft"/2) will be a real value and not complex.
  • Recombine the Signal: After applying the random phases to both parts, recombine them. For the even-length part, directly concatenate it with the odd-length part.
  • Perform Inverse FFT: Apply the inverse FFT to the combined signal to get the phase-randomized time-domain signal.
I hope this approach will help you perform phase randomization on odd-length audio signals while maintaining their RMS value. It's important to note that when recombining the even and odd parts, one should ensure that there is no overlap or gap between them.

Plus de réponses (0)

Catégories

En savoir plus sur Measurements and Spatial Audio dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by