Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 从绘图中的峰值查找[x,y]-坐标_Matlab - Fatal编程技术网

Matlab 从绘图中的峰值查找[x,y]-坐标

Matlab 从绘图中的峰值查找[x,y]-坐标,matlab,Matlab,我一直在寻找解决方案,但没有找到任何令人满意的答案,因为我找到的每一种方法都是针对一个特定的问题 描述我的情况: 通过读取信号并对其应用fft,我在for循环中生成值,这些值在特定时间段中绘制。我用圆圈标记了50000以上的数值。现在,我试图找出在哪个时间,哪个幂,是标记值,超过50000。基本上我是想找到x-y坐标。我在找,但找不到任何有用的东西。也许我一直都看错了。最后,还有更多 这是我的代码和情节 clear; clc; %% MATLAB %% read file %__________

我一直在寻找解决方案,但没有找到任何令人满意的答案,因为我找到的每一种方法都是针对一个特定的问题

描述我的情况: 通过读取信号并对其应用fft,我在for循环中生成值,这些值在特定时间段中绘制。我用圆圈标记了50000以上的数值。现在,我试图找出在哪个时间,哪个幂,是标记值,超过50000。基本上我是想找到x-y坐标。我在找,但找不到任何有用的东西。也许我一直都看错了。最后,还有更多

这是我的代码和情节

clear;
clc;
%% MATLAB
%% read file
%_________________________________________
[y,fs]=audioread('Undertale - Megalovania.wav');
% audioread = read wav -file
% y = contains the audio signal
% fs = 44100
% 'UnchainMyHeart' = name of the wav-file
%_________________________________________
%% PARAMETER FOR STFT
%_________________________________________ 
t_seg=0.03; % length of segment in ms
fftlen = 4096; %FFT-Points

% Defining size of frequency bands
f_low= 1:200;    %lower frequencies
f_medium= 201:600;  %medium frequencies
f_high= 601:1000; %higher frequencies
%__________________________________________
%% CODE

segl =floor(t_seg*fs); 
windowshift=segl/2; 
% defining the size of the window shift
window=hann(segl); 
% apply hann function on segment length (30 ms)
window=window.'; 
% transpose vector
si=1; 
% defining start index
ei=segl; 
% defining end index

N=floor( length(y)/windowshift - 1);
% Calculates the number, how often the window has to shift
% until to length of the audio signal

f1=figure;
    % Generating new window

    f=0:1:fftlen-1;
    f=f/fftlen*fs;
    % defining frequency vector

    Ya=zeros(1,fftlen);

    ValuesOfYc = NaN(1,N);
    ValuesOfYd = NaN(1,N);
    ValuesOfYe = NaN(1,N);

    x =(1:N)*windowshift/fs;
    % defining x-axis

for m= 1:1:N 

    y_a = y(si:ei);
    % a segment is taken out from audio signal length(30ms) 
    y_a= y_a.*window;
    % multiplying segment with window (hanning) 
    Ya=fft(y_a, fftlen);
    % Applying fft on segment
    Yb=abs(Ya(1:end/2)).^2;  
    % Squaring the magnitudes from one-sided spectrum

        drawnow; % Updating the graphical values

    figure(f1);
    % Showing the power values

    %% frequency bands

    y_low = Yb(f_low);  % LOW frequency spectrum

    Yc=sum(y_low);
    % Summing all the power values from one frequency spectrum together
    % so you get one power value from one spectrum 
    ValuesOfYc(m) = Yc;
    %Output values are being saved here, which are generated from the for
    %loop
    % m = start variable from for loop

    [pks0, locs0] = findpeaks(ValuesOfYc);

    subplot(2,1,1)
    p=plot(x,ValuesOfYc,'r-',x(locs0(pks0>=50000)), pks0(pks0>=50000),'ob');  
    p(1).LineWidth =0.5;

    %plot(x,ValuesOfYc,'marker','s');
    %[ym,ix]=find(sign(diff(ValuesOfYc))==-500,50000,'first');
    %plot((x(ix) ValuesOfYc(ix), [1 ,0 ,0]);

    xlabel('time (Audio length)')
    ylabel('Power')
    grid on


    si=si+windowshift; 
    % Updating start index 
    ei=ei+windowshift; 
    % Updating end index


end

for o= 1:1:N

    y_a = y(si:ei);
    % a segment is taken out from audio signal length(30ms) 
    y_a= y_a.*window;
    % multiplying segment with window (hanning) 
    Ya=fft(y_a, fftlen);
    % Applying fft on segment
    Yb=abs(Ya(1:end/2)).^2;  
    % Squaring the magnitudes from one-sided spectrum

        drawnow; % Updating the graphical values

    figure(f1);
    % Showing the power values

    %% frequency bands

    y_medium = Yb(f_medium); % MEDIUM frequency spectrum
    y_high = Yb(f_high); % HIGH frequency spectrum

    Yd=sum(y_medium);
    Ye=sum(y_high);
    % Summing all the power values from one frequency spectrum together
    % so you get one power value from one spectrum 
    ValuesOfYd(o) = Yd;
    ValuesOfYe(o) = Ye;
    %Output values are being saved here, which are generated from the for
    %loop
    % m = start variable from for loop

    [pks1, locs1] = findpeaks(ValuesOfYd); 
    [pks2, locs2] = findpeaks(ValuesOfYe);

    subplot(2,1,2)
    p=plot(x, ValuesOfYd,'g-', x(locs1(pks1>=400)), pks1(pks1>=400),'ro',...
        x, ValuesOfYe,'b-', x(locs2(pks2>=165)), pks2(pks2>=165),'ro' );
    p(1).LineWidth =0.5;
    xlabel('time (Audio length)')
    ylabel('Power')
    grid on

    si=si+windowshift; 
    % Updating start index 
    ei=ei+windowshift; 
    % Updating end index
end  

我不是命令你给我写解决方案或类似的东西,而是要求你采取正确的步骤或建议。顺便说一句,我曾尝试使用这样的代码方法,并自己应用,但效果不太好。 这是我尝试使用的一个:

x = 0:30:360;
y = sin(x)+rand(size(x));
line(x,y,'marker','s');
[ym,ix]=find(sign(diff(y))==-1,1,'first');
line(x(ix),y(ix),'marker','s','markerfacecolor', [0.56 ,0.5 ,0.5]); 

可能相关:嗯,我查看了它,但它只显示了指定范围内的峰值,这与我的类似,但我需要标记峰值的坐标。但是谢谢你试着帮助meIs x(locs0(pks0>=50000)),pks0(pks0>=50000)不是你想要的吗?这些是用圆圈标记的点的x和y坐标。参见
idx=2(等)?一旦你有了索引向量
idx
,用它来找到坐标(意思是:
x(idx)
y(idx)
。如果你需要位置-
find(x)
)。@Dev iL抱歉回复太晚了。是的,我的错,我后来才发现,它确实是我想要的。我为我的无知感到抱歉,非常感谢你。