- 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.
shuffling phases of fft when length is odd
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
Dhruv
il 31 Ago 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:
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.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Parametric Spectral Estimation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!