在matlab程序中绘制图形时出错

matlab matlab-figure

850 观看

1回复

37 作者的声誉

这是我的matlab源代码

% let 'y' is a workspace file containg sampled data from DSO.
fs=2500;   %sampling freq
T=1/fs;     % sample time
L=2500;    % length of the signal
t=(0:L-1)*T;  %time vector
NFFT=2^nextpow2(L);   %next power of 2 from length of y. 
                      %p = nextpow2(y) returns the smallest power of two that is greater than or equal to the absolute value of L. 
                      %(That is, p that satisfies 2^p >= abs(L)). 
                      %This function is useful for optimizing FFT operations, which are most efficient when sequence length is an exact power of two. 
                      %If A is non-scalar, nextpow2 returns the smallest power of two greater than or equal to length(L).
Y=fft(y,NFFT)/L;
f=fs/2*linspace(0,1,NFFT/2);
% to plot signal-sided amplitude spectrum.
plot(f,2*abs(Y(1:NFFT/2)))
title('Single-sided amplitude spectrum of y(t)');
xlabel('Frequency (Hz');
ylabel('|Y(f)');
grid;
bar(f,2*abs(Y(1:NFFT/2)),'BarWidth',1)

我正在从数字示波器获取采样数据,我希望以条形图形式获得FFT。

在绘制图形之后,不同的标签和标题和网格也没有出现。

作者: user991852 的来源 发布者: 2012 年 3 月 12 日

回应 (1)


2

4456 作者的声誉

问题是你正在绘制你的初始情节。

% to plot signal-sided amplitude spectrum.
plot(f,2*abs(Y(1:NFFT/2))) % create a plot
title('Single-sided amplitude spectrum of y(t)'); % annotate it nicely
xlabel('Frequency (Hz');
ylabel('|Y(f)');
grid;
% throw away all that nice data and plot and plot over it with this:
bar(f,2*abs(Y(1:NFFT/2)),'BarWidth',1)

试试这个:

figure;
% to plot signal-sided amplitude spectrum.
plot(f,2*abs(Y(1:NFFT/2)))
title('Single-sided amplitude spectrum of y(t)');
xlabel('Frequency (Hz');
ylabel('|Y(f)');
grid;
figure;
bar(f,2*abs(Y(1:NFFT/2)),'BarWidth',1)
作者: macduff 发布者: 12.03.2012 02:24
32x32