0

我有一个信号,它是两个频率的线性组合,我正在尝试使用 MATLAB 来确定(主)信号的频率。作为输入,我有采样率rate和带有信号数据的行向量segment

现在我有以下代码:

N=length(segment);

freq = rate*(0:N/2)/N;
X = fft(segment);
X=X(1:N/2+1);

plot(freq*2, abs(X))

这确实返回了一个具有两个峰值的图形,一个在信号所包含的每个频率上。现在我想提取这些频率。所以我想返回一个变量 ,signal它是两个频率的向量。

因此,如果我的信号是由30 Hz和 之一的信号的线性组合创建的60 Hz,那么我想要signal = [30,60]。我可以创建一个图表,然后识别它,但我想去掉那个中间人,只返回找到的频率,而不使用任何工具箱。

如何找到我想要的频率?

4

3 回答 3

2

Without toolboxes: select some threshold you deem acceptable, then simply do abs(x)>threshold, which will give you a logical array to index into freq, giving the frequencies above the threshold. For increased accuracy you can then do things like diff() on the resulting array, and find neighbouring indices, then select the maximum value on those consecutive indices on that sequence as the "peak" there.

Alternatively you can sort() the values, retain the indices of the maximum n (in your case 2) values and index that into the frequency arrays. Again not a very robust method, but quick and dirty.

Combining the two above techniques you could iteratively lower the threshold as per the sorted array, then check for things as proximity of peaks, their prominence etc.

If you don't want to implement this all yourself, see below for a one-stop function to do this.


If you are willing to use the signal processing toolbox you can use findpeaks(). This gives you indices, which you can then use to index your frequency array to get the desired frequencies. Alternatively use the peaks = findpeaks(data,x) syntax to directly extract the x location (frequencies in your case).

于 2019-11-08T13:16:43.743 回答
0

我最终做的是使用该max()功能。这将返回峰值,然后相应的 x-index 将与正确的频率相对应。检索到这个频率后,我选择了峰值周围的某个括号并将这些索引设置为零。然后我会再次运行max()以找到第二个峰值及其相应的频率。

于 2019-11-11T19:41:48.823 回答
0

2个简单的方法:

  1. 取返回的 fft 数组,并用每个峰值(一次 1 个)替换部分并用零替换(这样你最终只有 1 个峰值。然后在数组上执行逆 fft 以检索没有归零的信号频率。

  2. 如果您知道原始信号的相位 - 一次取一个并创建一个具有该频率的新信号并将其反转(即 0 信号 - 它上升的地方现在下降了!)。并将它添加到原始信号中。该频率将从音频信号中消失,需要 fft(验证您的结果除外。

于 2019-11-11T17:47:07.513 回答