Error using + Matrix dimensions must agree.

조회 수: 1 (최근 30일)
common fernando
common fernando 2020년 12월 2일
댓글: common fernando 2020년 12월 4일
by using white noise effect in the three level discrete F T:
clear all; close all; clc
fs=200; %sampling freq.
dt =1/fs;
N0=fs/50; %number of samples/cycle
m=3; %no. of cycles
t = dt*(0:200); %data window
fi=50; %Frequency test
ww=wgn(201,1,-40);
size(transpose(ww))
v=@(t) sin(2*pi*fi*t + 0.3)+transpose(ww);
tmax=1;
% v : as function of time
% fs : sampling frequency (Hz)
% tmax : time of final estimation
% to test: [t,f]=ZC(@(t)(220*sin(2*pi*50.1*t+pi/2)),50*512,1)
% to test: [t,f]=ZC(@(t)(220*sin(2*pi*50.1*t+pi/2)+randn(1)*.1),50*512,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((200: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
plot(t_est,f_est,'red')
o=rms(fi)
c=rms(f_est)
RMSE = sqrt(mean(c - o).^2)
t_est;
f_est
plot(t_est, f_est,'red')
hold on
RMSE = sqrt(mean((f_est-fi).^2))
xlabel('time')
ylabel('frequency')
title('three LDFT white noise')
plot (t_est,fi*ones(size(t_est)))
hold off
the error is :
Error using +
Matrix dimensions must agree.
Error in @(t)sin(2*pi*fi*t+0.3)+transpose(ww)
Error in threeDFT (line 33)
x=v((200:j+N0-2).*dt);
  댓글 수: 2
Rik
Rik 2020년 12월 3일
Please write your comments in the comments, not in flags. You can use links to the comment itself if you want an unambiguous reference.
common fernando
common fernando 2020년 12월 4일
ok

댓글을 달려면 로그인하십시오.

채택된 답변

VBBV
VBBV 2020년 12월 3일
%t = dt*(0:200); %data window COMMENT THIS LINE IN YOUR PROGRAM
fi=50; %Frequency test
ww=wgn(201,1,-40);
size(transpose(ww))
v=@(t) sin(2*pi*fi*t + 0.3)+transpose(ww); % using function handle
since you are using fuinction handle to define v in terms of t and calling inside the for loop with varying length of t
for j=1:j_max+1
x=v((200:j+N0-2).*dt); % ....
you dont have to define data window at beginning, comment that line
  댓글 수: 3
Walter Roberson
Walter Roberson 2020년 12월 3일
There is no point in defining t as a symbolic variable. Any initilization you do to t is ignored when you create an anonymous function with named parameter t: inside the body of the anonymous function, any named parameter will be replaced by the value passed into the function handle.
common fernando
common fernando 2020년 12월 3일
clear all; close all; clc
fs=200; %sampling freq.
dt =1/fs;
N0=fs/50; %number of samples/cycle
m=3; %no. of cycles
t = dt*(0:200); %data window
fi=50; %Frequency test
ww=wgn(201,1,-40);
size(transpose(ww))
x= sin(2*pi*fi*t + 0.3);
%v=@(t) sin(2*pi*fi*t + 0.3)+transpose(ww);
v = bsxfun( @plus, x , ww );
tmax=1;
% v : as function of time
% fs : sampling frequency (Hz)
% tmax : time of final estimation
% to test: [t,f]=ZC(@(t)(220*sin(2*pi*50.1*t+pi/2)),50*512,1)
% to test: [t,f]=ZC(@(t)(220*sin(2*pi*50.1*t+pi/2)+randn(1)*.1),50*512,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((200: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
plot(t_est,f_est,'red')
o=rms(fi);
c=rms(f_est)
RMSE = sqrt(mean(c - o).^2)
t_est;
f_est
plot(t_est, f_est,'red')
hold on
RMSE = sqrt(mean((f_est-fi).^2))
xlabel('time')
ylabel('frequency')
title('three LDFT white noise')
plot (t_est,fi*ones(size(t_est)))
hold off
Error
Error using *
Inner matrix dimensions must agree.
Error in threeDFT (line 39)
c(j)=x*Hc';

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Waveform Generation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by