簡體   English   中英

MATLAB中方波的頻譜

[英]Frequency spectrum of a square wave in MATLAB

我需要使用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,但是我真的不知道如何繪制圖形。

直接從fft文檔改編而成,但使用方波作為信號:

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)|')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM