Work with signals, frequency spectrum and frequency domain
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
So i made this:
%% (s1):
A1=1;
F1=4;
Ucc=-2;
Fs=1000; %Ts=1/Fs;
D=2; %(seconds)
t=0:1/Fs:D;
fi=0;
%% (s2):
A2=1;
F2=4;
Fs=1000; %Ts=1/Fs;
D=2; %(seconds)
t=0:1/Fs:D;
fi=0;
%% attributes for the signal marker (s3):
L=8;
Lim=50*L;
%% the 3 signals:
s1=(A1*sin(2*pi*F1*t+fi))+Ucc;
s2=A2*sin(2*pi*F2*t+fi);
s3=s1+s2;
%% figure:
figure()
subplot(3,1,1),plot(t,s1,'r'),grid on,title('Signal s1'),xlabel('time (s)'),ylabel('Amplitude'), axis([0, D, -D-1.5, -D+1.5])
subplot(3,1,2),plot(t,s2,'m'),grid on,title('Signal s2'),xlabel('time (s)'),ylabel('Amplitude'), axis([0, D, -D+0.5, D-0.5])
subplot(3,1,3)
hold on
plot(t,s3,'b'),title('Signall s3=s1+s2'),xlabel('time (s)'),ylabel('Amplitude'), axis([0, D, -D-2.5, -D+2.5])
plot(t(Lim),s3(Lim),'y>','MarkerFaceColor','g')
hold off
yline(0)
But, instead of displaying the signals for a limited time, like 1 second, I want to display the signals as an evolution over time. And then move on to the frequency domain and provide the graphical representation of the frequency spectrum. And I don't really know how to do these things. Can it be done without Simu-link?
0 comentarios
Respuestas (1)
Thiago Henrique Gomes Lobato
el 21 de Jun. de 2020
This version of your code should do what you expect. After the loop I wrote an example of how to go to the frequency domain
%% Initialize loop
figure()
for idxTime=1:1000
%% (s1):
A1=1;
F1=4;
Ucc=-2;
Fs=1000;
Ts=1/Fs*10; % A factor is needed, othwerwise it will be too slow
D=2; %(seconds)
t=Ts*(idxTime-1):1/Fs:D+Ts*(idxTime-1);
fi=0;
%% (s2):
A2=1;
F2=8;
Fs=1000; %Ts=1/Fs;
D=2; %(seconds)
t=Ts*(idxTime-1):1/Fs:D+Ts*(idxTime-1);
fi=0;
%% attributes for the signal marker (s3):
L=8;
Lim=50*L;
%% the 3 signals:
s1=(A1*sin(2*pi*F1*t+fi))+Ucc;
s2=A2*sin(2*pi*F2*t+fi);
s3=s1+s2;
subplot(3,1,1),plot(t,s1,'r'),grid on,title('Signal s1'),xlabel('time (s)'),ylabel('Amplitude'), axis([t(1), t(end), -D-1.5, -D+1.5])
subplot(3,1,2),plot(t,s2,'m'),grid on,title('Signal s2'),xlabel('time (s)'),ylabel('Amplitude'), axis([t(1), t(end), -D+0.5, D-0.5])
subplot(3,1,3)
hold on
plot(t,s3,'b'),title('Signall s3=s1+s2'),xlabel('time (s)'),ylabel('Amplitude'), axis([t(1), t(end), -D-2.5, -D+2.5])
plot(t(Lim),s3(Lim),'y>','MarkerFaceColor','g')
hold off
yline(0)
pause(0.001)
end
% Spectrum
FFT3 = fft(s3);
f = [0:length(s3)-1]/length(s3)*Fs;
figure,semilogx(f(1:end/2),abs(FFT3(1:end/2)))
2 comentarios
Ver también
Categorías
Más información sobre Spectral Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!