필터 지우기
필터 지우기

Problem with data precision while generating square wave.

조회 수: 2 (최근 30일)
Ashwini
Ashwini 2020년 11월 6일
답변: Mathieu NOE 2020년 11월 6일
I used square(2*pi*f*t) to generate a square wave.
I set f to 1000 and t=0:Ts:0.05
Ts=1.000000000000000e-05
when i type square(2*pi*1000*0.020500000000000) in command window, answer is +1 and for square(2*pi*1000*0.020510000000000) answer is -1
But when i run a program with the expression square(2*pi*f*t), even for square(2*pi*1000*0.020510000000000) , i am getting +1.
How to fix this???

답변 (1개)

Mathieu NOE
Mathieu NOE 2020년 11월 6일
hi
my suggestion
f = 1000 ;
Ts=1e-05;
t=0:Ts:0.05;
angl = 2*pi*(mod(f*t,1));
square_wav = 0.5*(sign(sin(angl))+1);
plot(t,angl);
plot(t,square_wav);

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by