簡體   English   中英

在進行FFT並獲得Amp,Freq,Phase信息后創建音頻文件

[英]Creating audio file after doing FFT and getting Amp,Freq,Phase infos

我首先使用下面的代碼進行FFT,然后采用FFT的前10個更大的幅度以及相應的頻率和相位信息。

在te代碼結束時,我正在嘗試盡可能地重建原始信號但不使用ifft,因為我正在嘗試實現。

最后,我正在嘗試編寫.wav,但獲得“輸出參數太多”。 總是錯誤。 你能告訴我你的反饋意見嗎?

close all
clear all
clc

[audio,Fs]=audioread('C:\Users\xaol\Desktop\sound.wma');
audioinfo('C:\Users\xaol\Desktop\sound.wma')
player=audioplayer(audio,44100); play(player)

length_audio=length(audio);
%plot(audio);

audio1=audio(2^16:2^17);   %taking a part of audio
audio_part=2^17-2^16;      %the lenght of taken part
plot(audio1);
title('original partly signal');
player=audioplayer(audio1,44100); play(player)

%% FFT

NFFT = audio_part;
Y = fft(audio1,NFFT)/length(audio1);
fs=length(audio1)/length(audio1);  
f = fs/2*linspace(0,1,NFFT/2+1);

[B,IX] = sort(abs(Y(1:NFFT/2+1))); %order the amplitudes
Amplitudes=B; %find all amplitudes 
Frequencies=f(IX(1+end-numel(Amplitudes):end)); %frequency of the peaks
Phases=angle(abs(Y));

%% 10 bigger amplitudes and corresponding frequency and phase are being found

A=B((length(IX)-9):(length(IX)));
F=Frequencies((length(IX)-9):(length(IX)));
P=angle(Y(IX((length(IX)-9):length(IX))))*180/pi;

FAP=[F;A;P]

%FAP is 3x10 matrix which includes frequency, amplitude and phase info

%% REBUILD ORIGINAL SIGNAL

ii=length(FAP);
org_audio=0;
t=0:length(audio1);

for i=1:1:ii
   org_audio=4*FAP(2,i)*exp(j*2*pi*FAP(1,i)*t+j*(pi/180)*FAP(3,i))+org_audio; 
end

figure, plot(t,org_audio)

audio_r1=abs(org_audio);
audio_r(:,1)=(audio_r1)';
audio_r(:,2)=audio_r(:,1);


filename='C:\Users\xaol\Desktop\sound2.wav';
AU=audiowrite(filename,audio_r,44100);

好吧,因為錯誤表明你有“太多的輸出參數”。 通過查看您的代碼,我認為問題在於audiowrite不會返回任何輸出參數(請查看http://www.mathworks.com/help/matlab/ref/audiowrite.html )。 你應該用

audiowrite(filename,audio_r,44100);

代替。
在任何情況下,您都應該學習如何使用MATLAB調試器( http://www.mathworks.com/help/matlab/debugging-code.html )來識別錯誤的位置。

順便說一句,線Phases = angle(abs(Y))是有意義的,因為絕對值沒有相位。 你的意思是Phases = angle(Y)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM