Lab13
Lab13
LAB NO : 13
Remarks:
DEADLINE:
DATE OF SUBMISSION:
FOURIER TRANSFORM
The Fourier transform is a mathematical formula that transforms a signal sampled in time or space
to the same signal sampled in temporal or spatial frequency. In signal processing, the Fourier
transform can reveal important characteristics of a signal, namely, its frequency components.
The Fourier transform is defined for a vector with uniformly sampled points
The fft function in MATLAB® uses a fast Fourier transform algorithm to compute the Fourier
transform of data.
PRACTICE EXERCISE 2:
Consider a sinusoidal signal x that is a function of time t with frequency components of 15 Hz and
20 Hz. Use a time vector sampled in increments of 1/50 seconds over a period of 10 seconds.
Find the Fourier transform of a signal which consists of two sine signals with 15Hz and 20Hz
frequencies. Perform fft shift to have the fourier transform on respective correct frequencies.
Ts = 1/50;
t = 0:Ts:10-Ts;
x = sin(2*pi*15*t) + sin(2*pi*20*t);
subplot 311 ; plot(t,x)
xlabel('Time (seconds)')
ylabel('Amplitude')
title('Time domain signal with 15Hz and 20Hz frequencies')
Compute the Ïouíieí tíansfoím of the signal, and cíeate the vectoí f that coííesponds to the signal's sampling in
fíequency space.
y = fft(x);
fs = 1/Ts;
f = (0:length(y)-1)*fs/length(y);
When you plot the magnitude of the signal as a function of fíequency, the spikes in magnitude coííespond
to the signal's fíequency components of 15 Hz and 20 Hz.
subplot 312; plot(f,abs(y))
xlabel('Frequency (Hz)')
ylabel('Magnitude')
title('FFT Magnitude')
The transform also produces a mirror copy of the spikes, which correspond to the signal's negative
frequencies. The reason is that the Fourier transform is symmetric about the y-axis, because the
Fourier transform is mathematically defined on the interval (-Inf,Inf). The actual Fourier transform
therefore has negative frequencies.
To better visualize this periodicity, you can use the fftshift function, which performs a zero-
centered, circular shift on the transform.
n = length(x);
fshift = (-n/2:n/2-1)*(fs/n);
yshift = fftshift(y);
subplot 313;
plot(fshift,abs(yshift))
xlabel('Frequency (Hz)')
ylabel('Magnitude')
title('FFT Magnitude after shift')
FOURIER TRANSFORM(FFT) OF SIGNAL WITH NOISE
In scientific applications, signals are often corrupted with random noise, disguising their frequency
components. The Fourier transform can process out random noise and reveal the frequencies. For
example, create a new signal, xnoise, by injecting Gaussian noise into the original signal, x.
Signal power as a function of frequency is a common metric used in signal processing. Power is the
squared magnitude of a signal's Fourier transform, normalized by the number of frequency samples.
PRACTICE EXERCISE 3:
Compute and plot the poweí spectíum of the noisy signal centeíed at the zeío fíequency. Despite noise, you
can still make out the signal's fíequencies due to the spikes in poweí.
rng('default')
xnoise = x + 2.5*randn(size(t));
ynoise = fft(xnoise);
ynoiseshift = fftshift(ynoise);
%power = abs(ynoiseshift).^2/n;
figure
plot(fshift,abs(ynoiseshift))
title('fft of signal with noise')
xlabel('Frequency (Hz)')
ylabel('Magnitude')
COMPUTATIONAL EFFICIENCY WITH FFT
Using the Fourier transform formula directly to compute each of the elements of requires on the
order of floating-point operations. The fast Fourier transform algorithm requires only on the
order of operations to compute. This computational efficiency is a big advantage when processing
data that has millions of data points. Many specialized implementations of the fast Fourier transform
algorithm are even more efficient when has small prime factors, such as is a power of 2.
PRACTICE EXERCISE 4:
Consider audio data collected from underwater microphones off the coast of California. This data
can be found in a library maintained by the Coínell Univeísity Bioacoustics Reseaích Píogíam. Load and
format a subset of the data in bluewhale.au, which contains a Pacific blue whale vocalization.
Because blue whale calls are low-frequency sounds, they are barely audible to humans. The time
scale in the data is compressed by a factor of 10 to raise the pitch and make the call more clearly
audible. You can use the command sound(x,fs) to listen to the entire audio file.
Write code to take the FFT of the audio and listen to the sound of the audio file.
whaleFile = 'bluewhale.au';
[x,fs] = audioread(whaleFile);
whaleMoan = x(2.45e4:3.10e4);
t = 10*(0:1/fs:(length(whaleMoan)-1)/fs);
plot(t,whaleMoan)
xlabel('Time (seconds)')
ylabel('Amplitude')
xlim([0 t(end)])
% write code to listen to the sound of the audio file.
Exercise 1 , 2 :
CODE:
Results:
Exercise 3:
CODE:
Results:
Task 4.1: Read Audio FILE:
CODE:
Results:
Results:
END