フィルターのクリア

error when using audioread within new function my_DFTwin

1 回表示 (過去 30 日間)
Mohamad
Mohamad 2020 年 1 月 14 日
コメント済み: Mohamad 2020 年 1 月 15 日
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
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.
Mohamad
Mohamad 2020 年 1 月 15 日
Thanks a lot , yes it is working normally now , is it possible to add line into the function to load go.mat or I must load it into the workspace before run the function my_DFTwinmy_DFTwin ? , thanks and best regards

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeAudio Processing Algorithm Design についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by