vector length problem error

2 views (last 30 days)
MICHKEL ANGLO J
MICHKEL ANGLO J on 2 Aug 2021
Commented: MICHKEL ANGLO J on 2 Aug 2021
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");

Accepted Answer

KSSV
KSSV on 2 Aug 2021
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 Comments
Image Analyst
Image Analyst on 2 Aug 2021
@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 on 2 Aug 2021
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");

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!