gabor with no error can I plot( fr estimated with fi input )at t=1

1 visualización (últimos 30 días)
common fernando
common fernando el 5 de Dic. de 2020
Editada: Walter Roberson el 5 de Abr. de 2021
clear all; close all; clc
Fs=200; %sampling freq.
dt =1/Fs;
N=Fs/50 %number of samples/cycle
m=3; %no. of cycles
t =dt*(0:200); %dt*(0:m*N); %data window
fi = 50
ww=wgn(201,1,-40);
size(transpose(ww))
y=sin(2*pi*fi*t + 0.3);
x=sin(2*pi*fi*t + 0.3)+transpose(ww);
tmax=1
for j=0:200/(N*m)
t =dt*(j*m*N:(j+1)*m*N);
x=sin(2*pi*fi*t + 0.3)+transpose(wgn(1+N*m,1,-40));
%figure()
%plot(x)
n=0:1:m*N; %n=(j*m*N):1:(j+1)*m*N;
bb=0.42 - 0.5*cos(2*pi*n/(m*N+1)) + 0.08*cos(2*pi*n/(m*N+1)); %Blackman Window figure()
%figure()
%plot(bb)
u=times(x,bb);
%figure()
%plot(u)
for h=4500:5100 %4900:5100
fx(h)=0;
for k =1:1+(m*N) % since u(>(1+(m*N))=0!!!!
fx(h)=fx(h)+u(k)*exp(-2*pi*1j*h*k/(Fs*100));
end
end
ff=abs(fx);
[maxVal maxInd] = max(ff);
i=4500:5100; %4900:5100;
%figure()
%plot(i, ff(4900:5100),'red')
fr(j+1)=maxInd;
end
fr
figure(2)
plot((fr/100),'red')
hold on
RMSE = sqrt(mean(((fr/100)-fi).^2))
xlabel('time')
ylabel('frequency')
title('GABOR white noise')
plot (t,fi)
hold off

Respuestas (1)

Walter Roberson
Walter Roberson el 5 de Abr. de 2021
Editada: Walter Roberson el 5 de Abr. de 2021
clear all; close all; clc
Fs=200; %sampling freq.
dt =1/Fs;
N=Fs/50 %number of samples/cycle
N = 4
m=3; %no. of cycles
t =dt*(0:200); %dt*(0:m*N); %data window
You assign a vector of length 201 to t at this point
fi = 50
fi = 50
ww=wgn(201,1,-40);
size(transpose(ww))
ans = 1×2
1 201
y=sin(2*pi*fi*t + 0.3);
x=sin(2*pi*fi*t + 0.3)+transpose(ww);
tmax=1
tmax = 1
200/(N*m)
ans = 16.6667
for j=0:200/(N*m)
17 different j iterations
t =dt*(j*m*N:(j+1)*m*N);
You overwrite t with a vector of length m*N+1 = 13
x=sin(2*pi*fi*t + 0.3)+transpose(wgn(1+N*m,1,-40));
%figure()
%plot(x)
n=0:1:m*N; %n=(j*m*N):1:(j+1)*m*N;
bb=0.42 - 0.5*cos(2*pi*n/(m*N+1)) + 0.08*cos(2*pi*n/(m*N+1)); %Blackman Window figure()
%figure()
%plot(bb)
u=times(x,bb);
%figure()
%plot(u)
for h=4500:5100 %4900:5100
fx(h)=0;
for k =1:1+(m*N) % since u(>(1+(m*N))=0!!!!
fx(h)=fx(h)+u(k)*exp(-2*pi*1j*h*k/(Fs*100));
end
end
ff=abs(fx);
[maxVal maxInd] = max(ff);
i=4500:5100; %4900:5100;
%figure()
%plot(i, ff(4900:5100),'red')
fr(j+1)=maxInd;
end
So 17 different fr values
figure(2)
size(t), size(fr)
ans = 1×2
1 13
ans = 1×2
1 17
plot((fr/100),'red')
13 locations plotted, using their index as the t value
hold on
RMSE = sqrt(mean(((fr/100)-fi).^2))
RMSE = 0.0448
xlabel('time')
ylabel('frequency')
title('GABOR white noise')
plot (t,fi, 'b*')
size(t), size(fi)
ans = 1×2
1 13
ans = 1×2
1 1
You are after the for loop. t has the same value it was last assigned:
t
t = 1×13
0.9600 0.9650 0.9700 0.9750 0.9800 0.9850 0.9900 0.9950 1.0000 1.0050 1.0100 1.0150 1.0200
Barely 1.
And fi was only ever assigned a scalar, so you are drawing with multiple different t values and a single fi value. You will get a series of dots as the result... down around time 1.
hold off
What can you do? Well, you could record the first t (or middle if you want) associated with each j iteration, so that when you
plot((fr/100),'red')
you could put in the time vector, so that at least the constant fi values would be plotted on the same time scale as the fr values.
Or maybe instead of the
plot (t,fi, 'b*')
you should instead
yline(fi)
if your purpose is to plot a reference line. Though keep in mind that your plot of fr is not plotting against absolute time...

Categorías

Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by