Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Errors in plotting Amplitude and Angular spectra of a functions .... (HELP !!!!)

Subject: Errors in plotting Amplitude and Angular spectra of a functions .... (HELP !!!!)

From: Animesh Pandey

Date: 6 Apr, 2011 13:34:05

Message: 1 of 2

clc
syms an bn a0;
syms t n;
syms x;

T = 2;
N = 33;
x = heaviside(t+0.5) - heaviside(t-0.5);
f = @(t) x;

an = int(f(t).*cos(n*pi*t/T),t,-T,T)*(1/T);
bn = int(f(t).*sin(n*pi*t/T),t,-T,T)*(1/T);
a0 = int(f(t),t,-T,T)*(1/T);
y = a0;

cn = sqrt((an*an) + (bn+bn));
angcn = atan2(an, bn);

pretty(a0);
pretty(an);
pretty(bn);
pretty(cn); %Amplitude Spectrum
pretty(angcn); %Frequency Spectrum

for i=1:1:N;
     y = y + subs(an, i).*cos(2*pi*i*t/T) + subs(bn, i).*sin(2*pi*i*t/T);
     y1= subs(cn, i);
end

y

t=-5 : 0.01 : 5 ;
er = eval(y);
er1 = eval(y1);
plot(t, er), grid;
figure, plot(t,er1), grid;

This program should plot the Fourier series, Amplitude spectrum and Angular Spectrum.
This plots fourier series just fine .....
I am getting errors in plotting both the spectra.

Please help !!!!
Thanx :)

Subject: Errors in plotting Amplitude and Angular spectra of a functions

From: Greg Heath

Date: 7 Apr, 2011 08:58:38

Message: 2 of 2

On Apr 6, 9:34 am, "Animesh Pandey" <apanimesh...@gmail.com> wrote:
.....
> cn = sqrt((an*an) + (bn+bn));
> angcn = atan2(an, bn);

Both statements are incorrect.

Hope this helps.

Greg

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us