Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

MFCC Matlab Code for speech regonition

Status
Not open for further replies.

mzoh

Newbie level 4
Joined
Nov 2, 2017
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
63
Hello,

I got this MFCC code from this forum. But it is giving errors. I am running it on matlab2010. Can anybody help me out regarding this.

Code:
AI=analoginput('winsound',1);
addchannel(AI,1);
set(AI,'samplerate',16000);
set(AI,'samplespertrigger',2*16000);
set(AI,'triggertype','immediate');
start(AI);
data=getdata(AI);
fs=16000;
%file = sprintf('%s%d.wav','database_new kar',i);
%%wavwrite(data,16000,file);

%% Computing MFCC Co-efficients..
    %% (1) Frame Blocking..
    N = 256;   % N point FFT
    M = 100;   % Overlapping

    NN = floor(N/2+1); %N/2
    nbFrames = ceil((length(data)-N)/M);
    Frames = zeros(nbFrames+1,N);
    for i = 0:nbFrames-1
        temp = data(i*M+1:i*M+N);
        Frames(i+1,1:N) = temp; 
    end

    % Last Frame..
    temp = zeros(1,N); 
    lastLength = length(data)- nbFrames*M;
    temp(1:lastLength) = data(nbFrames*M+1:(nbFrames*M +1 + lastLength-1));  
    Frames(nbFrames+1, 1:N) = temp;
    %% (2) Windowing..
    frameSize = size(Frames); 
    nbFrames = frameSize(1); 
    nbSamples = frameSize(2); 
 
    % Hamming window.. 
    w = hamming(nbSamples); 
    Windows = zeros(nbFrames,nbSamples);
    for i = 1:nbFrames
        temp = Frames(i,1:nbSamples); 
        Windows(i, 1:nbSamples) = w'.*temp; 
    end
    %% (3) Fourier Transform..
    ffts = fft(Windows');

    %% (4) Mel-frequency Wrapping..
    % (a) Calculate Power spectrum..
    PowSpecs = abs(ffts).^2;
    PowSpecs = PowSpecs(1:NN-1,:);

    % (b) Mel filter generation
    nof_c = 20; % Number of channels..
    df = fs/N;
    Nmax = N/2;
    fmax = fs/2;

    % Convert to mel scale..
    melmax = 2595*log10(1+fmax/700);

    melinc = melmax/(nof_c+1);

    melcenters = (1:nof_c).*melinc;

    % Convert to frequency scale.. 
    fcenters = 700*((10.^(melcenters./2595))-1);

    centerf = round(fcenters./df);

    startf = [1,centerf(1:nof_c-1)];
    stopf = [centerf(2:nof_c),Nmax];

    W = zeros(nof_c,Nmax);

    % Making filter..
    for i = 1:nof_c
        increment = 1.0/(centerf(i)-startf(i));
        for j = startf(i):centerf(i)
            W(i,j) = (j-startf(i))*increment;
        end
   
        decrement = 1.0/(stopf(i)-centerf(i));
        for j = centerf(i):stopf(i)
            W(i,j) = (j-centerf(i))*decrement;
        end 
    end
    % Normalising..
    for i = 1:nof_c
        W(i,:) = W(i,:)/sum(W(i,:));
    end
    
    % (c) Apply mel filters to Power spectrum coeffs..
    melPowSpecs = W*PowSpecs;
    % (d) MFCC calculations..
    melCeps = dct(log(melPowSpecs));
    melCeps(1,:) = [];
    
    load CodeBook
	dist_min = inf;
	spkr = 0;
	for ind = 1:length(codebook)
		single_cb =  codebook{ind};
		[M1, N1] = size(melCeps);
		[M2, N2] = size(single_cb);  
		dist_temp = zeros(N1,N2);
		if N1<N2
            repli = zeros(1,N2);
            for n1 = 1:N1
                dist_temp(n1,:) = sum((melCeps(:,n1+repli) - single_cb).^2,1);
            end
        else
            repli = zeros(1,N1);
            for n2 = 1:N2
                dist_temp(:,n2) = sum((melCeps - single_cb(:,n2+repli)).^2,1);
            end
        end
        dist_temp = sqrt(dist_temp);
		dist_val(ind) = sum(min(dist_temp,[],2))/size(dist_temp,1);
		if dist_val(ind) < dist_min
            dist_min = dist_val(ind);
			spkr = ind;
		end
	end
	msg = sprintf('The Speaker is found);
    	disp(msg);
 

I am getting the error.

??? Undefined function or method 'analoginput' for input arguments of type 'char'.
Error in ==> testing at 1
AI=analoginput('winsound',1);

In matlab 2010 this function is not available.
In the end of code load codebook. Whats the function of this. Can you explain this step.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top