Plotting a stem plot of a Fourier series

Here is my code:
% Plot amplitude vs frequencey
n = 0:15;
f = f0*n;
A = abs((8*10) ./ (pi^2) .* (1./n) .* cos(n.*w.*t));
figure
stem(f, A)
grid
xlabel('Frequency in Hz')
ylabel('Amplitude in Volts')
title('Signal Amplitude vs frequency ')
I keep on getting the error "Matrix dimesons must agree."
f0 is the funamental frequencey defined earlier in the code, it is 1e3 (aka 1kHZ).
t has also been predefined as t = linspace(0,3*T,1000);
T is the peroid, 1/f0 = 300ms.

 Respuesta aceptada

Supply the correct values for ‘f0’, ‘w’ and ‘t’, and it works —
% Plot amplitude vs frequencey
f0 = 1;
w = 2*pi*f0;
n = 0:15;
t = n;
f = f0*n;
A = abs((8*10) ./ (pi^2) .* (1./n) .* cos(n.*w.*t));
figure
stem(f, A)
grid
xlabel('Frequency in Hz')
ylabel('Amplitude in Volts')
title('Signal Amplitude vs frequency ')
I created some values for them here. Provide the correct ones.
.

4 comentarios

OvercookedRamen
OvercookedRamen el 1 de Oct. de 2021
Thanks big dog, I owe you.
Star Strider
Star Strider el 1 de Oct. de 2021
As always, my pleasure!
(I’m a polar bear, actually. That was more obvious when the thumbnails were square.)
.
OvercookedRamen
OvercookedRamen el 1 de Oct. de 2021
*Hands you a Coca-Cola *
Star Strider
Star Strider el 1 de Oct. de 2021
:-)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Preguntada:

el 1 de Oct. de 2021

Comentada:

el 1 de Oct. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by