Transform fft phase to write audio

13 ビュー (過去 30 日間)
Zeynep Sayali
Zeynep Sayali 2021 年 6 月 22 日
回答済み: Mathieu NOE 2021 年 6 月 23 日
I need to transform the phase (and not amplitude) of a sound and create a new sound file, however ifft() of the transformed array appears complex and cannot be written to audio. Below is my code:
% read the audio file and fourier transform it
[x, Fs] = audioread('Sample.m4a');
y = fft(x,Fs); % Compute DFT of x
Xf_mag = abs(y);
% the phase of each resulting frequency bin was randomly shuffled
Xf_phase = angle(y);
Xf_phase_new=shuffle(Xf_phase);
% The phase-shuffled frequency domain data were then back-transformed to
% the time domain using an inverse Fourier transform
Xf_new = Xf_mag.*exp(1i*Xf_phase_new);
x_new = ifft(Xf_new);
% write a new sound file
filename = 'test.m4a';
audiowrite(filename,x_new,Fs);
I get the following error:
Error using audiowrite (line 170)
Expected input to be real.

採用された回答

Mathieu NOE
Mathieu NOE 2021 年 6 月 23 日
hello
take the real part after you do the ifft :
x_new = real(ifft(Xf_new));

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by