필터 지우기
필터 지우기

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 CenterFile Exchange에서 Fourier 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