theta = -90:0.01:90;
for i=1:length(theta)
SS = zeros(Nr,1);
SS = exp(-1j*2*pi*d*(0:Nr-1)'*sind(theta(i))/lambda);
PP = SS'*(Vn*Vn')*SS;
Pmusic(i) = 1/ PP;
end
Pmusic = real(10*log10(Pmusic)); %Spatial Spectrum function
[pks,locs] = findpeaks(Pmusic,theta,'SortStr','descend','Annotate','extents');
MUSIC_Estim = sort(locs(1:K))
我想在八度运行音乐matlab代码(因为我没有matlab)
在matlab免费30天版,它确实工作得很好,但不是在八度.
错误:findpeaks:参数名称或开关为非字符串
如何解决这个错误?我下载了信号库并进行了更改,但它不工作。
在Octave中,提供的matlab示例运行良好。为什么不能在代码之上工作?
t = 2*pi*linspace(0,1,1024)';
y = sin(3.14*t) + 0.5*cos(6.09*t) + 0.1*sin(10.11*t+1/6) + 0.1*sin(15.3*t+1/3);
data = abs(y + 0.1*randn(length(y),1)); # Positive values + noise
[pks idx] = findpeaks(data,"MinPeakHeight",1);
dt = t(2)-t(1);
[pks2 idx2] = findpeaks(data,"MinPeakHeight",1,...
"MinPeakDistance",round(0.5/dt));
subplot(1,2,1)
plot(t,data,t(idx),data(idx),'or')
subplot(1,2,2)
plot(t,data,t(idx2),data(idx2),'or')
plot(t,data,t(idx2),data(idx2),'or')
请帮帮忙。谢谢。
我尽力了
pkg install“https://github.com/gnu-octave/pkg-control/releases/download/control-3.5.2/control-3.5.2.tar.gz“pkg install“https://downloads.sourceforge.net/project/octave/Octave%20Forge%20Packages/Individual%20Package%20Releases/signal-1.4.3.tar.gz“pkg load control pkg load signal
在Octave命令窗口,但它没有工作。
这个MUSIC算法的matlab代码不是我写的,只是一个简短的计算器代码,我会上传整个代码而不是写更小版本的代码,以便准确地看到MUSIC_Estim的值。
DOA = [35 30]; %Direction of arrival (Degree)
T = 200; %Snapshots (or Samples)
K = length(DOA); %The number of signal source(or traget)
Nr = 9; %Number of receiver's antennas
lambda = 1; %Wavelength
d = lambda/2; %Receiver's antennas spacing
SNR = 10; %Signal to Noise Ratio (dB)
A = zeros(Nr,K); %Steering Matrix
for k=1:K
A(:,k) = exp(-1j*2*pi*d*sind(DOA(k))*(0:Nr-1)'/lambda);
%Assignment matrix
end
Vj = diag(sqrt((10.^(SNR/10))/2));
s = Vj* ( randn(K,T) + 1j*randn(K,T) );
noise = sqrt(1/2)*(randn(Nr,T)+1j*randn(Nr,T));
X = A*s;
X = X+noise; %Insert Additive White Gaussain Noise (AWGN)
% MUSIC (MUltiple SIgnal Classification)
Rx = cov(X'); %Data covarivance matrix
[eigenVec,eigenVal] = eig(Rx); %Find the eigenvalues and eigenvectors of Rx
Vn = eigenVec(:,1:Nr-K); %Estimate noise subspace (Note that eigenvalues sorted ascendig on columns of "eigenVal")
theta = -90:0.01:90; %Grid points of Peak Search
for i=1:length(theta)
SS = zeros(Nr,1);
SS = exp(-1j*2*pi*d*(0:Nr-1)'*sind(theta(i))/lambda);
PP = SS'*(Vn*Vn')*SS;
Pmusic(i) = 1/ PP;
end
Pmusic = real(10*log10(Pmusic)); %Spatial Spectrum function
[pks locs] = findpeaks(Pmusic, "DoubleSided");
locs = theta(locs);
MUSIC_Estim = sort(locs)
figure;
plot(theta,Pmusic,'-b',locs(1:K),pks(1:K),'r*'); hold on
text(locs(1:K)+2*sign(locs(1:K)),pks(1:K),num2str(locs(1:K)'))
xlabel('Angle \theta (degree)'); ylabel('Spatial Power Spectrum P(\theta) (dB)')
title('DOA estimation based on MUSIC algorithm ')
xlim([min(theta) max(theta)])
grid on
/// locs = theta(locs); MUSIC_Estim = sort(locs)
值不是峰值。所以我试过了
Pmusic = real(10*log10(Pmusic)); %Spatial Spectrum function
[pks,locs] = findpeaks(Pmusic, "DoubleSided","MinPeakHeight", 5);
[sorted_pks, sorted_idx] = sort(pks(1:K)); % Sort peaks in descending order
MUSIC_Estim = theta(locs(sorted_idx(1:K))) % Select top K peak locations from sorted peaks
figure;
plot(theta,Pmusic,'-b',MUSIC_Estim,pks(1:K),'r*'); hold on
text(MUSIC_Estim(1:K)+2*sign(sorted_idx(1:K)),pks(1:K),num2str(MUSIC_Estim(1:K)'))
但是它有另一个排序峰值的问题,并且不能得到超过2个DOA。
1条答案
按热度按时间bsxbgnwa1#
基本上Octave findpeaks支持数据的单个参数:
[pks, loc] = findpeaks(data)
返回pks
中的峰值,以及loc
中的索引。Matlab findpeaks有一个可选的额外输入参数,包含数据样本
[pks, loc] = findpeaks(data,x)
的横坐标。在输出中,loc
包含峰的横坐标,而不是索引。但这不是唯一的区别。Octave版本没有
"SortStr"
属性。但你不需要它,因为你是排序后,无论如何。它没有"Annotate"
属性,但您也不需要它(来自Matlab文档:“如果使用输出参数调用findpeaks,则忽略此参数。”)最后,在第一个示例中,您必须用以下两行替换
findpeaks
调用:请注意,您可以通过阅读文档获得所有这些内容。