Professional Documents
Culture Documents
% ON-LINE HELP
help fft
dt=0.1;
t=0:dt:12.7;
signal_1=sin(2*pi*0.2362*t);
figure(1),plot(t,signal_1,'-o');
N=128;
ft_signal_1=fft(signal_1);
F=[0:N/2-1]/(N*dt);
figure(2),plot(F(1:64),imag(ft_signal_1(1:64)),'o')
dt=0.1;
t=0:dt:12.7;
signal_2=sin(2*pi*0.2362*t+pi/4);
N=128;
ft_signal_2=fft(signal_2,N);
F=[0:N/2-1]/(N*dt);
figure(3),
subplot(3,1,1)
plot(t,signal_2,'-o'),title('Original Signal')
subplot(3,1,2)
plot(F(1:32),real(ft_signal_2(1:32)),'o'),title('Real part of FFT')
subplot(3,1,3)
plot(F(1:32),imag(ft_signal_2(1:32)),'o'),title('Imaginary part of FFT')
dt=0.1;
t=0:dt:12.7;
signal_3=sin(2*pi*0.5*t)+3*sin(2*pi*1.5*t+pi/8);
N=128;
ft_signal_3=fft(signal_3,N);
F=[0:N/2-1]/(N*dt);
figure(4),
subplot(3,1,1)
plot(t,signal_3,'-o'),title('Original Signal')
subplot(3,1,2)
plot(F(1:32),real(ft_signal_3(1:32)),'o'),title('Real part of FFT')
subplot(3,1,3)
plot(F(1:32),imag(ft_signal_3(1:32)),'o'),title('Imaginary part of FFT')
%Figure C.5 of the textbook:
dt=0.1;
t=0:dt:6.3;
signal_4=sin(2*pi*4*t);
N=64;
ft_signal_4=fft(signal_4);
F=[0:N/2-1]/(N*dt);
figure(6),
subplot(3,1,1)
plot(t,signal_4,'-o')
subplot(3,1,2)
plot(F(1:32),real(ft_signal_4(1:32)),'o')
subplot(3,1,3)
plot(F(1:32),imag(ft_signal_4(1:32)),'o')
dt=0.2;
t=0:dt:6.3;
signal_5=sin(2*pi*4*t);
N=32;
ft_signal_5=fft(signal_5);
t1=0:0.05:6.3;
signal_4_full=sin(2*pi*4*t1);
F=[0:N/2-1]/(N*dt);
figure(7),
subplot(3,1,1)
plot(t,signal_5,'-o',t1,signal_4_full)
subplot(3,1,2)
plot(F(1:16),real(ft_signal_5(1:16)),'o')
subplot(3,1,3)
plot(F(1:16),imag(ft_signal_5(1:16)),'o')
power_signal_3=abs(ft_signal_3).^2/128;
N=128;
F=[0:N/2-1]/(N*dt);
figure(8),
plot(F(1:64),power_signal_3(1:64),'-o')
% POWER SPECTRUM ANALYSIS WITH MATLAB FFT
help randn
% The first 256 points (the other 256 points are symmetric) can be graphed on a
% frequency axis where we input length of the physical time interval 0.001s:
f = 1000*(0:255)/512;
figure(4),plot(f,Pyy(1:256)), xlabel('Frequency (Hz)'), ylabel('Power Spectrum')
load signal_xy.dat;
figure(5),plot(t,fpu_signal)
Y = fft(fpu_signal,512);
N=512;
ampl_s1=abs(fft(signal_3,N));
ampl_s2=abs(fft(signal_6,N));
ampl_s3=abs(fft(signal_9,N));
%A real number signal should have a transform amplitude that is symmetrical for
% positive and negative frequencies
help fftshift
ampl_s1=fftshift(ampl_s1);
ampl_s2=fftshift(ampl_s2);
ampl_s3=fftshift(ampl_s3);
% Spectrum now goes from -f_s/2 to f_s/2 where f_s is the sampling
% frequency and f_s/2 is the Nyqist frequency
F=[-N/2:N/2-1]/N;
figure(2)
subplot(3,1,1)
plot(F,ampl_s1),title('3 periods'),
subplot(3,1,2)
plot(F,ampl_s2),title('6 periods'),
subplot(3,1,3)
plot(F,ampl_s3),title('9 periods'), xlabel('frequency/f_s')
w1 = 7; w2 = 23;
t = [0:0.005:2];
x = cos(w1*t) + cos(w2*t);
figure(5),clf,plot(t,x),grid,xlabel('Time (s)'),ylabel('Amplitude'),...
set(gcf,'Position',fig_size)
t1 = [0:Ts1:2];
xlabel('Time (s)'),ylabel('Amplitude'),...
set(gcf,'Position',fig_size)
%
t2 = [0:Ts2:2];
xlabel('Time (s)'),ylabel('Amplitude'),...
set(gcf,'Position',fig_size)
t3 = [0:Ts3:2];
xlabel('Time (s)'),ylabel('Amplitude'),...
set(gcf,'Position',fig_size)
% Since ws3 < 2*w2, the Nyquist Sampling Theorem is violated, and x(t)
% could not be recovered from the samples obtained with Ts3 using an ideal
% low-pass filter. Aliasing has occurred. The samples of the original
% x(t) using a sampling period Ts3 have exactly the same values that the
% signal x1(t) = cos(w1*t) + cos((w2-ws3)*t) would have when sampled with
% a sampling period Ts3. w2 - w3 = -8.4159 r/s.
w2s3 = w2 - ws3;
x1 = cos(w1*t) + cos(w2s3*t);
%
figure(9),clf,stem(t3,xs3);grid,hold on,plot(t,x,'k:',t,x1,'r:'),...
set(gcf,'Position',fig_size),...
text(1.13,1.2,'x(t)'),text(0.1,1.6,'x_1(t)')