C question

This is a discussion on C question within the C Programming forums, part of the General Programming Boards category; Hi, Im trying to convert from C to MATLAB. Im a bit stuck with the following code. I need to ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    5

    C question

    Hi,

    Im trying to convert from C to MATLAB.

    Im a bit stuck with the following code. I need to know what is returned in OverallGainFilter?? This parameter is used elsewhere in the program.


    (1) Call the function:
    Code:
    float   overallGainFilter = interpolate ((float) 1000, filter_curve_db, number_of_points);
    filter_curve_db is a 26 by 2 matrix;
    number_of_points=26;

    (2) The function (interpolation):
    Code:
    float interpolate (float    freq, 
                       double   filter_curve_db [][2],
                       int      number_of_points) {
        double  result;
        int     i;
        double  freqLow, freqHigh;
        double  curveLow, curveHigh;
    	
        
        if (freq <= filter_curve_db [0][0]) {
            freqLow = filter_curve_db [0][0];
            curveLow = filter_curve_db [0][1];
            freqHigh = filter_curve_db [1][0];
            curveHigh = filter_curve_db [1][1];
            result = ((freq - freqLow) * curveHigh + (freqHigh - freq) * curveLow)/ (freqHigh - freqLow);
    		return (float) result;
        }
    
        if (freq >= filter_curve_db [number_of_points-1][0]) {
            freqLow = filter_curve_db [number_of_points-2][0];
            curveLow = filter_curve_db [number_of_points-2][1];
            freqHigh = filter_curve_db [number_of_points-1][0];
            curveHigh = filter_curve_db [number_of_points-1][1];
            result = ((freq - freqLow) * curveHigh + (freqHigh - freq) * curveLow)/ (freqHigh - freqLow);
    		return (float) result;
        }
            
        i = 1;
        freqHigh = filter_curve_db [i][0];
        while (freqHigh < freq) {
            i++;
            freqHigh = filter_curve_db [i][0];    
        }
        curveHigh = filter_curve_db [i][1];
    
        freqLow = filter_curve_db [i-1][0];
        curveLow = filter_curve_db [i-1][1];
    
        result = ((freq - freqLow) * curveHigh + (freqHigh - freq) * curveLow)/ (freqHigh - freqLow);
    	
    	
    	return (float) result;
    
    }
    Can anyone tell me what is returned in overallGainFilter??

    Thanks for any help.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    My guess is a floating point number.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    5
    Quote Originally Posted by quzah
    My guess is a floating point number.


    Quzah.
    And snow is usually white.

    Does anyone else have an idea what exactly is returned to overallGainFilter /how it is altered by function?

    Thanks for any help.

  4. #4
    Bob Dole for '08 B0bDole's Avatar
    Join Date
    Sep 2004
    Posts
    618
    >And snow is usually white.

    You're an ass.
    My guess is also a floating point number.

    Hence initializing overallGainFilter as a float and setting it equal to the return of that function...
    Hmm

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    29
    I'm 'guessing' it's a float too. And your an ass too...lol...sorry
    Code:
    float  interpolate { ... }
    float - this is the return data type of a function. Thus, a floating point number e.g. 3.212.
    Disk space: the final frontier

  6. #6
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,801
    The exact value returned by the function depends on the input and without knowing the input one could only make a general statement as to what is returned... a floating point number.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    29
    Well, from the given code, the function interpolate is expecting to return a 'float'. I don't see how the input arguments and the return type are connected. You could have a char as a parameter but return back an integer. It's a messy game. It all depends really on the function definition.

    Until we see the function definition and what the user wants the function to do, only then can we really be sure if the return type is correct.
    Disk space: the final frontier

  8. #8
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Could it possibly be returning decibels???

    The logic looks like it some sort of variant to calculate the gain of a filter as a function of frequency.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21