Got error in resample function

4 views (last 30 days)
Yijin
Yijin on 9 Apr 2025
Answered: Star Strider on 9 Apr 2025
I am a beginner of Matlab and I was trying to resample y by this resample function
but i got an error: " Incorrect number or types of inputs or outputs for function resample. "
please tell me what is the problem if you know. thanks a lot.
load handel.mat
y = y(:);
Fs = 8192;
fc = 2e5;
Fs_new = ceil( (Fs/2 + fc) / Fs * 2 ) * Fs;
y_resampled = resample(y,Fs_new,Fs);
  5 Comments
Image Analyst
Image Analyst on 9 Apr 2025
Set a breakpoint at that line and step into resample to further investigate.
Yijin
Yijin on 9 Apr 2025
problem solved. I forgot to install toolbox, thanks a lot

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 9 Apr 2025
An alternative approach could be to creeate a timetable and then use the retime function —
load handel.mat
y = y(:)
y = 73113×1
0 -0.0062 -0.0750 -0.0312 0.0062 0.0381 0.0189 -0.0250 -0.0312 -0.0750
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Fs = 8192;
fc = 2e5;
t = linspace(0, numel(y)-1, numel(y)).'/Fs; % Create Time Vector
Fs_new = ceil( (Fs/2 + fc) / Fs * 2 ) * Fs
Fs_new = 409600
% y_resampled = resample(y,Fs_new,Fs);
ytt = timetable(seconds(t), y) % Original ‘timetable’
ytt = 73113x1 timetable
Time y ______________ __________ 0 sec 0 0.00012207 sec -0.0061568 0.00024414 sec -0.075036 0.00036621 sec -0.031169 0.00048828 sec 0.0061568 0.00061035 sec 0.038095 0.00073242 sec 0.018855 0.00085449 sec -0.025012 0.00097656 sec -0.031169 0.0010986 sec -0.075036 0.0012207 sec -0.12583 0.0013428 sec -0.1443 0.0014648 sec -0.18124 0.0015869 sec -0.19048 0.001709 sec -0.075036 0.0018311 sec -0.012698
yttrs = retime(ytt, 'regular', 'linear', SampleRate=Fs_new) % Resulting ‘timetable’ After Using ‘retime’
yttrs = 3655601x1 timetable
Time y ______________ ___________ 0 sec 0 2.4414e-06 sec -0.00012314 4.8828e-06 sec -0.00024627 7.3242e-06 sec -0.00036941 9.7656e-06 sec -0.00049254 1.2207e-05 sec -0.00061568 1.4648e-05 sec -0.00073882 1.709e-05 sec -0.00086195 1.9531e-05 sec -0.00098509 2.1973e-05 sec -0.0011082 2.4414e-05 sec -0.0012314 2.6855e-05 sec -0.0013545 2.9297e-05 sec -0.0014776 3.1738e-05 sec -0.0016008 3.418e-05 sec -0.0017239 3.6621e-05 sec -0.001847
These are part of core MATLAB, so you should have them.
.

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!