Bypassing the sampling limits of resample function of p*q<2^31

5 ビュー (過去 30 日間)
r
r 2024 年 12 月 19 日
回答済み: Abhas 2024 年 12 月 31 日
So I have 3 arrays which I want to resample into equal length. I am using the code
C1=resample(c1,target_length,length(c1));
C2=resample(c2,target_length,length(c2));
C3=resample(c3,target_length,length(c3));
where target_length is 70000. The matrix sizes of c1,c2, and c3 are 1x72901, 1x72392, and 1x723532. As expected it gives an error due to the "The product of the downsample factor Q and the upsample factor P must be less than 2^31." I cannot use interp1 as I need unique points too. Is there a way around this or to bypass this restriction for this problem?
  6 件のコメント
r
r 2024 年 12 月 19 日
%original length of c1,c2,c3,v1,v2,v3>70000
%shortening it to fit each others
% Define target length
target_length = 50000; % Desired length for resampling
% equally spaced voltage arrays as max and min are the same;
Vmax=cellfun(@max,v2);
Vmin=cellfun(@max,v2);
V1=linspace(Vmax(1,1),Vmin(1,1),target_length);
V2=linspace(Vmax(1,2),Vmin(1,2),target_length);
V3=linspace(Vmax(1,3),Vmin(1,3),target_length);
C1=interp1(c1,v1,V1);
C2=interp1(c2,v2,V2);
C3=interp1(c3,v3,V3);
r
r 2024 年 12 月 20 日
@Meet this is the dropbox link
You can go to the processed mat folder and run the data analysis file.
This is the paper explaning the files. I am currently interested in only the capacity test so I extracted the values for all the 15 batteries and stored them in .mat files.

サインインしてコメントする。

回答 (1 件)

Abhas
Abhas 2024 年 12 月 31 日
Hi @r,
The issue arises because the "interp1" function in MATLAB requires the "x" array to have unique values, and your voltage data (the x input) may not satisfy this condition. To bypass the limitations of "interp1" or "resample", you can use a custom approach to handle duplicate or non-unique "x" values by following the below steps:
  • Identify and remove duplicate "x" values by averaging the corresponding "y" (capacity) values. This step ensures "interp1" works correctly.
  • After handling duplicates, use "interp1" to interpolate the data to the desired "target_length".
  • If "c1", "c2", or "c3" has too large or too small lengths, adjust them accordingly to avoid errors during resampling.
Here's a sample MATLAB code to achieve the same:
target_length = 70000;
c1 = rand(1, 72901);
c2 = rand(1, 72392);
c3 = rand(1, 723532);
% Example voltage arrays (replace with actual voltage data)
V1 = linspace(min(c1), max(c1), length(c1));
V2 = linspace(min(c2), max(c2), length(c2));
V3 = linspace(min(c3), max(c3), length(c3));
% Resample each dataset
C1 = handle_duplicates_and_resample(V1, c1, target_length);
C2 = handle_duplicates_and_resample(V2, c2, target_length);
C3 = handle_duplicates_and_resample(V3, c3, target_length);
% Display results
disp(size(C1));
disp(size(C2));
disp(size(C3));
% Function to handle duplicates and resample
function resampled_data = handle_duplicates_and_resample(x, y, target_length)
% Ensure unique x values
[x_unique, ~, idx] = unique(x, 'stable'); % 'stable' keeps original order
y_unique = accumarray(idx, y, [], @mean); % Average y values for duplicates
% Resample using interp1
x_resampled = linspace(min(x_unique), max(x_unique), target_length);
resampled_data = interp1(x_unique, y_unique, x_resampled, 'linear');
end
You may refer to the below MathWorks documentation links to know more about the same:
  1. https://www.mathworks.com/help/matlab/ref/double.unique.html
  2. https://www.mathworks.com/help/matlab/ref/accumarray.html
  3. https://www.mathworks.com/help/matlab/ref/double.interp1.html
I hope this helps!

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by