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 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