0

我正在尝试分析音频文件,因此我生成了信号的 FFT,并发现了高于某个阈值的峰值。这是代码的一部分:

%---------------------------Performing FFT--------------------------------%
 for i = 2:No_of_peaks

    song_seg = song(max_col(i-1):max_col(i)-1);
%     song_seg = song(max_col(6):max_col(7)-1);
    L = length(song_seg);    
    NFFT = 2^nextpow2(L); % Next power of 2 from length of y

    seg_fft = fft(song_seg,NFFT);%/L;

    N=5;Fst1=50;Fp1=60; Fp2=1040; Fst2=1050;

%     d = fdesign.bandpass('N,Fst1,Fp1,Fp2,Fst2');
%     h = design(d);
%     seg_fft = filter(h, seg_fft);

%     seg_fft(1) = 0;
%     
    f = FS/2*linspace(0,1,NFFT/2+1);
    seg_fft2 = 2*abs(seg_fft(1:NFFT/2+1));
    L5 = length(song_seg);

    figure(1+i)
    plot(f,seg_fft2)
    title('Frequency spectrum of signal')
    xlabel('Frequency (Hz)')
    %xlim([0 2500])
    ylabel('|Y(f)|')
    ylim([0 300])

    [points, loc] = findpeaks(seg_fft2,'MINPEAKHEIGHT',20)
 end

现在我有了points并且loc我希望能够提取 60Hz 和 1000Hz 之间的峰值。我如何编写代码来实现它并存储峰值幅度以及相应的频率值???

提前感谢

4

2 回答 2

2

您可以使用:

峰值查找器

另一种更简单的方法是对函数进行一阶导数(使用离散频率的 diff 向量),然后定位峰值。幅度可以从您的原始信号中获取。

于 2013-09-20T13:20:23.493 回答
2

两种类似的方式来解决这个问题。首先,在 FFT 之后,选择包含感兴趣区域的光谱子集,并将峰值搜索程序应用于该部分:

 for i = 2:No_of_peaks

    % ... code steps where you fft etc here ...
    % ... now pick the region of interest

    fmin = 60;
    fmax = 1000;
    region_of_interest = fmax>f & f>fmin;
    froi = f(region_of_interest);  

    [points, loc] = findpeaks(seg_fft2(region_of_interest),'MINPEAKHEIGHT',20)

    % index into froi to find the frequency of the peaks
    fpeaks = froi(loc);

 end

一个非常相似的替代方法是选择峰值,然后在感兴趣的频率区域内选择子集,如下所示:

 for i = 2:No_of_peaks

    % lots of code here to fft etc ...

    [points, loc] = findpeaks(seg_fft2,'MINPEAKHEIGHT',20)

    % find the peaks within the region of interest 

    fmin = 60;
    fmax = 1000;
    peaks_of_interest = find(fmax>f(loc) & f(loc)>fmin);
    fpeaks = f(loc(peaks_of_interest));
    apeaks = points(loc(peaks_of_interest));  % magnitude of the peaks


 end
于 2013-09-20T18:45:36.403 回答