Filter löschen
Filter löschen

Problem with data precision while generating square wave.

2 Ansichten (letzte 30 Tage)
Ashwini
Ashwini am 6 Nov. 2020
Beantwortet: Mathieu NOE am 6 Nov. 2020
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???

Antworten (1)

Mathieu NOE
Mathieu NOE am 6 Nov. 2020
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);

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by