Effacer les filtres
Effacer les filtres

I'm trying to create plots of Fourier Synthesis and FFT Spectrum of a square wave using harmonics, but I keep getting a vector length error for the FFT spectrum.

3 vues (au cours des 30 derniers jours)
N = 5;
f0 = 5;
tw = 1;
k = [1:2:N];
ak = 2./(pi*k);
T0 = 1/f0;
fs = 20*2*N*f0;
ts = 1/fs;
y = 0.5;
for m=1:length(k)
t=(0:ts:tw);
x = ak(m).*cos(2*pi*f0*k(m)*t-pi/2);
y = y+x;
h = plot(t,y);
xlabel('Time (s)')
end
fa = 0:fs/N:fs-fs/N;
f = fft(y)/N;
F = abs(f);
figure, plot(fa,f)

Réponses (0)

Catégories

En savoir plus sur Fourier Analysis and Filtering dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by