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?
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!