Clear Filters
Clear Filters

Fitting data to a new set of frequency

11 views (last 30 days)
Mohammad Khorshidian
Mohammad Khorshidian on 16 Apr 2024 at 19:17
Commented: Voss on 16 Apr 2024 at 21:25
I have two sets of data across two difference frequency points. I need to operate on these two data but since they have different length I'm unable to perform my operations. I'd like to define a unified set of frequency points and fit each of these two set of data to these new frequency points. Can someone please help me with the easiest method/function to do this?
For example, Data1 has frequency points at 1:0.33:34 and Data2 has frequency points 2:0.5:21 and I want to fit both data to frequency points 2:1:20. Thank you.

Accepted Answer

Voss
Voss on 16 Apr 2024 at 19:32
You can use interp1. Example follows:
% some made-up data defined on those frequency vectors
f1 = 1:0.33:34;
f2 = 2:0.5:21;
x1 = 0.25*sind(f1*2);
x2 = 0.2*cosd(f2*4);
% specified common frequency vector
f = 2:1:20;
% plot the original data
figure
plot(f1,x1,'-b',f2,x2,'-r')
% interpolate to common f
x1i = interp1(f1,x1,f);
x2i = interp1(f2,x2,f);
% plot interpolated values
hold on
plot(f,x1i,'bo',f,x2i,'ro')
% make a legend
legend('x1','x2','x1i','x2i')
  2 Comments
Mohammad Khorshidian
Mohammad Khorshidian on 16 Apr 2024 at 21:17
This is exactly what I needed. Thank you so much.

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!