Median power using find function

1 回表示 (過去 30 日間)
Claudia Vondra
Claudia Vondra 2021 年 10 月 23 日
回答済み: Chris 2021 年 10 月 24 日
Hi, I need to break 60000 data points into 60-1000 array intervals and covert to the frequency domain. From there I need to find the median power frequency for each interval but I keep getting array size errors for each change. Below is the code. Any help would be great!
[signal]=RMS(p31(:,2),20);
fixsignal=signal(6153:66153);
t=1:60;
for k=1:60
for i=1:length(fixsignal(:,1))
A=fft(fixsignal(i:i+999)); % Do FFT on the signal data.
for j=1:length(A)
A(1)=[];
n=round(length(A/2));
power=abs(A(1:n)).^2;
nyquist=1/2;
freq=(1:n)/(n)*nyquist*1000;
integ=cumtrapz(power);
ninteg=integ/max(integ);
power_med(1,k)=find(ninteg(1,j:)>=0.5,1); %Error statement is always on this line
end
end
%power_med(:,k)=median(split(:,k));
end

回答 (1 件)

Chris
Chris 2021 年 10 月 24 日
From that line,
ninteg(1,j:)
is invalid syntax. If you want element j through the end of the vector, you need
ninteg(1,j:end)
Also, if everything in your code consists of vectors (as opposed to two-dimensional arrays), you don't necessarily need that "1" in your indexing.
ninteg(j:end)
would be sufficient. Similarly, if fixsignal is a column vector,
fixsignal
is equivalent to
fixsignal(:,1)
and
fixsignal(:)
All variations select all elements of the first column of fixsignal, or in other words the entire signal.
If you pay attention to the size of the variables in Matlab's Workspace panel, it might help you understand future array size error messages (though probably not in this case, if I have correctly pointed out the problem)

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by