Error in resampling function

I try to change sampling rate from 4.8kHz to 5kHz
fs=4800;
t1 = 0:1/fs:1;
x = sin(t1);
x2=resample(x,4800,5000);
But I get error
Incorrect number or types of inputs or outputs for function resample.
How to solve it?
Even I used
[p,q]=rat(5000/4800)
x3=resample(x,p,q);
It seems the same error!

7 Comments

It works on my side
BTW , the correct code is
x2=resample(x,5000,4800);
and not
x2=resample(x,4800,5000);
are you sure the resample function in the Signal Processing Toolbox is not hidden by a another function that has the same name in your path or working directory ?
Cheng-Ling Kuo
Cheng-Ling Kuo on 27 Jan 2024
Edited: Cheng-Ling Kuo on 27 Jan 2024
It is hidden by other resample.m
As I try to use
>> which resample
C:\Program Files\MATLAB\R2023b\toolbox\matlab\timeseries\@timeseries\resample.m % timeseries method
After I change the order of signal toolbox in the path list
>> which resample
C:\Program Files\MATLAB\R2023b\toolbox\signal\signal\resample.m
It works. Thank you very much.
It's good that you got it working, but Matlab toolbox functions don't shadow each other. They are (supposed to be) always distinguishable by the precedence rules.
It would be interesting if you went back to your original configuration and executed:
fs=4800;
t1 = 0:1/fs:1;
x = sin(t1);
x2=resample(x,4800,5000);
which resample(x,4800,5000)
/MATLAB/toolbox/signal/signal/resample.m
That which() command will show the version of resample that is being called with the given arguments. It would be odd if it resolved to the timeseries method.
After I deleted the path setting
fs=4800;
t1 = 0:1/fs:1;
x = sin(t1);
x2=resample(x,4800,5000);
which resample(x,4800,5000)
I got the error message, as the same as before
Incorrect number or types of inputs or outputs for function resample.
>> which resample
C:\Program Files\MATLAB\R2023b\toolbox\matlab\timeseries\@timeseries\resample.m % timeseries method
Again I added the path setting
>> which resample
C:\Program Files\MATLAB\R2023b\toolbox\signal\signal\resample.m
Not sure what happened in my matlab. Is there conflict between toolboxes?
There shouldn't be any conflict between TMW toolboxes.
If you don't mind, run these exact commands at the command prompt one at a time with the original setup.
clear all
fs=4800;
t1 = 0:1/fs:1;
x = sin(t1);
class(x)
which resample(x,4800,5000)
If yout get any error messages, please paste back into your response the sequence of commands and the output from the command window, including the entire error message (all of the red text). Make sure it's clear in your repsonse which error message follows which command. Please do not intersperse comments like "I got the error message ..." Basically, we have to see exactly what's being run and the exact results.
I got the following message.
fs=4800;
t1 = 0:1/fs:1;
x = sin(t1);
class(x)
which resample(x,4800,5000)
ans =
'double'
'resample(x,4800,5000)' not found.
So, if trying to execute that resample command it resolves to the timeseries method. But the which command doesn't find anything. No idea what could be the problem.

Sign in to comment.

 Accepted Answer

If you want to use fs = 5000 Hz, then the command syntax has to be resample(x_siganl, time, fs_new) This is how it should be done:
fs=4800;
t1 = 0:1/fs:1;
x = sin(t1);
fs_new = 5e3;
x2=resample(x,t1,fs_new);
which resample(x,t1,fs_new)
/MATLAB/toolbox/signal/signal/resample.m
scatter(t1, x)
hold on
t2 = 0:1/fs_new:1;
scatter(t2, x2(1:end-1))
legend('Original Data', 'Resampled Data', 'Location', 'Best')
grid on
xlabel('t')
ylabel("x & x_{resampled}")
%% View a small portion of the data:
figure
scatter(t1, x)
hold on
t2 = 0:1/fs_new:1;
scatter(t2, x2(1:end-1))
legend('Original Data', 'Resampled Data', 'Location', 'Best')
grid on
xlabel('t')
ylabel("x & x_{resampled}")
xlim([0.95 1])

More Answers (0)

Products

Release

R2023b

Tags

Community Treasure Hunt

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

Start Hunting!