Sir, when I running my codeit showing a error like this"Matrix dimensions must agree. Error in feature(line 98) bankans(i,j)=sum((ft(i,:).*h(j,:)).^2); " .How to rectify the error?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Suchithra K S
am 28 Apr. 2019
Kommentiert: Walter Roberson
am 29 Apr. 2019
The code is given below,
clc;
clear all;
[x,fs1]=audioread('cryrumble.wav');
ts1=1/fs1;
N1=length(x);
Tmax1=(N1-1)*ts1;
t1=(0:ts1:Tmax1);
figure;
plot(t1,x),xlabel('Time'),title('Original audio');
fs2 = (20/441)*fs1;
na=resample(x,2000,44100);
N2=length(na);
%framing
frameSize=882;
frame_duration=0.025;
frame_len = frame_duration*fs2;
framestep=0.01;
framestep_len=framestep*fs2;
num_frames =floor(N2/frame_len);
frames=[];
for j=1:num_frames
frame=na((j-1)*framestep_len + 1: ((j-1)*framestep_len)+frame_len);
max_val=max(frame);
if (max_val>0.025)
frames=[frames;frame'];
end
end
% Step 3: Hamming Windowing
NumFrames=size(frames,1);
hamm=hamming(frame_len)';
windowed=[];
for i=1:NumFrames
windowed(i,:)=frames(i,:).*hamm;
end
% Step 4: FFT
for i=1:NumFrames
ft(i,:)=abs(fft((windowed(i,:)),frame_len));
%plot(ft(i,:))
end
%Greenwood filterbank
filt_num = 45;
kcnst= 500; %nfft
fs=44100;
%elephant sound features between 10hz to 10000hz
fmin= 10;
fmax= 10000;
%A1 and A2 areconstants and x is cochlea position K is cnst equal to 0.88.
greenwoodcnstK= 0.88;
greenwoodcnstA1= fmin/(1-greenwoodcnstK);
greenwoodcnstA2= log10((fmax/greenwoodcnstA1)+greenwoodcnstK);
i=0;
% greenwood frequency
for x = 0 : 0.01 : 1
i=i+1;
freq_grn(i) = (greenwoodcnstA1)*(10^(greenwoodcnstA2 * x)- (greenwoodcnstK));
end
%perceived frequency
for f= 10:1:500;
Fp(f)= (1/greenwoodcnstA2)*log10((f/greenwoodcnstA2)+greenwoodcnstK);
end
for i=1:1:filt_num
f(i)=floor((1024+1)*freq_grn(i)/fs);
end;
% define triangular melbank
for j=2:1:filt_num-1
for i=1:1:kcnst
if i<f(j-1)
h(i,j-1)=0;
elseif f(j-1)<=i && f(j)>=i
h(i,j-1)=(i-f(j-1))/(f(j)-f(j-1));
elseif f(j)<i && f(j+1)>=i
h(i,j-1)=(f(j+1)-i)/(f(j+1)-f(j));
else
h(i,j-1)=0;
end;
end;
end;
figure(3);
plot(h);
%processed signal
for i=1:NumFrames
for j=1:filt_num
bankans(i,j)=sum((ft(i,:).*h(j,:)).^2);
end
end
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 28 Apr. 2019
ft is numframes (number of samples * 20/441) by frame_len (fs1/882)
h is kcnst (500) by filt_num-1-1 -> 500 x 43
These are simply unrelated entities that should not be used together.
6 Kommentare
Walter Roberson
am 29 Apr. 2019
Your code assigns a constant to frame duration and uses it to calculate frame length. Instead of using a constant you could calculate a duration such that the frame length came out as 43.
Your code assigns 45 to the number of filters and uses that value minus 2 as the number of filters. Instead of assigning a constant you can calculate a filt_num such that after subtracting 2 the results were the frame length.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!