clc
t=linspace(-1,1,256);%%%
F=1; %%% kare dalga frekansı
A=2; %%% kare dalga genliği
harmonik=3;
kare=zeros(1,length(t));
for k=1:harmonik
coeff=(2*A)/(k*pi)*sin(k*pi/2);
kare=coeff*cos(k*2*pi*F*t)+kare;
end k_d=A/2+kare;
figure(1)
plot(t,kare);
grid on
close all
time=20;
Ts=1/100; %%% örnekleme frekansı
t=0:Ts:(time-Ts);
x=2*[t <= 2]; %%%% kare dalga genliği ve zaman aralığı
N=length(x);
ssf=((-N/2):(N/2-1))/(Ts*N);
fx=Ts*fft(x(1:N));
fxs=fftshift(fx);
figure
subplot(2,1,1);
set(plot(t,x),'LineWidth',1.5);
xlabel('sn');
subplot(2,1,2);
set(plot(ssf,abs(fxs)),'LineWidth',1.5);
xlabel('Frekans [Hz]'); ylabel('Genlik')
What does this code do? I need only variables like fx, ssf etc. What are these for?

 채택된 답변

Image Analyst
Image Analyst 2020년 11월 18일

1 개 추천

The first part of the code makes an x axis, "t" and then does a loop where it computes a single value for kare, because it didn't index kare. If it had used kare(k) = ..... then kare would have been a vector and the plot would plot kare vs. t.
The second part computers fx and ssf according to the formulas and functions so it sounds like that's what you need. If you need more specifics, can you ask the author? Or just run it and see what it does?

댓글 수: 4

Cem Kagan AKBULUT
Cem Kagan AKBULUT 2020년 11월 19일
I need somethings like that. My teacher wants all meanings one by one. So right, i need more specifics. But thanks anyway.
Image Analyst
Image Analyst 2020년 11월 19일
If your teacher is trying to get you in the habit of commenting your code, then I would say that that is a very very good teacher. Putting in lots of comments (while you're typing, not hopefully after you're done with the whole program because that rarely ever happens) is one of my two main items of advice for programmers. The other is that you use descriptive variable names, not one or two letter, cryptic variable names which just makes an alphabet soup mess of a program. Thank your teacher also for teaching you a skill that hopefully you will retain and use for the rest of your life. Far too many programmers write unmaintainable code without sufficient comments and with cryptic variable names, making code that is impenetrable and difficult or impossible to understand and maintain.
Steven Lord
Steven Lord 2020년 11월 19일
Commenting your code as you're writing it is good. IMO commenting your code before you write it, so you keep track of what steps you need to implement, can be even better.
Cem Kagan AKBULUT
Cem Kagan AKBULUT 2020년 12월 8일
Thank you both. I'll keep working on it. I hope i can understand all the codes with comments because we don't take the lesson in english, so its kinda hard time to time.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by