How to find input data that best matches given output data

2 次查看(过去 30 天)
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 个评论
dpb
dpb 2017-1-23
@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 2017-1-24
allright, guys, I have edited my question. I hope it is clear now.

请先登录,再进行评论。

采纳的回答

dpb
dpb 2017-1-25
  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
>>

更多回答(1 个)

Lateef Adewale Kareem
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 个评论
Luki
Luki 2017-1-23
编辑:Luki 2017-1-23
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 2017-1-24
So, Lateef, I have edited my question quite a bit. I hope my question is clear now, maybe you can help?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by