-2

This is the part causing the problem. I am really not able to find anything not ok. This part is for the mel binning function for a front end construction.

The original document is at http://www.ee.columbia.edu/~stanchen/fall12/e6870/labs/lab1.html

Thanks for any help in advance!

double fmax = 0;
double w = 0;       // half of the length of the bottom line of each bin of triangular

fmax = 1127*log(1+1/(1400*samplePeriod));
w = fmax/27;

double f    = 0;
double fmel = 0;
double xf   = 0;
double H    = 0;
double sum  = 0;

for (int frmIdx = 0; frmIdx < inFrameCnt; ++frmIdx)
    for (int dimIdx = 0; dimIdx < outDimCnt; ++dimIdx){
        sum = 0;
        for (int j = 0; j < 256; ++j){
            f = j/(256/20000);
            fmel = 1127*log(1+f/700);
            xf = sqrt(inFeats(frmIdx,2*j)*inFeats(frmIdx,2*j)+inFeats(frmIdx,2*j+1)*inFeats(frmIdx,2*j+1));
            if (fmel > dimIdx*w && fmel < (dimIdx+1)*w){
                H = (fmel- dimIdx*w)/w;
            }
            else if(fmel > ((dimIdx+1)*w) && fmel < ((dimIdx+2)*w)){
                H = ( (dimIdx+2)*w-fmel)/w;
            }
            else {
                H = 0;
            }
            sum = sum + xf*H;
        }
        outFeats(frmIdx,dimIdx)=sum;

        if (doLog == true){
            outFeats(frmIdx,dimIdx) = log(outFeats(frmIdx,dimIdx));
        }
        else{
            outFeats(frmIdx,dimIdx) = outFeats(frmIdx,dimIdx);
        }
    }
phuclv
  • 37,963
  • 15
  • 156
  • 475
Yaozhong
  • 89
  • 1
  • 2
  • 7
  • @Yazohong I mean where the exception occurs? –  Oct 04 '12 at 20:45
  • I didn't know, as I commented all this part, there would be no exception. As i uncommented this part, exception appeared. Anyway, I have solved this by changing to f=j/(256.0/20000.0). Thanks! – Yaozhong Oct 04 '12 at 20:52

1 Answers1

1

Check that there are no divisions by zero.
this is the first one that is 0 by definition:
f = j/(256/20000); // (256 and 20000 are treated as integers)
256. / 20000. (or 256.0 / 20000.0 ) would make a float.

Aki Suihkonen
  • 19,144
  • 1
  • 36
  • 57