How to find input data that best matches given output data

2 views (last 30 days)
f2 = linspace(-fs/2,fs/2,length(x));
f1 = transpose(f2(end/2+1:end));
freq = transpose([10.7e9 11.213e9 11.725e9 12.238e9 12.75e9]);
Given data:
fs/2 = 5e11
length(x) = 1048576
I am looking for the entries of f1 corresponding to all frequencies between min(freq) and max(freq). I was thinking to achieve this with:
find(ismembertol(f1,min(freq),0.0001e+10) ==1);
But this gives the error: "Index exceeds matrix dimensions".
So for example, entries 11219,11220,11221 of f1 are:
  1. 10698805521,7795 rounded to 1.0699e+10
  2. 10699759197,0054 rounded to 1.0700e+10
  3. 10700712872,2314 rounded to 1.0701e+10
So apparently there is no entry of f1 equal to min(freq) = 10.7e9. So, two questions: First: Can I make f1 have frequencies ranging from min(freq) to max(freq) in steps of 0.001e9 just by changing length(x) ? I mean these frequencies have to be within the range of f1, but f1 is also allowed to have smaller and/or higher frequencies.
Second: If there is no such way to achieve my first question, how do I at least find the closest frequencies of f1 corresponding to frequencies between min(freq) and max(freq) ? In the example given, this would be entry 11220 of f1.
Thanks for help!!
  4 Comments
dpb
dpb on 23 Jan 2017
@Jan -- I believe those are Luki just giving us numerical values for the variables above for context...so fs would be 1E10, etc., ...
Luki
Luki on 24 Jan 2017
allright, guys, I have edited my question. I hope it is clear now.

Sign in to comment.

Accepted Answer

dpb
dpb on 25 Jan 2017
  1. f=[freq(1):100000:freq(end)].'; % if want fixed df between ranges use colon instead of linspace
  2. ix=interp1(f1,1:length(f1),freq,'nearest'); % to find closest to given freq in vector f1
Answers for 2. above...
>> [ix f1(ix)/1E6 freq/1E6 f1(ix)-freq]
ans =
1.0e+05 *
0.1122 0.1070 0.1070 -2.4080
0.1176 0.1121 0.1121 -1.6353
0.1230 0.1172 0.1172 -0.3994
0.1283 0.1224 0.1224 0.3734
0.1337 0.1275 0.1275 1.6093
>>

More Answers (1)

Lateef Adewale Kareem
Lateef Adewale Kareem on 23 Jan 2017
I guess this is what you wanted fs/2 = 5e11 length(x) = 958576 freq = transpose([10.7 11.213 11.725 12.238 12.75] e9)
f2 = linspace(-fs/2,fs/2,length(x));
f1 = transpose(f2(end/2+1:end));
you didnt tell us what v is. my guess is v must be of the same dimension as freq and f1 will contain 479289 elements.
if you tell us the error message you are getting we may be able to help interpol_v = interp1(freq,v,f1,'spline');
  2 Comments
Luki
Luki on 23 Jan 2017
Edited: Luki on 23 Jan 2017
you're right, v has the same dimension as freq. There is no error message. When I evaluate v at all frequencies f1, I will also consider frequencies which are much smaller than min(freq). I think the solution is just to evaluate v at f1, but then only consider entries 10257 to 12222 of the output vector, since:
find(ismembertol(f1,min(freq),1e-6) ==1) = 10257
find(ismembertol(f1,max(freq),1e-6) ==1) = 12222
This should then give me the values of v for frequencies which are contained in f1 and also within the range of min(freq) to max(freq). Am I right?
Luki
Luki on 24 Jan 2017
So, Lateef, I have edited my question quite a bit. I hope my question is clear now, maybe you can help?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!