Effacer les filtres
Effacer les filtres

How do I fix this error?

2 vues (au cours des 30 derniers jours)
Byungho
Byungho le 4 Avr 2024
Modifié(e) : cui,xingxing le 27 Avr 2024
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
ans = 1x2
1 513
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ans = 1x2
513 1024
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Arrays have incompatible sizes for this operation.
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.
  1 commentaire
Torsten
Torsten le 4 Avr 2024
You cannot add arrays of size 1x513 and 513x1024 (see above).

Connectez-vous pour commenter.

Réponse acceptée

cui,xingxing
cui,xingxing le 5 Avr 2024
Modifié(e) : cui,xingxing le 27 Avr 2024
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 commentaire
Derek
Derek le 9 Avr 2024
Modifié(e) : Derek le 9 Avr 2024
So using this data provided how do you plot the psd vs frequency? In a log log plot. Do you have to do the fgts prior to the peridogram

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by