plot square with a given average value
古いコメントを表示
Hi all,
I want to ask a question about plotting a square waveform by using Matlab. I can plot the square waveform with square() function but i don't know how i can draw a square wave with a certain average value. i must plot a square waveform with an average value -2.
Best regards, Dilem
回答 (1 件)
Wayne King
2012 年 3 月 24 日
t = 0:.0001:.0625;
y = square(2*pi*30*t)-2;
plot(t,y); set(gca,'ylim',[-3.5 -0.5]);
hold on; grid on;
plot(t,mean(y).*ones(length(y),1),'r');
If you want it exactly -2,
y = square(2*pi*30*t);
y = y-mean(y)-2;
plot(t,y); set(gca,'ylim',[-3.5 -0.5]);
hold on; grid on;
plot(t,mean(y).*ones(length(y),1),'r');
3 件のコメント
dilem
2012 年 3 月 24 日
Wayne King
2012 年 3 月 24 日
no, look at the mean-value theorem for integrals if you want to think of the square wave as a continuous time function. If you want to think of it as a vector, you simply sum the elements of the vector and divide by the number of elements.
y = square(2*pi*30*t);
y = y-mean(y)-2;
mean(y)
you get -2. The mean of y is -2. You can also see from the plot that I showed you how to produce that the mean value is -2.
dilem
2012 年 3 月 24 日
カテゴリ
ヘルプ センター および File Exchange で Waveform Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!