如何在MATLAB中绘制ASCII值的fft? [英] How to Plot fft of ascii values in MATLAB?

查看:123
本文介绍了如何在MATLAB中绘制ASCII值的fft?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含2048个x和y值对的ascii文件.我只是想知道如何在MATLAB中绘制y的fft.我正在编写以下MATLAB代码,但无法找到合适的结果.

I have a ascii file containing 2048 x and y value pairs. I just want to know how to plot fft of y in MATLAB. I am writing following MATLAB code but could not be able to find appropriate result.

我该怎么做?这是我尝试过的:

How can I do this? This is what I have tried:

I = load('data1.asc');

for i = 1:2048
    y = I(:,2);
end

plot(x)

Fs = 40000;                    
T = 1/Fs;                   
L = 2000;     
NFFT = 2^nextpow2(L);
Y = abs(fft(y,NFFT))/L;
f = Fs/2*linspace(0,1,NFFT/2+1);

figure, plot(f,2*abs(Y(1:NFFT/2+1))) 
axis([0 40000 0 40])
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')

推荐答案

与其直接进入MATLAB的FFT例程,不如考虑使用周期图函数负责此操作的所有详细信息为您服务,即应用窗口函数,计算FFT,从FFT输出推导幅度,适当地缩放轴,甚至在需要时进行绘图.

Instead of diving straight into MATLAB's FFT routine you should instead consider using the periodogram function. When people say "FFT" they usual mean PSD or periodogram, i.e. a plot of power spectral density using a suitably windowed and FFTed sample. The periodogram function in MATLAB takes care of all the details of this for you, i.e. applying a window function, calculating the FFT, deriving magnitude from FFT output, appropriate scaling of axes, and even plotting if required.

注意:periodogram在MATLAB Signal Processing Toolbox中-如果您无权访问,则可以考虑使用八度(免费的MATLAB克隆),其中有一个periodogram克隆,否则您需要自己将各种构建基块放在一起:

Note: periodogram is in the MATLAB Signal Processing Toolbox - if you do not have access to this then you can either consider using Octave (free MATLAB clone) which has a periodogram clone, otherwise you would need to put the various building blocks together yourself:

  • 窗口功能
  • FFT
  • 计算幅度
  • 恐吓频率和幅度值的缩放
  • 绘制PSD

这篇关于如何在MATLAB中绘制ASCII值的fft?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆