Subtracting two vectors of different length
    7 views (last 30 days)
  
       Show older comments
    
Hello,
I am trying to compare two vectors of very different length by using interpolation (R1 - F1). These are values related to the frequency bins described as f_aff and f vectors (respectively). My current code works but it does not seem to do the right thing. See my script below.
I am not sure if I am correct but I think the error maybe be because the frequency vector is non-linear so I am not sure if the linspace here works... 
When I plot these two vectors separately without interpolation, the difference is pretty small but then after interpolation it goes up to 20 dB. 
I would appreciate your help!
f_aff = [125 129 172 215 258 301 344 387 430 473 516 559 602 645 688 731 774 817 860 903 946 989 1032 1075 1118 1161 1204 1247 1290 1333 1376 1419 1462 1505 1548 1591 1634 1677 1720 1763 1806 1849 1892 1935 1978 2021 2064 2107 2150 2193 2236 2279 2322 2365 2408 2451 2497 2537 2580 2623 2666 2709 2752 2795 2838 2881 2924 2967 3010 3053 3096 3139 3182 3225 3268 3311 3354 3397 3440 3483 3526 3569 3612 3655 3698 3741 3784 3827 3870 3913 3956 3999 4042 4085 4128 4171 4214 4257 4300 4343 4386 4429 4472 4515 4558 4601 4644 4687 4730 4773 4816 4859 4902 4945 4988 5031 5074 5117 5160 5203 5246 5289 5332 5375 5418 5461 5504 5547 5590 5633 5676 5719 5762 5805 5848 5891 5934 5977 6020 6063 6106 6149 6192 6235 6278 6321 6364 6407 6450 6493 6536 6579 6622 6665 6708 6751 6794 6837 6880 6923 6966 7009 7052 7095 7138 7181 7224 7267 7310 7353 7396 7439 7482 7525 7568 7611 7654 7697 7740 7783 7826 7869 7912 7955 8000];      
f = [125, 160, 200, 250, 315, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500, 3150, 4000, 5000, 6300, 8000, 10000];
F1_m = [35.4 50	57.8 57.1 57.2 64.3 65.1 65.2 66.4 65.0 64.6 68.4 72 73.8 72.4 70.3 66.3 65.1 63.7 65];
R1_m = [46.9495525566315	48.0385256275429	56.7394910936395	59.0526580982104	57.8898823427092	56.5598810922227	58.2073459581807	59.3866454154771	58.3950368323739	58.8199162224362	61.9296747113695	63.0969864811895	60.7879172041026	57.3170848211968	60.7188155387509	62.0582099275805	60.1723427899083	56.9803700421588	55.6347526633159	56.3474293999317	57.4697167980110	59.1332558500579	60.1472787808621	60.0700214652395	58.1676314128097	56.4107148752243	58.4685305240429	60.8140271008369	61.5126142738754	60.4956251086211	59.6556204846324	58.4236301798295	57.9374910794919	60.5622411865936	63.1375533480448	64.9511183524034	64.8476467038119	64.9025455169853	63.4472618963326	61.0155598172182	61.4237963394965	63.6638870733989	64.9954449383057	65.6656491635678	66.5262451579203	66.9105699595665	66.7287029388819	66.2255597367988	65.4700233075733	65.4855983849100	67.2464501321911	69.9080552671495	71.9552205168995	71.8986939021709	71.2182752711739	71.7953224013434	72.0485719479038	71.6554581661854	70.6533058677423	70.7459826221040	72.5498793344994	74.2827882995270	75.1329565759775	75.7420636821961	75.6914519367813	75.2796338178501	74.4716993754235	73.2781974313175	72.3862361067673	73.1483619180440	73.0750739043636	72.7099302183872	72.0222399591912	71.9027602718696	70.8335543208131	70.4076791756693	69.8605791056181	69.6092517365672	68.7526959862595	67.7324282910174	67.7991858416926	68.4551178973679	69.8746112187334	70.9466366085484	70.0428364881271	68.7269740993748	68.4971983333549	67.8397098760714	68.0440389888663	67.8073626318051	67.2347068241060	66.9425225562858	65.8236572406199	64.7565656795052	64.5942847791963	64.4232361865823	65.1980549942284	65.4479025455588	65.0671287009502	64.5758128537930	63.7949152533354	63.0458796308529	62.7355424443258	62.4360128568897	61.4913612591605	60.3833723058361	60.4330285882857	60.9186529157498	61.3391017974483	62.1022050022118	62.5338066666576	62.5875493933869	61.5056000644960	60.1370032732948	59.7234100407571	60.4256524582559	60.7183699531295	59.3473586169763	58.8191038661669	59.4782003376343	60.3960244231483	60.9971961250525	60.8662182325371	60.6295066579305	60.9115791987718	60.5834947987681	59.8773567280509	58.8190898299718	58.3662174037829	57.8211830875231	55.9721517225508	55.4655187820830	55.1357713572842	55.5987703734668	55.4501886343092	55.5926044746766	56.2628681171663	56.2422405693999	56.0066763588240	57.0821192658925	58.4264865255485	58.6712881614999	58.4456620086571	57.9624866349172	58.1616957091606	58.3558387131633	57.7337606307656	57.5354877251610	57.8315275221234	58.0559771099481	57.7420874610169	56.4452817336371	56.6065146047738	57.2900951682665	57.5010422723460	58.0814352999206	58.3130680512442	58.6314234228966	58.4888129562938	58.3346209135367	57.3122257895209	56.4843907798461	56.2327147066294	56.0637890640808	55.3209902146068	55.5382575383832	55.4977169373532	54.7479846374780	55.1323914183025	55.4564144147509	55.0461578255621	54.2568171478017	53.9245645352059	54.5689992544002	54.8731771104946	54.3875880321623	53.2008885786154	52.8017592144459	51.9694080931309	51.6435567214985	51.1985111648497	50.4133912244660	50.0592902032103	50.2735671563406	50.4594062567421];
F1_m = F1_m([1:19]); %cutting the last value for 10kHz
xo2 = 1:numel(F1_m);
xi2 = linspace(1, numel(F1_m), length(R1_m));
F1_int = interp1(xo2, F1_m, xi2);
semilogx(f_aff, R1_m-F1_int)         
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

