"Johannes Mulder" <JCM@eo.ie.philips.nl> wrote:
> To VRF : Interpolating to differently spaced array - revisited
>
> /* Function ReSample
> * purpose: map an array of samples into a differently
> * mapped array, using lineair interpolation
> *
> * OrgF[0] must be lower than NewF[0]
> * OrgF[M] must be higher than NewF[N-1]
> * to be sure interpolation works always properly
> *
Thanks for the source!
One observation though - I glanced thru the code and so far as I can tell
it does the same (or very similar) job as the Build Arb Waveform object.
Is this code perhaps more efficient? Am I missing something?
Guess I was kind of hoping for a cubic spline fit rather than linear
interpolation, though I suppose one could alter that section of
this code appropriately.
Anyone have a cubic spline algorithm in C that could be spliced into
this function?
thanks
Stan Bischof
stanb@sr.hp.com
From: "Johannes Mulder" <JCM@eo.ie.philips.nl>
To: Stan Bischof <stanb@hpnmrsb2.sr.hp.com>
Date: Mon, 29 Jan 1996 17:47:39 GMT+0100
Subject: Re: VRF : Interpolating to differently spaced array
> From: Stan Bischof <stanb@hpnmrsb2.sr.hp.com>
> Date: Mon, 29 Jan 1996 08:14:43 -0800 (PST)
> To: JCM@eo.ie.philips.nl
> Cc: hpvxd_xc%hpislsup.lvld.hp.com@hplb.hpl.hp.com
> Subject: Re: VRF : Interpolating to differently spaced array
>
> Thanks for the source!
>
> One observation though - I glanced thru the code and so far as I can tell
> it does the same (or very similar) job as the Build Arb Waveform object.
>
The big difference is that the output array does not need to be
equidistant (spelling OK?), and that is what I need. The resulting
array needs to match exactly the given frequencies. I don't know an
easy way to do this using any built-in function.
Thanks for your reaction.
With kind regards,
Johannes Mulder
Philips Electron Optics
Building AAE-room 21
P.O.B. 218
5600 MD ACHT, the Netherlands
tel +31 40 2766947
fax +31 40 2766820
> To VRF : Interpolating to differently spaced array - revisited
>
> /* Function ReSample
> * purpose: map an array of samples into a differently
> * mapped array, using lineair interpolation
> *
> * OrgF[0] must be lower than NewF[0]
> * OrgF[M] must be higher than NewF[N-1]
> * to be sure interpolation works always properly
> *
Thanks for the source!
One observation though - I glanced thru the code and so far as I can tell
it does the same (or very similar) job as the Build Arb Waveform object.
Is this code perhaps more efficient? Am I missing something?
Guess I was kind of hoping for a cubic spline fit rather than linear
interpolation, though I suppose one could alter that section of
this code appropriately.
Anyone have a cubic spline algorithm in C that could be spliced into
this function?
thanks
Stan Bischof
stanb@sr.hp.com
From: "Johannes Mulder" <JCM@eo.ie.philips.nl>
To: Stan Bischof <stanb@hpnmrsb2.sr.hp.com>
Date: Mon, 29 Jan 1996 17:47:39 GMT+0100
Subject: Re: VRF : Interpolating to differently spaced array
> From: Stan Bischof <stanb@hpnmrsb2.sr.hp.com>
> Date: Mon, 29 Jan 1996 08:14:43 -0800 (PST)
> To: JCM@eo.ie.philips.nl
> Cc: hpvxd_xc%hpislsup.lvld.hp.com@hplb.hpl.hp.com
> Subject: Re: VRF : Interpolating to differently spaced array
>
> Thanks for the source!
>
> One observation though - I glanced thru the code and so far as I can tell
> it does the same (or very similar) job as the Build Arb Waveform object.
>
The big difference is that the output array does not need to be
equidistant (spelling OK?), and that is what I need. The resulting
array needs to match exactly the given frequencies. I don't know an
easy way to do this using any built-in function.
Thanks for your reaction.
With kind regards,
Johannes Mulder
Philips Electron Optics
Building AAE-room 21
P.O.B. 218
5600 MD ACHT, the Netherlands
tel +31 40 2766947
fax +31 40 2766820
On request the source code of my solution
*********************************************
***THE C-CODE:
void _far _cdecl ReSample(
int N, /* length of array NewF[], OutV[] */
int M, /* length of array OrgF[], OrgV[] */
double NewF[], /* New Frequencies - sorted upwards */
double OrgF[], /* Original Frequencies - sorted upwards */
double OrgV[], /* Original Value - to be interpolated */
double OutV[]) /* Output-values : linear interpolation */
/* between OrgF-values for NewF-frequencies */
{
/* Function ReSample
* purpose: map an array of samples into a differently
* mapped array, using lineair interpolation
*
* OrgF[0] must be lower than NewF[0]
* OrgF[M] must be higher than NewF[N-1]
* to be sure interpolation works always properly
*
* INTERNALS:
* i index 0 .. N-1
* j index 0 .. M-1
*
*/
int j,i;
/* How the OrgF[] and OrgV[] arrays could be extended,
* before this function is called
*
* extend OrgF-array at begin:
* IntV[0] = OrgV[0];
* IntF[0] = minimum(NewF[0], OrgF[0]-1);
* copy OrgF-array:
* j=0;
* while (j<M)
* {
* IntV[j+1] = OrgV[j];
* IntF[j+1] = OrgF[j];
* j++
* }
* extend OrgF-array at end:
* IntV[M+1] = OrgV[M-1];
* IntF[M+1] = maximum(NewF[N-1]+1, OrgF[M-1]+1);
* M=M+2;
*/
/* init i,j: pre-condition OrgF[j] <= NewF[i]
* OrgF[j+1] > NewF[i]
*/
i = 0;
j = 0;
while (NewF[i] >= OrgF[j+1]) j++;
/* loop thru NewF[] values */
while (i < N)
{
/* interpolation */
OutV[i] = OrgV[j] + ((NewF[i]-OrgF[j]) / (OrgF[j+1]-OrgF[j]) *
(OrgV[j+1]-OrgV[j]));
/* next i,j: satisfy pre-condition */
i++;
while (NewF[i] >= OrgF[j+1]) j++;
}
}
*********************************************
***THE DEFINITION FILE FOR HPVEE
/*
definition file for ReSample.c
*/
void ReSample(
int N, /* length of array NewF[], OutV[] */
int M, /* length of array OrgF[], OrgV[] */
double NewF[], /* New Frequencies - sorted upwards */
double OrgF[], /* Original Frequencies - sorted upwards */
double OrgV[], /* Original Value - to be interpolated */
double OutV[]) /* Output-values : linear interpolation */
; /* between OrgF-values for NewF-frequencies */
*********************************************
***GENERAL REMARKS
- The required extension of the arrays OrgV and OrgF is done
outside the C-code, in a VEEuserobject.
Extension of the OrgV can be done by extrapolating or by
copying the outside values, depends on the application.
- By converting the Frequency arrays first to log-values, the
interpolation will be logarithmic, which is mostly suitable
for frequency related problems.
With kind regards,
Johannes Mulder
Philips Electron Optics
Building AAE-room 21
P.O.B. 218
5600 MD ACHT, the Netherlands
tel +31 40 2766947
fax +31 40 2766820