The graph wasnt showing the appropiate answer

3 次查看(过去 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

回答(1 个)

Cris LaPierre
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
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))

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by