フィルターのクリア

Error as Move all statements after the "formula" function definition to before the first local function definition."

1 回表示 (過去 30 日間)
This is a code for computing mfcc.I'm trying to resolve the issue for a long time.The error is given as below.
"Function definitions in a script must appear at the end of the file.
Move all statements after the "formula" function definition to before the first local function definition."
Here two functions are used.Formula function and dct function.Do the function definitions used in the code are properly arranged?
Could anybody help?
%make frames
clear all;
[signal,fs] = audioread('chakitham1.wav');
f_d = 0.025;
f_size = round(f_d*fs);
n = length(signal);
n_f = floor(n/f_size);
temp = 0;
for i = 1 : n_f
frame(i,:) = signal(temp + 1 : temp + f_size);
temp = temp + f_size;
end
if mod(n_f,2) == 1
frame(n_f+1,:) = zeros(size(frame(1,:)));
n_f=n_f+1;
end
save('framedchakitham1');
load('framedchakitham1','n_f','frame');
disp(length(frame(1,:)))
%window the frame
for j = 1 : n_f
disp(1)
fr_wind(j,:) = frame(j,:)'.*hamming(length(frame(j,:)));
a=1;
end
save('windowchakitham1')
f_low=300;
f_high=8000;
%%computing band in mel-scale
mel_low=1125*log(1+(f_low/700));
mel_high=1125*log(1+(f_high/700));
filt_num=26;
%%creating the mel-scaled vector
Mel = linspace(mel_low,mel_high,filt_num+2);
%%computing frequencies of the Mel vector
%FREQ=700*((10.^(Mel/2595))-1);
Freq = 700*((exp(Mel/1125))-1);
fs=16000;
nfft = 512;
%%convert frequencies to nearest bins
for i=1:filt_num+2
f(i) = floor((nfft+1)*Freq(i)/fs);
end
for m =2:length(Mel)-1
for k=1:floor(nfft/2+1)
h(m-1,k) = formula(k,f,m)
end
end
save('mel_filter_bank')
function H=formula(k,f,m)
if k<f(m-1)
H = 0;
elseif k>=f(m-1)&&k<=f(m)
H = (k-f(m-1))/(f(m)-f(m-1));
elseif k<=f(m+1)&&k>=f(m)
H = (f(m+1)-k)/(f(m+1)-f(m));
elseif k>f(m+1)
H = 0;
end
end
load('periodogram','psdy');
load('mel_filter_bank','h','filt_num');
load('framed','n_f');
for j = 1 : n_f
for i = 1 : filt_num
num(i,:) = psdy(j,:).*h(i,:);
end
energy_log(j,i) = log(sum(num(i,:)));
dct_energy(j,:) = dct(energy_log(j,:));
end
function y = dct(x, n)
if (nargin < 1 || nargin > 2)
print_usage;
end
realx = isreal(x);
transpose = (rows (x) == 1);
if transpose, x = x (:); end
[nr, nc] = size (x);
if nargin == 1
n = nr;
elseif n > nr
x = [ x ; zeros(n-nr,nc) ];
elseif n < nr
x (nr-n+1 : n, :) = [];
end
if n == 1
w = 1/2;
else
w = [ sqrt(1/4/n); sqrt(1/2/n)*exp((-1i*pi/2/n)*[1:n-1]') ] * ones (1, nc);
end
if ( realx && rem (n, 2) == 0 )
y = fft ([ x(1:2:n,:) ; x(n:-2:1,:) ]);
y = 2 * real( w .* y );
else
y = fft ([ x ; flipud(x) ]);
y = w .* y (1:n, :);
if (realx) y = real (y); end
end
if transpose, y = y.'; end
end

採用された回答

Walter Roberson
Walter Roberson 2021 年 8 月 17 日
load('periodogram','psdy')

is not inside any function. It is not part of "formula" which has an "end" matching the "function" statement.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by