Problem with data precision while generating square wave.
2 ビュー (過去 30 日間)
古いコメントを表示
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???
0 件のコメント
回答 (1 件)
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);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!