i dont know why my code is not working..

조회 수: 3 (최근 30일)
okan
okan 2014년 12월 24일
편집: Yona 2014년 12월 25일
if true
fs = 200;
Ts = 1/fs;
t = 0:Ts:50; % Zaman vektörü
u2=sin(2.*pi.*(1+5.*t).*t);
N=ceil(log2(length(u2)));
for k=1:N
X(k)=0;
for n=1:N
X(k)=X(k)+u2(n).*exp(-1j.*2.*pi.*(n-1).*(k-1)./N);
end
end
Pyy=X.*conj(X);
f=fs*(0:(2^(N-1)-1))/2^N;
figure(1),plot(f,Pyy(1:2^(N-1)));
[MAX, MAXidx] = max(Pyy(1:2^(N-1)));
hold on
plot(f(MAXidx), MAX,'or')
end
Index exceeds matrix dimensions.

답변 (1개)

Yona
Yona 2014년 12월 24일
plot(f,Pyy(1:2^(N-1)));
the length of pyy in 14 so you cannot take cell number 16384 (2^13).
another problem: length(f)=8196 so length(Pyy) need to be the same.
  댓글 수: 3
okan
okan 2014년 12월 24일
btw when i use that
if true
fs = 200; % Örnekleme frekansı fs
Ts = 1/fs; % Öernekleme periyodu Ts
% Oluşturacağımız sinyaldeki frekanslar
t = 0:Ts:50; % Zaman vektörü
u2=sin(2.*pi.*(1+5.*t).*t);
noise=u2+0.5*randn(size(t));
N=ceil(log2(length(u2)));
X=fft(noise);
Pyy=X.*conj(X);
f=fs*(0:(2^(N-1)-1))/2^N;
figure(1),plot(f,Pyy(1:2^(N-1)));
[MAX, MAXidx] = max(Pyy(1:2^(N-1)));
hold on
plot(f(MAXidx), MAX,'or')
figure(1),ylabel('Genlik');
figure(1),xlabel('Zaman (s)');
figure(1),grid;
end
its working but i shouldn't use fft command for my homework
Yona
Yona 2014년 12월 24일
편집: Yona 2014년 12월 25일
In your error-file length(X)=14 and in correct-file it 1001. try to check why it append, it probably will fix your problem

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by