How do I fix this error?
1 次查看(过去 30 天)
显示 更早的评论
deltat=0.1;
nsamples=2^10;
fs=1/deltat;
time=[0 : deltat : deltat*(nsamples-1)];
psdtot(1:nsamples/2+1) = zeros(1,nsamples/2+1);
nblock = 10;
for k=1:nblock
for i=1: nsamples
ydata(i,:) =5+10*cos(2*pi*time+pi/6)+15* randn(1);
end
[pxx,f] = periodogram(ydata,rectwin(nsamples),nsamples,fs);
size(psdtot)
size(pxx)
psdtot = psdtot + pxx/nblock;
end
figure(1);
plot(time,ydata);
I'm trying to generate Gaussian noise from x(t)=5+10*cos(2*pi*t+pi/6)+G(sigma,t)
G(sigma,t) is Gaussian noise with a standard deviation of 15 (sigma G=15), detat=0.1(s), and nsample=2^10.
It is the start of calculating Power Spectral Density with FFT.
The overall variance of the signal is (sigma g)^2+(A)^2/2 as expected.
The generated random signal should be sinusoidal because X(t) has the cosine factor.
采纳的回答
cui,xingxing
2024-4-5
编辑:cui,xingxing
2024-4-27
You should make sure that the array dimensions in the arithmetic are consistent, for example I changed your psdtot variable to a column vector. As far as I remember, matlab supports automatic dimension expansion since R2016a/b.
deltat=0.1;
nsamples=2^10;
fs=1/deltat;
time=[0 : deltat : deltat*(nsamples-1)];
psdtot(1:nsamples/2+1) = zeros(1,nsamples/2+1);
psdtot = psdtot(:); % here
nblock = 10;
for k=1:nblock
for i=1: nsamples
ydata(i,:) =5+10*cos(2*pi*time+pi/6)+15* randn(1);
end
[pxx,f] = periodogram(ydata,rectwin(nsamples),nsamples,fs);
psdtot = psdtot + pxx/nblock;
end
figure(1);
plot(time,ydata);
-------------------------Off-topic interlude, 2024-------------------------------
I am currently looking for a job in the field of CV algorithm development, based in Shenzhen, Guangdong, China. I would be very grateful if anyone is willing to offer me a job or make a recommendation. My preliminary resume can be found at: https://cuixing158.github.io/about/ . Thank you!
Email: cuixingxing150@gmail.com
1 个评论
更多回答(1 个)
Jose Sevilla
2024-8-25
Hola todos necesito ayuda con este gramento de codigo en Matlab 2024RA
% Inicialización de variables
distances = distance_start:distance_increment:distance_end;
received_power_5 = zeros(1, num_measurements); % 5to piso
received_power_4 = zeros(1, num_measurements); % 4to piso
received_power_3 = zeros(1, num_measurements); % 3er piso
std_dev_5 = zeros(1, num_measurements); % Desviación estándar 5to piso
std_dev_4 = zeros(1, num_measurements); % Desviación estándar 4to piso
std_dev_3 = zeros(1, num_measurements); % Desviación estándar 3er piso
rmse = zeros(1, num_measurements); % Error medio cuadrático
k_factor = zeros(1, num_measurements); % Factor K
1 个评论
Walter Roberson
2024-8-25
That code has the potential to work provided that
num_measurements = length(distances);
But if num_measurements is different than distances, then it seems most likely that you need more like
% Inicialización de variables
distances = (distance_start:distance_increment:distance_end).';
num_distances = length(distances);
received_power_5 = zeros(num_distances, num_measurements); % 5to piso
received_power_4 = zeros(num_distances, num_measurements); % 4to piso
received_power_3 = zeros(num_distances, num_measurements); % 3er piso
std_dev_5 = zeros(num_distances, num_measurements); % Desviación estándar 5to piso
std_dev_4 = zeros(num_distances, num_measurements); % Desviación estándar 4to piso
std_dev_3 = zeros(num_distances, num_measurements); % Desviación estándar 3er piso
rmse = zeros(num_distances, num_measurements); % Error medio cuadrático
k_factor = zeros(num_distances, num_measurements); % Factor K
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!