Problem in calling multiple reurns and counting number of args passed

Hiii...

i.m in mid of my program.... as the following code is in MATLAB and i'm converting these into JAVA.... but there i stuck with an strange problems wiz..

1) i can't call multiple returns for multiple variable declaration in different method... and...

2) how can i count the number of arguments passed in an method...

Problems in following piece of code:

function [NoiseFlag, SpeechFlag, NoiseCounter, Dist]=vad(signal,noise,NoiseCounter,NoiseMargin,Hangover)

%[NOISEFLAG, SPEECHFLAG, NOISECOUNTER, DIST]=vad(SIGNAL,NOISE,NOISECOUNTER,NOISEMARGIN,HANGOVER)

%Spectral Distance Voice Activity Detector

%SIGNAL is the the current frames magnitude spectrum which is to labeld as

%noise or speech, NOISE is noise magnitude spectrum template (estimation),

%NOISECOUNTER is the number of imediate previous noise frames, NOISEMARGIN

%

%(default 3)is the spectral distance threshold. HANGOVER ( default 8 )is

%the number of noise segments after which the SPEECHFLAG is reset (goes to

%zero). NOISEFLAG is set to one if the the segment is labeld as noise

%NOISECOUNTER returns the number of previous noise segments, this value is

%reset (to zero) whenever a speech segment is detected. DIST is the

%spectral distance.

%Saeed Vaseghi

%edited by Esfandiar Zavarehei

%Sep-04

if nargin<4

NoiseMargin=3;

end

if nargin<5

Hangover=8;

end

if nargin<3

NoiseCounter=0;

end

FreqResol=length(signal);

SpectralDist= 20*(log10(signal)-log10(noise));

SpectralDist(find(SpectralDist<0))=0;

Dist=mean(SpectralDist);

if (Dist < NoiseMargin)

NoiseFlag=1;

NoiseCounter=NoiseCounter+1;

else

NoiseFlag=0;

NoiseCounter=0;

end

% Detect noise only periods and attenuate the signal

if (NoiseCounter > Hangover)

SpeechFlag=0;

else

SpeechFlag=1;

end

Main MATLAB Program :

function output=MultibandSS(signal,fs)

% OUTPUT=SSMULTIBAND(S,FS,IS)

% Multi-band Spectral subtraction

% subtraction with adjusting subtraction factor. the adjustment is

% according to local a postriori SNR and the frequency band.

% S is the noisy signal, FS is the sampling frequency and IS is the initial

% silence (noise only) length in seconds (default value is .25 sec)

%

if (nargin<3 | isstruct(IS))

IS=.25; %seconds

end

W=fix(.025*fs); %Window length is 25 ms

nfft=W;

SP=.4; %Shift percentage is 40% (10ms) %Overlap-Add method works good with this value(.4)

wnd=hamming(W);

% IGNORE THIS SECTION FOR CAMPATIBALITY WITH ANOTHER PROGRAM FROM HERE.....

% if (nargin>=3 & isstruct(IS))%This option is for compatibility with another programme

%W=IS.windowsize

%SP=IS.shiftsize/W;

%nfft=IS.nfft;

%wnd=IS.window;

%if isfield(IS,'IS')

% IS=IS.IS;

%else

% IS=.25;

%end

% end

% .......IGNORE THIS SECTION FOR CAMPATIBALITY WITH ANOTHER PROGRAM T0 HERE

NIS=fix((IS*fs-W)/(SP*W) +1);%number of initial silence segments

Gamma=2;%Magnitude Power (1 for magnitude spectral subtraction 2 for power spectrum subtraction)

y=segment(signal,W,SP,wnd);

Y=fft(y,nfft);

YPhase=angle(Y(1:fix(end/2)+1,:)); %Noisy Speech Phase

Y=abs(Y(1:fix(end/2)+1,:)).^Gamma;%Specrogram

numberOfFrames=size(Y,2);

FreqResol=size(Y,1);

N=mean(Y(:,1:NIS)')'; %initial Noise Power Spectrum mean

NoiseCounter=0;

NoiseLength=25;%This is a smoothing factor for the noise updating

Beta=.03;

minalpha=1;

maxalpha=5;

minSNR=-5;

maxSNR=20;

alphaSlope=(minalpha-maxalpha)/(maxSNR-minSNR);

alphaShift=maxalpha-alphaSlope*minSNR;

BN=Beta*N;

%Delta is a frequency dependent coefficient

Delta=1.5*ones(size(BN));

Delta(1:fix((-2000+fs/2)*FreqResol*2/fs))=2.5; %if the frequency is lower than FS/2 - 2KHz

Delta(1:fix(1000*FreqResol*2/fs))=1; %if the frequency is lower than 1KHz

for i=1:numberOfFrames

[NoiseFlag, SpeechFlag, NoiseCounter, Dist]=vad(Y(:,i).^(1/Gamma),N.^(1/Gamma),NoiseCounter); %Magnitude Spectrum Distance VAD

if SpeechFlag==0

N=(NoiseLength*N+Y(:,i))/(NoiseLength+1); %Update and smooth noise

BN=Beta*N;

end

SNR=10*log(Y(:,i)./N);

alpha=alphaSlope*SNR+alphaShift;

alpha=max(min(alpha,maxalpha),minalpha);

D=Y(:,i)-(Delta.*alpha.*N); %Nonlinear (Non-uniform) Power Specrum Subtraction

X(:,i)=max(D,BN); %if BY>D X=BY else X=D which sets very small values of subtraction result to an attenuated

%version of the input power spectrum.

end

output=OverlapAdd2(X.^(1/Gamma),YPhase,W,SP*W);

function ReconstructedSignal=OverlapAdd2(XNEW,yphase,windowLen,ShiftLen);

%Y=OverlapAdd(X,A,W,S);

%Y is the signal reconstructed signal from its spectrogram. X is a matrix

%with each column being the fft of a segment of signal. A is the phase

%angle of the spectrum which should have the same dimension as X. if it is

%not given the phase angle of X is used which in the case of real values is

%zero (assuming that its the magnitude). W is the window length of time

%domain segments if not given the length is assumed to be twice as long as

%fft window length. S is the shift length of the segmentation process ( for

%example in the case of non overlapping signals it is equal to W and in the

%case of %50 overlap is equal to W/2. if not givven W/2 is used. Y is the

%reconstructed time domain signal.

%Sep-04

%Esfandiar Zavarehei

if nargin<2

yphase=angle(XNEW);

end

if nargin<3

windowLen=size(XNEW,1)*2;

end

if nargin<4

ShiftLen=windowLen/2;

end

if fix(ShiftLen)~=ShiftLen

ShiftLen=fix(ShiftLen);

disp('The shift length have to be an integer as it is the number of samples.')

disp(['shift length is fixed to ' num2str(ShiftLen)])

end

[FreqRes FrameNum]=size(XNEW);

Spec=XNEW.*exp(j*yphase);

if mod(windowLen,2) %if FreqResol is odd

Spec=[Spec;flipud(conj(Spec(2:end,:)))];

else

Spec=[Spec;flipud(conj(Spec(2:end-1,:)))];

end

sig=zeros((FrameNum-1)*ShiftLen+windowLen,1);

weight=sig;

for i=1:FrameNum

start=(i-1)*ShiftLen+1;

spec=Spec(:,i);

sig(start:start+windowLen-1)=sig(start:start+windowLen-1)+real(ifft(spec,windowLen));

end

ReconstructedSignal=sig;

function [NoiseFlag, SpeechFlag, NoiseCounter, Dist]=vad(signal,noise,NoiseCounter,NoiseMargin,Hangover)

%[NOISEFLAG, SPEECHFLAG, NOISECOUNTER, DIST]=vad(SIGNAL,NOISE,NOISECOUNTER,NOISEMARGIN,HANGOVER)

%Spectral Distance Voice Activity Detector

%SIGNAL is the the current frames magnitude spectrum which is to labeld as

%noise or speech, NOISE is noise magnitude spectrum template (estimation),

%NOISECOUNTER is the number of imediate previous noise frames, NOISEMARGIN

%

%(default 3)is the spectral distance threshold. HANGOVER ( default 8 )is

%the number of noise segments after which the SPEECHFLAG is reset (goes to

%zero). NOISEFLAG is set to one if the the segment is labeld as noise

%NOISECOUNTER returns the number of previous noise segments, this value is

%reset (to zero) whenever a speech segment is detected. DIST is the

%spectral distance.

%Saeed Vaseghi

%edited by Esfandiar Zavarehei

%Sep-04

if nargin<4

NoiseMargin=3;

end

if nargin<5

Hangover=8;

end

if nargin<3

NoiseCounter=0;

end

FreqResol=length(signal);

SpectralDist= 20*(log10(signal)-log10(noise));

SpectralDist(find(SpectralDist<0))=0;

Dist=mean(SpectralDist);

if (Dist < NoiseMargin)

NoiseFlag=1;

NoiseCounter=NoiseCounter+1;

else

NoiseFlag=0;

NoiseCounter=0;

end

% Detect noise only periods and attenuate the signal

if (NoiseCounter > Hangover)

SpeechFlag=0;

else

SpeechFlag=1;

end

function Seg=segment(signal,W,SP,Window)

% SEGMENT chops a signal to overlapping windowed segments

% A= SEGMENT(X,W,SP,WIN) returns a matrix which its columns are segmented

% and windowed frames of the input one dimentional signal, X. W is the

% number of samples per window, default value W=256. SP is the shift

% percentage, default value SP=0.4. WIN is the window that is multiplied by

% each segment and its length should be W. the default window is hamming

% window.

% 06-Sep-04

% Esfandiar Zavarehei

if nargin<3

SP=.4;

end

if nargin<2

W=256;

end

if nargin<4

Window=hamming(W);

end

Window=Window(:); %make it a column vector

L=length(signal);

SP=fix(W.*SP);

N=fix((L-W)/SP +1); %number of segments

Index=(repmat(1:W,N,1)+repmat((0:(N-1))'*SP,1,W))';

hw=repmat(Window,1,N);

Seg=signal(Index).*hw;

[9348 byte] By [nimi_shonaa] at [2007-11-26 17:45:53]
# 1
http://forum.java.sun.com/help.jspa?sec=formatting
suparenoa at 2007-7-9 0:14:02 > top of Java-index,Java Essentials,Java Programming...
# 2
It sounds like you need to first learn Java. http://java.sun.com/docs/books/tutorial/
sabre150a at 2007-7-9 0:14:02 > top of Java-index,Java Essentials,Java Programming...
# 3
hey thnx for your advice.... but even then... i can't resolve my problem.... and if can help me anyhow then do please...
nimi_shonaa at 2007-7-9 0:14:02 > top of Java-index,Java Essentials,Java Programming...
# 4
hey... i can't get your reply....how can i resolve my problem by formatting text....Message was edited by: nimi_shona
nimi_shonaa at 2007-7-9 0:14:02 > top of Java-index,Java Essentials,Java Programming...
# 5
> hey... i can't get your reply....> > how can i resolve my problem by formatting text....> 1st give the program in Java within the code tags.... Ur java code does not seem like Java-TC
AbiSSa at 2007-7-9 0:14:02 > top of Java-index,Java Essentials,Java Programming...
# 6

hiii

well the program i gave is not in java... the language is MATLAB....

well here is the corresponding java code with the MATLAB program i provided...but that code piece where i had problem is not completed... here the codes are....

<"

import java.awt.*;

import java.lang.Math.*;

import javax.swing.*;

import java.io.*;

import sun.audio.* ;

import javax.sound.sampled.AudioFormat;

import Jama.Matrix;

class MultibandSS{

double [][] multibandss(double []singnal,double []fs){

double wnd[];

double NIS;

//////////////////////////////////////////////

for(int i=0;i<fs.length;i++){

double temp={0.25};

Matrix TEMP =new Matrix(temp);

double fs =new fs(i);

Matrix FS = new Matrix(fs);

Matrix FST = FS.Times(TEMP);

double FST1=FST.getArray();

int w = Math.floor(FST1);

Matrix W = new Matrix(w);

}

//////////////////////////////////////////////////////

double sp[] ={0.4};

Matrix SP = new Matrix(sp);

///FINDING HAMMING//////////

for(int k=0;k<w.length;k++){

double wnd1[]= Math.cos(2*22/7*k/(n-1));

Matrix WND1 = new Matrix(wnd1);

double cons[] = {0.46};

Matrix CONS = new Matrix(cons);

Matrix A = CONS.Times(WND1);

double const1 [] = {0.54};

Matrix CONST1 = new Matrix(const1);

Matrix WND = CONST1.minus(A);

wnd[k+1] = WND.getArray();

}

///////////

////////FIND NO OF INITIAL SILENCE//////////////

///////////////

double [] is ={.25};

Matrix IS = new Matrix(is);

Matrix SPW = SP.times(W);

int row = SPW.getRowDimension();

Matrix idn = identity(int row, int row);

Matrix SPW1 = SPW.plus(idn);

Matrix ISFS = IS.times(FS);

Matrix ISFSW = ISFS.minus(W);

Matrix SPW2 = SPW.inverse();

Matrix ISFW2 = ISFS.times(SPW2);

double isfw2=ISFW2.getArray();

double NIS[] = Math.floor(isfw2);

//////////////

///////////magnitude power/////////////

//////////////

double gamma []={2};

Matrix GAMMA =new Matrix(gamma);

/// //////////////////////////////////////////////////////// //////FINDING SEGMENT////////////

segment(double [] signal,W,sp,%make it a column vector);

double y=seg;

////////////////////////////////////////////////////////////////////////finding fft ///

//matrix object Y

///array object y

///////findig angle & %Noisy Speech Phase///////////

int row=Y.length;

int col=Y[0].length;

int rowcol=(row*col)/2;

int fixrc=Math.floor(rowcol)+1;

double y1[] = new double[fixrc];

for(p=0;p<fixrc;p++){

y1[p]=y[p];

}

Matrix Y1 = new Matrix(y1);

for(int q=1;q<=y1.length;q++){

///////////////////////////////////////////////////////////////////////finding angle///

}

//////////finding abs/////////

for(int ab=1;ab<y1.length;ab++){

double [] yab = Math.abs(y1);

Matrix YAB = new Matrix(yab);

matrix Y= YAB.arrayTimes(GAMMA);

}

/////////finding size/////

int numberOfFrames=Y[0].length;

////Matrix NUMBEROFFRAMES = new Matrix(numberOfFrames);////

int FreqResol=Y.length;

Matrix FREQRESOL = new Matrix(FreqResol);

double ynis[] = new ynis[NIS];

//////// finding Mean//////

for(int nis=1;nis<=NIS;nis++){

ynis[nis] =Y[nis];

Matrix YNIS = new Matrix(ynis);

Matrix TYNIS = YNIS.transpose();

}

double tynis [] = TNYIS.getArray();

int tlen = TYNIS.length;

double sum=0.0;

double m = new double[tlen];

for(int tl=1;tl<=tlen;tl++){

sum=sum+tynis[tl];

}

m=sum/tlen;

Matrix M = new Matrix(m);

Matrix N = M.transpose();

double n = N.getArray();

//////////

////////////SOME SMOOTHING FACTOR FOR NOISING UPDATING////////////

///////////

double noiseCounter = {0};

Matrix NOISECOUNTER = new Matrix(noiseCounter);

double noiseLength = {25};

Matrix NOISELENGTH =new Matrix(noiseLength);

double beta = {0.03};

Matrix BETA = new Matrix(Beta);

double minalpha = {1};

Matrix MINALPHA = new Matrix(minalpha);

double maxalpha = {5};

Matrix MAXALPHA = new Matrix(maxalpha);

double minsnr = {-5};

Matrix MINSNR = new Matrix(minsnr);

double maxsnr = {20};

Matrix MAXSNR = new Matrix(maxsnr);

Matrix MAXMINPHA = MINALPHA.minus(MAXALPHA);

Matrix MAXMINSNR = MINSNR.minus(MAXSNR);

Matrix MAXMINPS = MAXMINSNR.inverse();

Matrix ALPHASLOPE = MAXMINPS.times(MAXMINPHA);

////////////////// double alphaslope[] = ALPHASLOPE.getArray();

Matrix ALPHAMAX = ALPHASLOPE.times(MAXSNR);

Matrix ALPHASHIFT = ALPHAMAX.minus(MAXALPHA);

///////double alphashift[] = ALPHASHIFT.getArray();

//////////////////////

//////////////////////////////////////////////////Matrix BN=objectofn .times(BETA);

////////////////////////

///////////Finding frequency dependent coefficient////////////

double bn[] = BN.getArray();

int N=bn.length;

// int P=bn[0].length;

Matrix BNNN=identity(int N,int N);

double [] const15 = {1.5};

Matrix CONST15 = new Matrix(const15);

Matrix DELTA =BNNN.times(CONST15);

double delta [] =DELTA.getArray();

double c20 = {-2000};

Matrix C20 = new Matrix(c20);

double c2 = {2};

Matrix C2 = new Matrix(c2);

Matrix IC2 = C2.inverse();

Matrix IC2FS =IC2.times(FS);

Matrix IC20FS =IC2FS.plus(C20);

Matrix FRERESOL2= C2.times(FREQRESOL);

Matrix FS1 = FS.inverse();

Matrix FSFR = FS1.times(FRERESOL2);

Matrix ICFSFR = FSFR.times(IC20FS);

double icfsfr=ICFSFR.getArray();

double Fffr[] = Math.floor(icfsfr);

Matrix FFFR = new Matrix(Fffr);

int len=Fffr.length;

///////// %if the frequency is lower than FS/2 - 2KHz///////

//double Delta[] = new double[len];

for(int ff=1;ff<=len;ff++){

delta[ff]=2.5;

}

/////////////%if the frequency is lower than 1KHz//////////////

double c10 = {1000};

Matrix C20= new Matrix(c20);

Matrix FFRC2=FSFR.times(C20);

///

double ffrc2[]=FFRC2.getArray();

double ffrsol = Math.floor(ffrc2);

Matrix FFRSOL = new Matrix(ffrsol);

int lsol=FFRSOL.length;

for(int f=1;f<=lsol;f++){

delta[f]=1;

}

///////////Update and smooth nois//////////////////

for(int nf=1;nf<=numberOfFrames;nf++){

///////CALLING VAD FUNCTION//////////////

Matrix IGAMMA = GAMMA.inverse();

Matrix NIG = IGAMMA.arrayTimes();

vad();

[NoiseFlag, SpeechFlag, NoiseCounter, Dist]=vad(Y(:,i).^(1/Gamma),N.^(1/Gamma),NoiseCounter); %Magnitude Spectrum Distance VAD

}

}

}

//////////////////////////////////////////////////////////

/////////////////////

///////////////////////FUNCTION VAD///////////////////////

////////////////////////

/////////////////////////////////////////////////////////

double vad(double signal [],int noise,int NoiseCounter,int NoiseMargin,int Hangover){

//////////////////////////////////////////////////Three Code will hear/////////////////

Matrix SIGNAL = Matrix(signal);

int FreqResol = SIGNAL.length;

double co20[] = {20};

Matrix CO20 = new Matrix(co20);

double lsig = Math.log(signal);

Matrix LSIG = new Matrix(lsig);

double ct10 = Math.log(10);

Matrix CT10 = new Matrix(ct10);

Matrix ICT10 = CT10.inverse();

Matrix L10S =ICT10.times(LSIG);

double lnoise = Math.log(noise);

Matrix LNOISE = new Matrix(lnoise);

Matrix L10N =ICT10.times(LNOISE);

Matrix LSN =L10N.minus(L10S);

Matrix SPECTRALDIST = CO20.times(LSN);

double SpectralDist[] = SPECTRALDIST.getArray();

int sd = SpectralDist.length;

for(int s=1;s<=sd;s++){

if(SpectralDist[s]><0)

SpectralDist[s] = 0;

///////////////////////////////////////////////////

///////////////

/////////////

///////////////////////FUNCYION SEGMENT/////////////

/////////////

////////////////////////////////////////////////////

double segment(double [][] signal,W,sp,%make it a column vector){

//////finding W with the help of nargine//////////

//double [] w = {256};

//Mateix W = new Matrix(w);

/////////make it a column vector///////////

////finding the lenght with the help of single//////////

int l=single.length;

Matrix L = new Matrix(l);

Matrix SPW = SP.times(W);

double SPW1[]=SPW.getArray();

double sp[] = Math.floor(SPW1);

Matrix SP = new Matrix(sp);

/////////Finding no of Segment///////

Matrix WL = W.minus(L);

Matrix SP1 = SP.inverse();

Matrix SP1WL = SP1.times(WL);

double one[] = {1};

Matrix ONE = new Matrix(one);

Matrix ONEWL = ONE.plus(SP1WL);

double onewl=ONEWL.getArray();

double n[] = Math.floor(onewl);

Matrix N = new Matrix(n);

//Index=/////////////////

int value[] = new int[w];

for(int i=1;i<=w;i++){

value=i;

}

Matrix WN = W.times(N);

double wn[] = WN.getArray();

double value1[][] = new int[wn];

for(int i=1;i<n;i++){

for(int j=1;j<value.length;j++){

value1[j]=value[j];

}

System.out.println();

}

Matrix VALUE1 = new Matrix(value1);

//////////////new REPMAT////////

double o1={1};

Matrix O1 = new Matrix(o1);

Matrix N1 = O1.minus(N);

Matrix IN1 = N1.inverse();

Matrix SPI = SP.times(IN1);

double spi[] = SPI.getArray();

int on=spi.length;

double value2[] = new double[on];

for(int i=0;i<=on;i++){

value2=i;

}

Matrix SPN = SPI.times(N);

double spn[] = SPN.getArray();

double value3[][] = new int[spn];

for(int i=1;i<w;i++){

for(int j=1;j<value2.length;j++){

value3[j]=value2[j];

}

}

Matrix VALUE3 = new Matrix(value3);

Matrix INDEX = VALUE3.plus(VALUE1);

double index = INDEX.getArray();

///////CREATING REPMAT WITH THE HELP OF WINDOW/////////

}

">

nimi_shonaa at 2007-7-9 0:14:02 > top of Java-index,Java Essentials,Java Programming...