質問

let us consider following code

function [ x ] = generate1(N,m,A3)
f1 = 100;
f2 = 200;
T = 1./f1;
t = (0:(N*T/m):(N*T))'; %'
wn = randn(length(t),1); %zero mean variance 1
x = 20.*sin(2.*pi.*f1.*t) + 30.*cos(2.*pi.*f2.*t) + A3.*wn;
%[pks,locs] = findpeaks(x);
 %plot(x);
end

as i know peaks in Fourier domain represent at this frequency,which are present in signal,for example let us take plot of Fourier transform of this signal let us run this signal

y=generate1(3,500,1);

and plot

plot(abs(fft(y)))

enter image description here

but clearly it does not shows me peaks at frequency given in signal,what is problem?please help me,generally it is stationary signal,that why this graph should show me exact picture but it does not do,why?

EDITED :

y1=generate1(3,500,0); enter image description here

役に立ちましたか?

解決

function [ x, fs ] = generate1(N,m,A3)
f1 = 100;
f2 = 200;
T = 1./f1;
t = (0:(N*T/m):(N*T))'; %'
wn = randn(length(t),1); %zero mean variance 1
x = 20.*sin(2.*pi.*f1.*t) + 30.*cos(2.*pi.*f2.*t) + A3.*wn;
%[pks,locs] = findpeaks(x);
 %plot(x);
 fs = 1/(t(2)-t(1));
end

and see

absfft = abs(fft(y));
plot(fs/2*linspace(0,1,length(absfft)/2+1),2*absfft(1:end/2+1))

or

plot(linspace(-fs/2,fs/2,length(absfft)),fftshift(absfft))

the x-axis in your plot is from 0 to fs/2 and then from -fs/2 to 0

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top