three level DFT need help in error

1 visualización (últimos 30 días)
common fernando
common fernando el 4 de Dic. de 2020
Editada: KALYAN ACHARJYA el 4 de Dic. de 2020
clear all; close all; clc
fs=200; %sampling freq.
dt =1/fs;
N0=fs/3; %number of samples/cycle
m=3; %no. of cycles
t = linspace(0,200,1+N0*m); %data window
fi=50; %Frequency test
ww=wgn(201,1,-40);
size(transpose(ww))
x= sin(2*pi*fi*t + 0.3);
v = bsxfun( @plus, x , ww );
%v=@(t) (sin(2*pi*fi.*t + 0.3)+ transpose(wgn(1+N0*m,1,-40)));
tmax=1;
n=N0-1:-1:0;
f0=50;
f=50.88;
Hc=2/N0*cos(2*pi*n/N0+pi/N0);
Hs=-2/N0*sin(2*pi*n/N0+pi/N0);
t_est=[];
f_est=[];
j_max=tmax*fs;
for j=1:j_max+1
x=v((j-1:j+N0-2)*dt);
c(j)=x*Hc';
s(j)=x*Hs';
if(j>N0)
Ac(j-N0)=sqrt(sum(c(end-N0+1:end).^2)/N0);
As(j-N0)=sqrt(sum(s(end-N0+1:end).^2)/N0);
cc(j-N0)=c(end-N0+1:end)*Hc';
ss(j-N0)=c(end-N0+1:end)*Hs';
if(j>2*N0)
Acc(j-2*N0)=sqrt(sum(cc(end-N0+1:end).^2)/N0);
Ass(j-2*N0)=sqrt(sum(ss(end-N0+1:end).^2)/N0);
ccc(j-2*N0)=cc(end-N0+1:end)*Hc';
ccs(j-2*N0)=cc(end-N0+1:end)*Hs';
ssc(j-2*N0)=ss(end-N0+1:end)*Hc';
sss(j-2*N0)=ss(end-N0+1:end)*Hs';
ff=f0*N0/pi*atan(tan(pi/N0)*((ccc(j-2*N0).^2+ccs(j-2*N0).^2)./(ssc(j-2*N0).^2+sss(j-2*N0).^2)).^.25);
t_est=[t_est;(j-1)*dt];
f_est=[f_est;ff];
end
end
end
t_est;
f_est
RMSE = sqrt(mean((f_est-fi).^2))
plot(t_est,f_est,'red')
hold on
xlabel('time')
ylabel('frequency')
title('three LDFT white noise')
plot (t,fi)
plot (t,fi)
hold off
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ERROR
Subscript indices must either be real positive integers or logicals.
Error in CODE (line 23)
x=v((j-1:j+N0-2)*dt);
>>

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 4 de Dic. de 2020
Editada: KALYAN ACHARJYA el 4 de Dic. de 2020
Please note: MATLAB allows positive array indices only, examples
data(-2); % Invalid
data(0); % Invalid
data(4); % Valid
Whatever you do during array indexing, please make sure that within "()", there should be a positive integer values only such as 1,2,3,….
In the code, as you have shared, in the first iteration of the loop
N0=fs/3; %Which approximately equal to 66.67
For the iteration, once the "j" reach to 67, then "if condition" becomes true, in that case:
for j=1:j_max+1
...
if j>N0
Ac(j-N0)=....
end
end
Here
A(67-N0)
A(67-66.66)
%.. ^= is no a positive integer
Hope you get the points of error. Hence requested to do the coding in such a way that, which only generates positive values with array indexing.
:)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by