답변 (1개)

Geoff Hayes
Geoff Hayes 2015년 10월 17일

0 개 추천

Abduladeam - in order to get the square wave, you will have to sum over the odd k (which is missing from your above equation). Also, you need to divide the 4 by (k*pi). Try the following code
freq = 1;
func = @(k,t)(4/(k*pi))*sin(2*pi*k*t*freq);
t = linspace(0,1,500);
k = 1;
% create a vector for k==1 across all t
fkt = func(k,t);
% now sum over the odd numbers
upperBound = 100;
for k=3:2:upperBound
fkt = fkt + func(k,t);
end
plot(t,fkt);
Adjust the freq to increase the frequency of the wave, and increase the upperBound in order to improve upon the square wave's approximation.

댓글 수: 2

Abduladeam abdullah
Abduladeam abdullah 2015년 10월 17일
thanks but this is the main equation f(t)=(4/m*pi)sin(2*pi*m*t) m=1,3,5,7,9
and I need to plot the sum of harmonics against time for a time period between 0 and 10
f(t)=(4/pi)sin(2*pi*t)+(4/3*pi)sin(2*pi*3*t)+(4/5*pi)sin(2*pi*5*t)+(4/7*Pi)sin(2*pi*7*t)
Geoff Hayes
Geoff Hayes 2015년 10월 17일
I'm not sure I understand your question then. Can you not use the above to code for your work?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

2015년 10월 17일

댓글:

2015년 10월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by