Académique Documents
Professionnel Documents
Culture Documents
WAVES PART II
% Creates an array t
% Generates a sine wave with period for the elements of t
% Breaks the figure window into an 3X1 matrix of plots and
% chooses the first plot row wise
plot(t,a,'LineWidth',2) % Generates a plot of t vs a
grid on
% Displays a grid on the plot
axis([0 20 -1.2 1.2])
xlabel('time')
% Labels the x axis
ylabel('sin(t)')
% Labels the y axis
title('Plot to show that the sum of sine waves of different frequencies does not
result in a sine wave')
% Displays a title for the plot
% Code continued on next page
b= sin(4*t);
subplot(3,1,2)
plot(t,b,'LineWidth',2)
grid on
axis([0 20 -1.2 1.2])
xlabel('time')
ylabel('sin(4t)')
% Generates a plot of t vs c
% Displays a grid on the plot
% Labels the x axis
% Labels the y axis
c= a + b;
subplot(3,1,3)
plot(t,c,'LineWidth',2) % Generates a plot of t vs c
grid on
% Displays a grid on the plot
axis([0 20 -2.4 2.4])
xlabel('time')
% Labels the x axis
ylabel('sin(t)+sin(4t)') % Labels the y axis
Plot to show that the sum of sine waves of different frequencies does not result in a sine wave
sin(t)
1
0
-1
0
10
time
12
14
16
18
20
10
time
12
14
16
18
20
10
time
12
14
16
18
20
sin(4t)
1
0
sin(t)+sin(4t)
-1
2
0
-2
10
time
12
14
16
18
20
% Creates an array t
s = zeros(1,N);
for k=1:1:1001
s= -(sin(2*pi*k.*t)./k)+ s;
end
plot(t,s,'LineWidth',2)
grid on
title('Generation of Sawtooth waveform from Sine Waves of different frequencies')
10
FFT IN MATLAB
The Fourier theorem states that any waveform can be duplicated
by the superposition of a series of sine and cosine waves.
We did this while generating a square from the superposition of
sine waves of different frequencies!
We use Fourier transform to perform the decomposition
Were going from time domain to frequency domain
FFT( Fast Fourier transform) is an algorithm to find the Fourier
transform of an input sequence
We use the MATLAB command fft
>> g=[1 2 3 4 5];
>> fft(g)
ans =
15.0000
-2.5000 + 3.4410i -2.5000 + 0.8123i -2.5000 0.8123i -2.5000 - 3.4410i
-50
Magnitude in dB
-100
-150
-200
-250
-300
-350
-80
-60
-40
-20
0
Frequency in Hz
20
40
60
80
SPECTRUM OF SPEECH
Type this in the MATLAB command window
>>demoai_fft
CHIRP SIGNAL
clc;
clear
close all;
Fs = 4000;
T = 1;
dt = 1/Fs;
N = T*Fs;
% Number of samples
df = Fs/N;
% frequency spacing
t = (1:N)*dt - dt;
% time samples
f(1:N/2)=(1:N/2)*df-df;
% Nonnegative frequency samples
f(N/2+1:N)=-fmax+(0:N/2-1)*df; % Negative frequency samples
f2=fftshift(f);
% shifting the values in f so that it goes from f max to +fmax
% Code continued on next page
x = cos(f.*t);
wavplay(x,1/dt)
plot(t,x)
axis([0 2.2 -1.2 1.2])
xf = fft(x).*dt;
xf = fftshift(abs(xf)); % Absolute value of the Fourier coefficients
figure
stem(f,xf)
grid on
title(Spectrum of chirp signal)
% Creates an array t
x = zeros(1,N);
x(1,N/4:N/2) = 1:-4/N:0;
x(1,N/2:(3*N/4)) = 0:4/N:1;
%plot(x_r)
plot(t,x_r,'LineWidth',2)
grid on