vector length problem error

1 回表示 (過去 30 日間)
MICHKEL ANGLO J
MICHKEL ANGLO J 2021 年 8 月 2 日
コメント済み: MICHKEL ANGLO J 2021 年 8 月 2 日
1. Compute the DFT of a sinusoidal signal with six frequencies: ω1=0.1*pi; ω2=0.2*pi; ω3=0.3*pi; ω4=0.4*pi; ω5=0.5*pi; ω6 =0.6*pi and plot the magnitude spectrum .for this qn tried many time but delimiter and vector error occurs.
here is my code:
w1=0.1*pi;
w2=0.2*pi;
w3=0.3*pi;
w4=0.4*pi;
w5=0.5*pi;
w6=0.6*pi;
t=0:1000;
x=sin(w1*t)+sin(w2*t)+sin(w3*t)+sin(w4*t)+sin(w5*t)+sin(w6*t);
y = fft(x);
m = abs(y);
c=2*pi*((0:length(y)-1)/2);
f = c/length(y);
plot(f/pi,m(1:length(y)-1/2));
title("magnitude spectrum");

採用された回答

KSSV
KSSV 2021 年 8 月 2 日
w1=0.1*pi;
w2=0.2*pi;
w3=0.3*pi;
w4=0.4*pi;
w5=0.5*pi;
w6=0.6*pi;
t=0:1000;
x=sin(w1*t)+sin(w2*t)+sin(w3*t)+sin(w4*t)+sin(w5*t)+sin(w6*t);
y = fft(x);
m = abs(y);
c=2*pi*((0:length(y)-1)/2);
f = c/length(y);
n = round(length(f)/2) ;
plot(f(1:n)/pi,m(1:n));
title("magnitude spectrum");
  3 件のコメント
Image Analyst
Image Analyst 2021 年 8 月 2 日
@MICHKEL ANGLO J, yes, you've got that. All the vectors are 1x1000. If youi don't agree, which are you saying have different length(s)?
MICHKEL ANGLO J
MICHKEL ANGLO J 2021 年 8 月 2 日
I mean line drawn (length of x to y axis)@Image Analyst. I got the output now.
w1=0.1*pi;
w2=0.2*pi;
w3=0.3*pi;
w4=0.4*pi;
w5=0.5*pi;
w6=0.6*pi;
t=0:1000;
x=sin(w1*t)+sin(w2*t)+sin(w3*t)+sin(w4*t)+sin(w5*t)+sin(w6*t);
m = abs(x);
c=2*pi*(0:1000);
f = c/1001;
n = round(length(f)/2) ;
plot(f(1:n)/pi,m(1:n));
title("magnitude spectrum");

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by