【问题标题】:FFT in MATLAB or Java [duplicate]MATLAB或Java中的FFT [重复]
【发布时间】:2017-05-02 08:33:58
【问题描述】:

我在 MATLAB 中有用于信号(音频信号)代码的 FFT,但它显示(绘制)图形。但是我只想将频率分量存储在一个变量中,但我不知道如何。 如果代码不适用,任何人都可以给我在 Matlab 或 Java 中工作的代码吗?

注意:我不是信号处理或 MATLAB 方面的专家。


   %% Basic Fourier Analysis
   % This example uses the Fourier transform to identify component
   % frequencies in a simple signal. 

   %%
   % Create a time vector |t| and a sinusoidal signal |x| that is a        function of |t|.
   t = 0:1/50:10-1/50;                     
   x = sin(2*pi*15*t) + sin(2*pi*20*t);

   %%
   % Plot the signal as a function of time.
   plot(t,x)

   %%
   % Compute the Fourier transform of the signal, and then compute the   magnitude
   % |m| and phase |p| of the signal.  
   y = fft(x);         
   m = abs(y);                               
   p = angle(y);                     

   %%
   % Compute the frequency vector associated with the signal |y|, which is
   % sampled in frequency space.
   f = (0:length(y)-1)*50/length(y);



   %% 
   % Plot the magnitude and phase of the signal as a function of frequency.
   % The spikes in magnitude correspond to the signal's frequency
   % components.
   subplot(2,1,1)
   plot(f,m)
   title('Magnitude')

   subplot(2,1,2)
   plot(f,rad2deg(p))
   title('Phase')

   %%
   % Compute and plot the inverse transform of $y$, which reproduces the
   % original data in $x$ up to round-off error.
   figure
   x2 = ifft(y);
   plot(t,x2)

【问题讨论】:

  • 请展示您的尝试。据我了解,这段代码不是你写的。
  • 是的,我在 matlab 网站上找到了它
  • 我尝试像这样存储它 h=fft(t,x2) 然后 x_h=h.x y_h=h.y

标签: java matlab signals signal-processing fft


【解决方案1】:

在您问题的 MATLAB 代码中,向量 m 包含每个 FFT 输出箱的幅度。每个 bin 对应一个频率,因此该向量为您提供每个 bin 频率的幅度。如果您正在寻找频谱中最大峰值的频率,那么只需在m 中找到最大值,然后将此峰值的 bin 索引转换为频率。 bin索引与频率的关系由下式给出:

f = i * Fs / N

其中i在感兴趣的bin的索引中,Fs是采样率,N是FFT大小,f是对应的bin中心频率。更详细的解释见this question。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-28
    相关资源
    最近更新 更多