【问题标题】:Frequency spectrum of a square wave in MATLABMATLAB中方波的频谱
【发布时间】:2013-12-04 01:02:36
【问题描述】:

我需要使用 MATLAB 绘制方波的频谱。波在 0 和 -2 之间为 HIGH (5mV),在 0 和 2 之间为 LOW (omv)。我已经获得了傅里叶序列 对于这个函数,我有该系列的前十个组件。

(5/2) + ((10/pi)*sin((pi*t)/2)) + ((10/(3*pi))*sin((3*pi*t)/2 )) + ((10/(5*pi))*sin((5*pi*t)/2)) + ((10/(7*pi))*sin((7*pi*t)/2 ))+ ((10/(9*pi))*sin((9*pi*t)/2))+ ((10/(11*pi))*sin((11*pi*t)/2 ))+ ((10/(13*pi))*sin((13*pi*t)/2))+ ((10/(15*pi))*sin((15*pi*t)/2 ))+ ((10/(17*pi))*sin((17*pi*t)/2))+ ((10/(19*pi))*sin((19*pi*t)/2 ))

如何使用 MATLAB 绘制此波的频谱?我曾尝试使用 FFT,但我真的不知道它是如何绘制图形的。

【问题讨论】:

  • 请分享您的方波方法和方波频率。
  • 方波的周期是4ms,但频谱不取决于傅里叶级数中各个分量的频率吗?

标签: matlab fft frequency


【解决方案1】:

这是直接改编自fft docs,但使用方波作为信号:

Fs = 1000;                    %// Sampling frequency
freq = 50;
T = 1/Fs;                     %// Sample time
L = 1000;                     %// Length of signal
t = (0:L-1)*T;                %// Time vector
A = 10;                       %// Amplitude

y = A*(sin(2*pi*freq*t) > 0); %// Make a square wave


plot(Fs*t,y);
xlabel('time (milliseconds)')

NFFT = 2^nextpow2(L);         %// Next power of 2 from length of y
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);

%// Plot single-sided amplitude spectrum.
plot(f,2*abs(Y(1:NFFT/2+1))) 
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)') %// probably would be more meaningful if you convert this to radians per second, check out the xtickmark and xtickmarklabel properties of plot
ylabel('|Y(f)|')

【讨论】:

  • 我尝试了一些变化来适应我的方波,但图表并不完全是它应该的样子。我根据需要得到 11 个峰值,但我不应该在频率为 0(来自傅立叶级数)处得到一个(5/2)峰值吗?我的峰值在 5 点多一点。code Fs = 1000; T = 1/Fs; L = 长度(一); t2 = (0:L-1)*T; NFFT = 2^nextpow2(L); Y = fft(a,NFFT)/L; f = Fs/2*linspace(0,1,NFFT/2+1); plot(f,2*abs(Y(1:NFFT/2+1))) axis([0, 5 0, 5]) code 其中a是我在原始问题中发布的波形
  • 我不明白...你必须在创建a之前创建t,并且你需要在t之前创建L。您不能使用不同的 t 来计算 a 与用于 fft 图的 a...
  • @user2802349 嗯...我不确定为什么 fft 图中有一个2*,但这可以解释为什么你会得到两倍的 0Hz 信号幅度。如果我是你,我会调查的
猜你喜欢
  • 1970-01-01
  • 2017-09-08
  • 1970-01-01
  • 1970-01-01
  • 2015-06-12
  • 1970-01-01
  • 1970-01-01
  • 2019-11-09
  • 2017-09-03
相关资源
最近更新 更多