Azzera filtri
Azzera filtri

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 visualizzazioni (ultimi 30 giorni)
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)

Risposte (0)

Categorie

Scopri di più su Fourier Analysis and Filtering in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by