shuffling phases of fft when length is odd
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Spectral Measurements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!