Trying to plot a sine wave, getting a straight line.

4 ビュー (過去 30 日間)
Nat
Nat 2018 年 2 月 8 日
コメント済み: Nat 2018 年 2 月 9 日
I need to create a time series using x(n)=sin(2pi/N)*n where N=256 and plot the amplitude. I keep getting a straight line instead of a sine wave. Any pointers?
%Create time series x(n)
N=256;
x=zeros(N,1); %allocate space
for n=1:N;
x(n)=sin((2*pi)/N)*n;
end
%Plot x(n)
figure(1)
n=0:255;
plot(n,x(1:N))
xlim([0 255])
ylim([-120 120])
xlabel('n')
ylabel('Amplitude')
title('x(n)'

採用された回答

Roger Stafford
Roger Stafford 2018 年 2 月 9 日
You have placed your ’n’ variable outside the parentheses for the sine function. That would make it a straight line. It should be this to get a sine curve:
x(n)=sin(2*pi/N*n);
  1 件のコメント
Nat
Nat 2018 年 2 月 9 日
Thanks Roger, that worked!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by