vector length problem error

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by