Plot discrete fourier transform of a sine wave

18 ビュー (過去 30 日間)
Cynthia Lucy
Cynthia Lucy 2021 年 5 月 10 日
コメント済み: Star Strider 2021 年 5 月 10 日
Hi, I want to plot the sampled signal in frequency domain which means I need to use the discrete fourier transform, right? But when I run the code below I only get the display of sampled signal in discrete time domain and an error saying vector lengths must match came out on the command window. What does this mean? And what should be fixed? Please help me.
%chap1-38a
f = 6000;
fs = 16000;
w = 2*pi*(f/fs);
n = 0:50;
y = sin(w.*n);
subplot(2,1,1);
stem(n,y);
f = -fs/2:fs/(N-1):fs/2;
z = fftshift(fft(x));
subplot(2,1,2);
plot(f,abs(z));
The display when I run the code.

採用された回答

Star Strider
Star Strider 2021 年 5 月 10 日
Try this —
f = 6000;
fs = 16000;
w = 2*pi*(f/fs);
N = 50;
n = 0:N;
y = sin(w.*n);
subplot(2,1,1);
stem(n,y);
f = -fs/2:fs/(N):fs/2;
z = fftshift(fft(y));
subplot(2,1,2);
plot(f,abs(z));
I will let you discover the changes I made that are necessary to make it run!
  2 件のコメント
Cynthia Lucy
Cynthia Lucy 2021 年 5 月 10 日
Ive found the changes you made and now I understand what is wrong with my previous code! Thank you so much for your help! @Star Strider
Star Strider
Star Strider 2021 年 5 月 10 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by