Error in resampling function
20 次查看(过去 30 天)
显示 更早的评论
Hi I am still new to MATLAB but have been instructed to upsample some torque data using a function:
function res_signal_out = resample_zeroshift(res_signal_in, length_resample)
% Zero the signal start
tmp_signal = res_signal_in - res_signal_in(1);
% Flip and append so that signal ends at zero
tmp_signal = [tmp_signal; flipud(tmp_signal)];
% Resample linearly
res_tmp_signal = resample(tmp_signal, length_resample*2, length(tmp_signal));
% Take first half of resampled signal and add offset that was removed
res_signal_out = res_tmp_signal(1:length_resample) + res_signal_in(1);
end
I am calling the function with the script:
clear; clc;
% import data file
textTable = readtable(fullfile(pwd,'Torque08forResampling.TXT'));
% convert data to array
textArray = table2array(textTable);
% iterate through the 7 columns of data in the file and resample using function resample_zeroshift
for i = 1:width(textArray)
textResults(:,i) = resample_zeroshift(textArray(:,i),93001);
end
This function works for a torque file that has only 2993 rows of data, being upsampled to 6000... however when I use the same code for a torque file which is 46517 rows long, upsampling to 93001, the error that I am getting is:
Error using upfirdn>validateinput (line 129)
The product of the downsample factor Q and the upsample factor P must be less than 2^31.
Error in upfirdn (line 81)
[p,q] = validateinput(x,h,varargin);
Error in resample>uniformResample (line 478)
yVec = upfirdn(x,h,p,q);
Error in resample (line 217)
uniformResample(xIn, isDimValSet, Dim, dimIn, numericArgs{:});
Error in resample_zeroshift (line 7)
res_tmp_signal = resample(tmp_signal, length_resample*2, length(tmp_signal));
Would appreciate any help!!
Thanks
PS I am using MATLAB R2021a
0 个评论
采纳的回答
Joel Bottin-Noonan
2023-2-7
编辑:Joel Bottin-Noonan
2023-2-7
Hi Alexandra,
The resample function doesnt allow p*q to be > 2^31 = 2147483648. Because of the error message from the function upfirdn not allowing p*q to be > intmax('int32').
In the resample function it seems you have assigned your p value to be to be double the length of length_resample = 93001*2 = 186002. And your q value to be length(tmp_signal) = 46517*2 (due to the flip and concatenation) = 93034. Therefore your p*q = 17304510068.
My first guess would have been to simplify the fraction of p and q by halving the denominator and numerator.BUT in its simplest form p/q = (186002/2)/(93034/2) = 93001/46517. Giving your p*q = 4326127517 > 2^31.Unfortunately you cant fix this with a decimal point either as p and q are required to be poistive integers.
There are 2 options in my opinion.
1. You could estimate the value of upsample ratio p/q to be 2. Therefore making p = 2 and q = 1.(You can choose a more accurate ratio if you'd like as long as p*q is not > 2^31.)
2.If accuracy of the sampling time is a big issue, cut your data into smaller arrays and resample.
Kind Regards!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!