2013-07-08 66 views
0

我已經繪製出來的圖表和我有一些是在這裏繪製圖形的MATLAB峯值(中發現的峯值,但想知道的價值)

fs = 100; %freq 100hz 
N = length(pbcg); %data length, before that do a pbcg=load('pbcg.txt') 
duration_in_seconds = N/fs; 
duration_in_minutes = duration_in_seconds/60; 
BPM_avg = beat_count/duration_in_minutes; 

fid = fopen('y1.txt','a'); %txt naming and append 

%count the dominant peaks in the signal 
for k = 2 : length(pbcg)-1 
    if (pbcg(k) > pbcg(k-1) && pbcg(k) > pbcg(k+1) && pbcg(k) > 1) 
     beat_count = beat_count + 1; 
    end 
    fprintf(fid, 'x_axis%i\t ', k); %open writer 
    fprintf(fid, 'BPM%i\n ', BPM_avg); %open writer 
end 
disp(BPM_avg); %display the BPM 
fclose(fid); %close writer 

圖像是這裏的代碼(唐」沒有聲望插入img)... https://skydrive.live.com/embed?cid=0525DA685954952E&resid=525DA685954952E%21407&authkey=ALmvTzzQ7Xer2Do

我想知道的是,你可以看到,有11峯值最高,我怎麼得到'價值'峯值本身?因爲在我想知道如何得到Y軸值或計算值。

+2

在if語句中,您已經擁有了所有需要的東西。在'if'裏面你可以添加'峯值(beat_count)= pbcg(k);',並且你會在峯值中得到峯值的Y值。 – Adiel

+0

沒有理由感到抱歉。你的情況很好。我的意思是你應該在'beat_count = Beat_count + 1'這行後面加上另一行,並且在'end'之前。 – Adiel

+0

@Adiel非常感謝!我知道你的意思,我設法得到高峯..謝謝! – myfriday13

回答

0

我做這種方式就像@Adiel如何教..

%determine the bpm 

beat_count = 0; 
fs = 100; %freq 100hz 
N = length(pbcg); %data length, before that do a pbcg=load('pbcg.txt') 
duration_in_seconds = N/fs; 
duration_in_minutes = duration_in_seconds/60; 
BPM_avg = beat_count/duration_in_minutes; 

fid = fopen('y1.txt','a'); %txt naming and append 

%count the dominant peaks in the signal 
for k = 2 : length(pbcg)-1 
    if (pbcg(k) > pbcg(k-1) && pbcg(k) > pbcg(k+1) && pbcg(k) > 1) 
    beat_count = beat_count + 1; 
    peaks(beat_count)=pbcg(k); 
end 
fprintf(fid, 'x_axis%i\t ', k); %open writer 
fprintf(fid, 'BPM%i\n ', BPM_avg); %open writer 
end 

disp(BPM_avg); %display the BPM 
fclose(fid); %close writer 

,並從MATLAB命令我輸入「峯」,它顯示我與y軸分值峯的總數。但是因爲我需要清除「beat_count」和「峯值」,因爲每次我'運行'該函數都會使數據量翻倍

+0

很高興你能解決它! – Floris

+0

謝謝@弗洛里斯.. – myfriday13

+0

嗨@弗洛里斯你知道嗎? http://stackoverflow.com/questions/17561419/matlab-plot-graphsegment-by-segment-and-user-input-threshold-value-before-writ – myfriday13