Sir, when i run my code in matlab it taking toomuch time and always it showing running. I am not getting any output. What's the problem with this. how to rectify this?

1 visualizzazione (ultimi 30 giorni)
The code is given below:
[audio, fs] = audioread('cryrumble.wav');
%sound(x,fs1);
ts1=1/fs;
N1=length(audio);
Tmax1=(N1-1)*ts1;
t1=(0:ts1:Tmax1);
figure;
plot(t1,audio),xlabel('Time'),title('Original audio');
%Step 1: Pre-Emphasis
a=[1];
b=[1 -0.95];
z=filter(b,a,audio);
subplot(413),plot(t1,z),xlabel('Time'),title('Signal After High Pass Filter - Time Domain');
subplot(414),plot(fs,fftshift(abs(fft(z)))),xlabel('Freq (Hz)'),title('Signal After High Pass Filter - Frequency Spectrum');
nchan = size(audio,2);
for chan = 1 : nchan
%subplot(1, nchan, chan)
spectrogram(audio(:,chan), 256, [], 25, 2000, 'yaxis');
title( sprintf('spectrogram of resampled audio ' ) );
end
% Step 2: Frame Blocking
frameSize=882;
% frameOverlap=128;
% frames=enframe(y,frameSize,frameOverlap);
% NumFrames=size(frames,1);
frame_duration=0.02;
frame_len = frame_duration*fs;
framestep=0.01;
framestep_len=framestep*fs;
% N = length (x);
num_frames =floor(N1/frame_len);
% new_sig =zeros(N,1);
% count=0;
% frame1 =x(1:frame_len);
% frame2 =x(frame_len+1:frame_len*2);
% frame3 =x(frame_len*2+1:frame_len*3);
frames=[];
for j=1:num_frames
frame=z((j-1)*framestep_len + 1: ((j-1)*framestep_len)+frame_len);
% frame=x((j-1)*frame_len +1 :frame_len*j);
% identify the silence by finding frames with max amplitude less than
% 0.025
max_val=max(frame);
if (max_val>0.025)
% count = count+1;
% new_sig((count-1)*frame_len+1:frame_len*count)=frames;
frames=[frames;frame];
end
end
% Step 3: Hamming Windowing
NumFrames=size(frames,1);
hamm=hamming(882);
for i=1:NumFrames
windowed(i,:)=frames(i,:).*hamm;
end
% Step 4: FFT
% Taking only the positive values in the FFT that is the first half of the frame after being computed.
ft = abs( fft(windowed,441, 2) );
plot(ft);
% Step 5: Mel Filterbanks
Lower_Frequency = 100;
Upper_Frequency = fs/2;
% With a total of 22 points we can create 20 filters.
Nofilters=20;
lowhigh=[300 fs/2];
%Here logarithm is of base 'e'
lh_mel=1125*(log(1+lowhigh/700));
mel=linspace(lh_mel(1),lh_mel(2),Nofilters+2);
figure;
plot(mel);
xlabel('frequency in Hertz');ylabel('mels');
title('melscale');
melinhz=700*(exp(mel/1125)-1);
%Converting to frequency resolution
fres=floor(((frameSize)+1)*melinhz/fs2);
%Creating the filters
for m =2:length(mel)-1
for k=1:frameSize/2
if k<fres(m-1)
H(m-1,k) = 0;
elseif (k>=fres(m-1)&&k<=fres(m))
H(m-1,k)= (k-fres(m-1))/(fres(m)-fres(m-1));
elseif (k>=fres(m)&&k<=fres(m+1))
H(m-1,k)= (fres(m+1)-k)/(fres(m+1)-fres(m));
elseif k>fres(m+1)
H(m-1,k) = 0;
end
end
end
%H contains the 20 filterbanks, we now apply it to the processed signal.
for i=1:NumFrames
for j=1:Nofilters
bankans(i,j)=sum((ft(i,:).*H(j,:)).^2);
end
end
figure;
plot(bankans(i,j));
figure;
plot(H);
xlabel('Frequency');ylabel('Magnitude');
title('Mel-Frequency Filter bank');
% Step 6: Nautral Log and DCT
% pkg load signal
%Here logarithm is of base '10'
logged=log10(bankans);
for i=1:NumFrames
mfcc(i,:)=dct2(logged(i,:));
end
%plotting the MFCC
figure
hold on
for i=1:NumFrames
plot(mfcc(i,1:13));
title('mfcc');
end
hold off
% save c5 mfcc
i= mfcc;
save i i
load i.mat
X=i;
k=1;
[IDXi,ci] = kmeans(X,k);
save c41i ci
  3 Commenti
OCDER
OCDER il 5 Feb 2019
From what I can see, you are growing a lot of matrices, which is slow.
frames=[]; %Anytime you grow frames, it's slow
for j=1:num_frames
frame=z((j-1)*framestep_len + 1: ((j-1)*framestep_len)+frame_len);
max_val=max(frame);
if (max_val>0.025)
frames=[frames;frame]; %DON'T DO THIS! Preallocate Frames
end
end
Try this for instance:
tic
F = [];
for j = 1:10000
F = [F j];
end
toc %0.045 s
tic
F = zeros(1, 10000);
for j = 1:10000
F(j) = j;
end
toc %0.012 s
Suchithra K S
Suchithra K S il 6 Feb 2019
Sir i tried this now the program showing the error like this,"Error using .*
Matrix dimensions must agree.
Error in mfcheck (line 80)
windowed(i,:)=F(i,:).*hamm;"

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 6 Feb 2019
The output of filter applied to aa column vector is aa column vector . You zz is aa column vector . When you index aa column vector you get out aa column vector . Therefore your frame variable is aa column vector . When you vertcat column vector together you get a column vector . Therefore your frames variable is a column vector. You are trying to use .* between the column vector and the hamming window which is not going to give you the result you expect

Community Treasure Hunt

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

Start Hunting!

Translated by