error when using audioread within new function my_DFTwin

1 visualización (últimos 30 días)
Mohamad
Mohamad el 14 de En. de 2020
Comentada: Mohamad el 15 de En. de 2020
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 comentarios
Walter Roberson
Walter Roberson el 14 de En. de 2020
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 el 15 de En. de 2020
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

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Audio Processing Algorithm Design en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by