FFT and IFFT: Random Phases

조회 수: 23 (최근 30일)
Nycholas Maia
Nycholas Maia 2019년 3월 21일
댓글: oloo 2023년 2월 22일
I imported a single audio file to MATLAB workspace.
After I apply the FFT:
Y = fft(signal)
How can I random change the audio phases before apply the Inverse FFT and get the 'new_signal'?
new_signal = ifft(Y)
How can I do it?

채택된 답변

Brittany Scheid
Brittany Scheid 2019년 6월 16일
편집: Brittany Scheid 2019년 6월 16일
Following the comment by David Goodmanson above, here is what I used to randomize an array of timeseries data:
function randX = phaseRandomize(X)
% Returns a phase-randomized version of the input data X. If X is an array,
% each row is treated as an independant time series, and columns represent
% sample points.
[N,L]=size(X);
Y=fft(X,[],2); % Get spectrum
% Add random phase shifts (negative for conjugates), preserve DC offset
rnd_theta= -pi + (2*pi).*rand(N,L/2-1);
Y(:,2:L/2)=Y(:,2:L/2).*exp(1i*rnd_theta);
Y(:,L/2+2:L)=Y(:,L/2+2:L).*exp(-1i*flip(rnd_theta,2));
% return phase-randomized data
randX =ifft(Y,[],2);
end
  댓글 수: 2
oloo
oloo 2023년 2월 21일
Could You please provide code to revert phases back to oryginal signal? of course based on same rnd_theta. Thank You very much.
oloo
oloo 2023년 2월 22일
ok i figured it out already

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

David Goodmanson
David Goodmanson 2019년 3월 22일
Hi Nycholas,
Assuming signal is real and of length n, n even, then
Y(1) is for frequency 0, the DC contribution, and it's real. Don't mess with that point.
Y(2) and Y(n) are complex conjugates. You can multiply one of that pair by exp(i*theta) and the other by exp(-i*theta), where theta is a random angle with 0 <= theta < 2*pi. the new Y(2) and Y(n) remain complex conugates.
In general from k = 2 to n/2, Y(k) and Y(n+2-k) form a complex conjugate pair. For each of those pairs, do the same kind of multiplcation as above, with a different random angle. Each pair remain complex conjugates.
Y(n/2+1) is real. Don't mess with that point either.
ifft back.
Here the random phases are totally uncorrelated from frequency to frequency, which may or may not be physically realistic.
  댓글 수: 3
David Goodmanson
David Goodmanson 2019년 3월 23일
Hi NM, what have you tried so far?
David Daminelli
David Daminelli 2019년 6월 1일
Hello NM and DG! I'm working on a project that needs this same function, and I've done an algorithm that does that. It is here https://www.mathworks.com/matlabcentral/answers/465112-help-with-sound-function, followed by a question I had during the project, if they can help it would be usefull!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Transforms에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by