不好意思
完整的CODE是這樣
Function (1)
function y=cirshftt(x,m,N) % function of circular shift of m samples wrt size N in sequence x
% x=input sequence of length <= N
% m=sample shift
% N=size of circular buffer
if length(x)>N % check for length of x
error('N must be >= the length of x')
end
x=[x zeros(1,N-length(x))];
n=[0:1:N-1];
n=mod(n-m,N);
y=x(n+1);
Function (2)
function y=circonvt(x1,x2,N) % function of N-point circular convolution between x1 and x2
% x1=input sequence of length N1 <= N
% x2=input sequence of length N2 <= N
% N=size of circular buffer
if length(x1)>N % check for length of x1
error('N must be >= the length of x1')
end
if length(x2)>N % check for length of x2
error('N must be >= the length of x2')
end
x1=[x1 zeros(1,N-length(x1))];
x2=[x2 zeros(1,N-length(x2))];
m=[0:1:N-1];
x2=x2(mod(-m,N)+1);
H=zeros(N,N);
for n=1:1:N
H(n,:)=cirshftt(x2,n-1,N); % using cirshftt function
end
y=x1*H';
Function (3)
function [y] = my_ola_filter(x, h, N) %function of overlap add method
% x=input sequence
% h=impulse response
% N=blocksize
Lenx = length(x); M= length(h);% length of x & lenght of h
N1 = N+M-1;
m=rem(Lenx,N); %find remainder
if m~=0
x=[x zeros(1,N-m)]; % preappend (M-1) zeros
K=floor(Lenx/N)+1; % number of blocks
else
x=x;K=floor(Lenx/N);
end
ytemp=zeros(1, N1-N);
n1=1; n2=N;
for k=1:K %convolution with succesive blocks
xk=x(n1:n2);
Y(k,:)=circonvt(xk, h, N1); % recall circonvt function
for i=1:N1-N
Y(k,i)=Y(k,i)+ytemp(i);
ytemp(i)=Y(k,i+N);
end
y(n1:n2)=Y(k,1:N);
n1=n1+N; n2=n2+N;
end
在M FILE 中有了這三條FUNCTION,
當我用FUNCTION 3時候
N=XXXXX<-----數字
>> y=my_ola_filter(x, h, N)
之後出現了
[bo]??? Error using ==> horzcat
CAT arguments dimensions are not consistent.
Error in ==> my_ola_filter at 9
x=[x zeros(1,N-m)]; % preappend (M-1) zeros[/bo]
>>
如何解決???? |