error when using audioread within new function my_DFTwin
1 次查看(过去 30 天)
显示 更早的评论
Dear all , Hi , Please I have a new function named my_DFTwin , I need to use audioread of audio file 'go.au' , and use the signal and sampling frequency as inputs to the function or i need to load as .mat ,
but i get error
Error using zeros NaN and Inf not allowed,
so what would be the solution ? , function is below
function my_DFTwinmy_DFTwin( frame_duration,index,n_overlap)
% This function will compute the DFT of a windowed length L segment of the vector x.
% The window would start at the index of the signal
[signal,Fs]=audioread('go.au');
dt=1/Fs;
L=length(signal);
signal_duration=L/Fs; % duration of the whole speech signal in seconds
frame_length=ceil(frame_duration*Fs); % Number of samples of the window
nfft = 2^nextpow2(frame_length); % Number of DFT points
w = hamming(frame_length); % type of window
y=zeros(L,floor((L-n_overlap)/(frame_length-n_overlap)));
Y=zeros(nfft,floor((L-n_overlap)/(frame_length-n_overlap)));
t=zeros(1,floor((L-n_overlap)/(frame_length-n_overlap)));
for k=index:floor((L-n_overlap)/(frame_length-n_overlap))
y(:,k)=[zeros(1,(k-1)*n_overlap) w' zeros(1,L-frame_length-(k-1)*n_overlap) ]'.*signal;
Y(:,k)=abs(fft(nonzeros(y(:,k)),nfft));
P1(:,k) = Y(1:nfft/2+1,k);
P1(2:end-1,k) = 2*P1(2:end-1,k);
end
figure(1) ; plot(1000*(0:dt:signal_duration-dt),signal,'r') ; grid ; xlabel('Time in m seconds ') ; ylabel('Amplitude')
figure(2) ; spectrogram(signal,hamming(frame_length),n_overlap,nfft,Fs,'yaxis');
end
4 个评论
Walter Roberson
2020-1-14
I changed
function my_DFTwinmy_DFTwin( frame_duration,index,n_overlap)
% This function will compute the DFT of a windowed length L segment of the vector x.
% The window would start at the index of the signal
[signal,Fs]=audioread('go.au');
into
function my_DFTwinmy_DFTwin( signal, Fs, frame_duration,index,n_overlap)
% This function will compute the DFT of a windowed length L segment of the vector x.
% The window would start at the index of the signal
%[signal,Fs]=audioread('go.au');
and after loading your go.mat I invoked
my_DFTwinmy_DFTwin(signal, Fs, 0.962625, 1, 40)
I did not encounter any error.
Please confirm that when you do
[signal,Fs]=audioread('go.au');
that Fs is set to 8000 . I suspect it is being returned as 0.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio Processing Algorithm Design 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!