vector length problem error

2 vues (au cours des 30 derniers jours)
MICHKEL ANGLO J
MICHKEL ANGLO J le 2 Août 2021
Commenté : MICHKEL ANGLO J le 2 Août 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");

Réponse acceptée

KSSV
KSSV le 2 Août 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 commentaires
Image Analyst
Image Analyst le 2 Août 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 le 2 Août 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");

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by