error in my code

2 views (last 30 days)
common fernando
common fernando on 3 Dec 2020
Commented: common fernando on 3 Dec 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('DE white noise')
plot (t,fi)
plot (t,fi)
hold off
  2 Comments
Stephan
Stephan on 3 Dec 2020
Is this the same question again? Or is it new stuff?
common fernando
common fernando on 3 Dec 2020
New about the three level discrete transform
but i forget to edit the line code :
title('DE white noise')
it should be
title('3LDFT white noise')

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!