I'm not sure how to fix this error Warning: Integer operands are required for colon operator when used as index. > In demo (line 147)

2 ビュー (過去 30 日間)
%convolution
y1 = conv(x,h1)*Ts; %multiply by interval Ts to get integral
Nsamps = length(y1); %Nsamps is the length of array y1
t = (Ts)*(1:Nsamps); %Prepare time data for plot
figure
plot(t,y1);
xlim([1.5 1.51]); %only plot t within xlim
xlabel('Time (s)');
ylabel('Amplitude');
title('Convolution with 200Hz Cutoff');
%Do Fourier Transform of the 200Hz Cutoff signal
y_fft = abs(fft(y1 * 5)/Fs); %Normalize the signal & Retain Magnitude
y_fft = (y_fft(1:Nsamps/2)); %Discard Half of Points
f = Fs*(0:Nsamps/2-1)/Nsamps; %Prepare freq data for plot

採用された回答

Voss
Voss 2021 年 12 月 19 日
This is probably due to the fact that Nsamps is odd, so that Nsamps/2 is not an integer, so that this line:
y_fft = (y_fft(1:Nsamps/2)); %Discard Half of Points
produces the warning. It's just a warning (not an error), so you don't need to 'fix' it, but you can avoid it by only using integers with the colon operator when used as indexes. For instance:
if rem(Nsamps,2) == 1
y_fft = y_fft(1:(Nsamps-1)/2);
else
y_fft = y_fft(1:Nsamps/2);
end
or, equivalently:
y_fft = y_fft(1:(Nsamps-rem(Nsamps,2))/2);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by