Sir my program howing a error. how to rectify the error.

1 view (last 30 days)
[audio, fs1] = audioread('noisyroaradultfemale.wav');
%sound(x,fs1);
ts1=1/fs1;
N1=length(audio);
Tmax1=(N1-1)*ts1;
t1=(0:ts1:Tmax1);
figure;
plot(t1,audio),xlabel('Time'),title('Original audio');
fs2 = (20/441)*fs1;
y=resample(audio,2000,44100);
%sound(y,fs2);
ts2=1/fs2;
N2=length(y);
Tmax2=(N2-1)*ts2;
t2=(0:ts2:Tmax2);
figure;
plot(t2,y),xlabel('Time'),title('resampled audio');
% Step 2: Frame Blocking
frameSize=600;
% frameOverlap=128;
% frames=enframe(y,frameSize,frameOverlap);
% NumFrames=size(frames,1);
frame_duration=0.03;
frame_len = frame_duration*fs2;
framestep=0.01;
framestep_len=framestep*fs2;
% N = length (x);
num_frames =floor(N2/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=y((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(500)';
windowed = bsxfun(@times, frames, hamm);
% 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,500, 2) );
plot(ft);
% Step 5: Mel Filterbanks
Lower_Frequency = 100;
Upper_Frequency = fs2/2;
% With a total of 22 points we can create 20 filters.
Nofilters=20;
lowhigh=[300 fs2/2];
%Here logarithm is of base 'e'
fmin=10;
fmax=10000;
k=0.88;
x=0:1;
A=fmin/(1-k);
a=log10((fmax/A)+k);
%%perceived_freq_Fp=(1/a)*(ln((f/a)+K)/ln10);
%perceived_freq_F=A*((10^(a*x))-k);
f=A*((10.^(A*x))-k);
figure;
plot(f);
title('Greenwood scale');
%Converting to frequency resolution
fres=floor(((frameSize)+1)*f/fs2);
%Creating the filters
for m =2:length(fres)-1
for k=0:0.88
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(H);
title('Greenwood filterbank');
xlabel('Frequency');
ylabel('Magnitude');
% Step 6: Nautral Log and DCT
% pkg load signal
%Here logarithm is of base '10'
logged=log10(bankans);
for i=1:NumFrames
gfcc(i,:)=dct2(logged(i,:));
end
%plotting the MFCC
figure
hold on
for i=1:NumFrames
plot(gfcc(i,1:13));
figure;
title('gfcc');
end
hold off
% save c5 mfcc
d= gfcc;
save i d
load i.mat
X=d;
the error is like this,"Undefined function or variable 'H'.
Error in gfccc (line 107)
bankans(i,j)=sum((ft(i,:).*H(j,:)).^2);"

Answers (1)

Ken Atwell
Ken Atwell on 29 Nov 2018
The variable 'H' is used but does not exist. I see that you are trying to assign to 'H' in a loop above this failure, and I'll guess this code is never run. Try setting a breakpoint around the statements ans single-step through the code to spot the error:
for m =2:length(fres)-1
for k=0:0.88
In particular, that inner 'for' loop looks supect - that will generated just k==0
  7 Comments
Walter Roberson
Walter Roberson on 29 Nov 2018
Well look at your code:
%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
If the "20 filterbanks" is intended to correspond with "Nofilters" then it follows that H is expected to be an array with at least 20 rows, which is to say Nofilters rows.
The loop
for m =2:length(fres)-1
consistently assigns to H(m-1,something). Therefore in order for the final m-1 to equal Nofilters, it follows that the maximum m must equal Nofilters+1 . You are defining the maximum m as length(fres)-1 and from there it follows that for the right number of rows to be created in H, that length(fres)-1 must equal Nofilters+1 and so that length(fres) = Nofilters+2 .
This suggests that you should use
x = linspace(0, 1, Nofilters+2);
Suchithra K S
Suchithra K S on 29 Nov 2018
Now it showing the error like this,
Subscript indices must either be real positive integers or logicals.
Error in gfccc (line 94)
H(m-1,k) = 0;

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!