Reputation: 13
I'm using below codes to fo FFT first and then take the first 10 bigger amplitudes of FFT and corresponding frequency and phase informations.
At the end of te code, i'm trying to rebuild the original signal as much as possible but not using ifft because of the implementation that i'm trying.
Finally, i'm trying to write the .wav but getting "too many output arguments." error always. Could you pls let me know about your feedbacks?
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);
Upvotes: 1
Views: 695
Reputation: 2332
Well, as the error suggests you have "too many output arguments". By looking at your code I believe that the problem is that audiowrite
does not return any output arguments (have a look at http://www.mathworks.com/help/matlab/ref/audiowrite.html). You should use
audiowrite(filename,audio_r,44100);
instead.
In any case, you should learn how to use the MATLAB debugger (http://www.mathworks.com/help/matlab/debugging-code.html) in order to identify where your error is.
BTW, the line Phases = angle(abs(Y))
makes on sense as the absolute values do not have phase. Did you mean Phases = angle(Y)
?
Upvotes: 3