The graph wasnt showing the appropiate answer
조회 수: 2 (최근 30일)
이전 댓글 표시
clc
clear all
Ts=0.1; %Ts=sampling time
Tc=Ts/100; %Tc=continuous time increament
Tr=10; %Tr=record time
A=1; %A=amplitude of vibration
f=1; %f=frequency of signal
%Plot of waveform (continuous and discrete)
t=0.001:Ts:Tr;
x=A*sin(2*pi*1*t)+ A*sin(2*pi*11*t);
tc=0:Tc:Tr;
xc=A*sin(2*pi*1*tc) + A*sin(2*pi*11*tc);
subplot(211)
plot(t,x,'*',tc,xc)
%Find the spectrum of x(kT), so X(iw)=fft(x(k))
Xs=fft(x); %Xs=spectrum of x
%Now we want to plot the magnitude of X(iw), thus |X(iw)|=abs(X(iw))
[k,b]=size(Xs);
N=b;
N2=N/2;
magXs=(2/N)*abs(Xs);
df=1/Tr; %df=Frequency resolution
i=0:(N2-1);
f1=df*i;
subplot(212)
plot(f1,magXs(1,1:N2))
subplot
This is the code and it wont show the right spectrum cause the other spectrum should be at 11 Hz
댓글 수: 0
답변 (1개)
Cris LaPierre
2021년 10월 19일
You have specificed a sample frequency of 10 Hz (Ts=0.1). Therefore, according the Nyquist criterion, the highest frequency you can resolve is 5 Hz.
댓글 수: 1
Cris LaPierre
2021년 10월 19일
Change your sample frequency to something at least double the maximum frequency you want to detect, and it will appear.
% v made Ts 10x smaller. Corresponding Fs is now 100 Hz. Can now resolve up to 50 Hz
Ts=0.01; %Ts=sampling time
Tc=Ts/100; %Tc=continuous time increament
Tr=10; %Tr=record time
A=1; %A=amplitude of vibration
f=1; %f=frequency of signal
%Plot of waveform (continuous and discrete)
t=0.001:Ts:Tr;
x=A*sin(2*pi*1*t)+ A*sin(2*pi*11*t);
tc=0:Tc:Tr;
xc=A*sin(2*pi*1*tc) + A*sin(2*pi*11*tc);
%Find the spectrum of x(kT), so X(iw)=fft(x(k))
Xs=fft(x); %Xs=spectrum of x
% Calculate magnitude of X(iw), thus |X(iw)|=abs(X(iw))
[k,b]=size(Xs);
N=b;
N2=N/2;
magXs=(2/N)*abs(Xs);
df=1/Tr; %df=Frequency resolution
i=0:(N2-1);
f1=df*i;
% Plot
subplot(211)
plot(t,x,'*',tc,xc)
subplot(212)
plot(f1,magXs(1,1:N2))
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!