How can I fix an undefined function error in MATLAB?
I'm trying to write the code for quadrature phase-shift keying (QPSK) with zeroforcing when N=2, and I got an error.
Here is the code:
Modulation = 'QPSK'
Decode_Method = 'ZeroForcing'
switc开发者_JS百科h Modulation
case {'QPSK'}
Symbols = [ 1+j 1-j -1+j -1-j ]';
end
Symbols = Symbols.';
nSymbols = length(Symbols);
SNR_Array = [0.3 0.7 1.2 2.5 5 6.2 10 15.4 22 45 75.7 100.0];
nSNR = length(SNR_Array);
Ntest = 20;
N = 2;
for iSNR = 1 : nSNR
SNR = SNR_Array(iSNR);
Nerror = 0;
for i = 1:Ntest
H = randn(N,N) + j*randn(N,N);
X = Symbols( ceil( nSymbols*rand(N,1) ) )';
Noise = (randn(N,1) + j*randn(N,1))/sqrt(2)/sqrt(SNR);
Y = H*X + Noise;
switch Decode_Method
case {'ZeroForcing'}
X_Decode = Zero_Forcing(Y,H,Symbols);
end
end
Nerror = Nerror + length( find( X ~= X_Decode) );
end
Symbol_Error_Rate(iSNR) = Nerror/Ntest/N;
figure(1)
loglog(SNR_Array, Symbol_Error_Rate,'b')
hold on
xlabel('SNR')
ylabel('Symbol Error Ratio')
title('Symbol Error Ratio for NxN MIMO System')
And the error is:
??? Undefined function or method 'Zero_Forcing' for input arguments of type 'double'.
Error in ==> Untitled2 at 33 X_Decode = Zero_Forcing(Y,H,Symbols);
How can I fix this error?
The error indicates that MATLAB cannot find the function Zero_Forcing
. If you have a function of that name, you should make sure it's on the MATLAB path, that is, a directory MATLAB knows about. Otherwise, you should write the function. It seems rather important.
Also, you may want to not call your function 'Untitled2', but give it a more meaningful name.
精彩评论