had a trouble in the following program

x=55125;
y=54900;
function[ABSE,MSE,RMSE,SNR]=objectiveanalysis(x,y)
L=length(x);
y=y(1:L);
ABSE=sum(abs(x-y));
MSE=(sum(((x-y).^2))).*(1/L);
RMSE=MSE.^.5;
nem=sum((x).^2);
den=sum(((x-y).^2));
SNR1=nem./den;
SNR=10*log10(SNR1);
fprintf ('Absolute Error : %g\n\n',ABSE);
fprintf ('Mean Square Error : %g\n\n',MSE);
fprintf ('Root Mean Square Error : %g\n\n',RMSE);
fprintf ('Signal to Noise Ratio : %g\n\n',SNR);
note... actuly x is my speech signal and its length is i define same y is my encoded speech and its length i defined

1 Comment

You forgot to describe the trouble. What's going wrong?

Answers (2)

Mischa Kim
Mischa Kim on 24 Feb 2014
The first two lines of your code (assigning values to x and y) you should execute in the MATLAB command window. Only the code including and following the function definition should be in the function file (named objectiveanalysis.m).
Or, have it all in a single m-file called test (if you want to do it that way, in a single m-file):
function test
x=55125;
y=54900;
[ABSE,MSE,RMSE,SNR]=objectiveanalysis(x,y)
function[ABSE,MSE,RMSE,SNR]=objectiveanalysis(x,y)
L=length(x);
y=y(1:L);
ABSE=sum(abs(x-y));
MSE=(sum(((x-y).^2))).*(1/L);
RMSE=MSE.^.5;
nem=sum((x).^2);
den=sum(((x-y).^2));
SNR1=nem./den;
SNR=10*log10(SNR1);
fprintf ('Absolute Error : %g\n\n',ABSE);
fprintf ('Mean Square Error : %g\n\n',MSE);
fprintf ('Root Mean Square Error : %g\n\n',RMSE);
fprintf ('Signal to Noise Ratio : %g\n\n',SNR);

This question is closed.

Asked:

on 24 Feb 2014

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!