• No results found

Fast Fourier Transform

N/A
N/A
Protected

Academic year: 2020

Share "Fast Fourier Transform"

Copied!
13
0
0

Loading.... (view fulltext now)

Full text

(1)

http://www.bogotobogo.com/Matlab/Matlab_Tutorial_DFT_Discrete_Fourier_Transform.php Signal Processing

Signal Processing Toolbox™ provides functions and apps to generate, measure, transform, filter, and visualize signals. The toolbox includes algorithms for resampling, smoothing, and synchronizing signals, designing and analyzing filters, estimating power spectra, and measuring peaks, bandwidth, and distortion. One can use Signal Processing Toolbox to analyze and compare signals in time, frequency, and time-frequency domains, identify patterns and trends, extract features, and develop and validate custom algorithms to gain insight into your data.

Signal Processing Toolbox Central Features

The Signal Processing Toolbox functions are algorithms, expressed mostly in M-files that implement a variety of signal processing tasks. These toolbox functions are a specialized extension of the MATLAB computational and graphical environment.

Filtering and FFTs

Two of the most important functions for signal processing are not in the Signal Processing Toolbox are built-in MATLAB functions:

•filter applies a digital filter to a data sequence.

•fft calculates the discrete Fourier transform of a sequence.

The Signal Processing Toolbox uses many other standard MATLAB functions and language features, including polynomial root finding, complex arithmetic, matrix inversion and manipulation, and graphics tools.

Signals and Systems

The basic entities that toolbox functions work with are signals and systems. The functions emphasize digital, or discrete, signals and filters, as opposed to analog, or continuous, signals. The principal filter type the toolbox supports is the linear, time-invariant digital filter with a single input and a single output.

Key Areas: Filter Design and Spectral Analysis

In addition to its core functions, the toolbox provides rich, customizable support for the key areas of filter design and spectral analysis. It is easy to implement a design technique that suits your application, design digital filters directly, or create analog prototypes and discretize them. Toolbox functions also estimate power spectral density and cross spectral density, using either parametric or nonparametric techniques.

Fourier Transforms

The Fourier transform defines a relationship between a signal in the time domain and its representation in the frequency domain. The time domain is displayed as a WAVEFORM of voltage versus time, whereas the frequency domain is shown as a spectrum of magnitude or power versus frequency.

The FFT can be used to simply characterize the magnitude and phase of a signal, or it can be used in combination with other operations to perform more involved computations such as convolution or correlation.

(2)

A Fast Fourier transform (FFT) is a fast computational algorithm to compute the discrete Fourier transform (DFT) and its inverse. The Fast Fourier Transform does not refer to a new or different type of Fourier transform. It refers to a very efficient algorithm for computing the DFT.

The time takes to perform a DFT on a computer depends primarily on the number of multiplications involved (O(N2)) while FFT only needs Nlog2(N).

The central insight which leads to this algorithm is the realization that a discrete Fourier transform of a sequence of N points can be written in terms of two discrete Fourier transforms of length N/2. Therefore, if N is a power of 2, it is possible to recursively apply this decomposition.

Basic Concept

Spectral Windowing

The FFT computation presumes that the input data repeats over and over. This is important when the initial and final values of your data are not the same: the discontinuity causes aberrations in the spectrum computed by the FFT. "Windowing" smooths the ends of the data to eliminate these aberrations.

Power Spectra (Spectral Analysis of Signals)

"Power Spectra" answer the question "which frequencies contain the signal´s power?" The answer is in the form of a distribution of power values as a function of frequency, where "power" is considered to be the average of the signal². In the frequency domain, this is the square of FFT´s magnitude.

Power spectra can be computed for the entire signal at once (a "periodogram") or periodograms of segments of the time signal can be averaged together to form the "power spectral density". Spectral analysis is of tree types – (i) Spectral analysis of stationary sinusoidal signals (parameters are amplitude, frequency and phase).

(ii) Spectral analysis of non stationary sinusoidal signals with time varying parameters (e.g Radar, Speech and Sonar Signals).

(iii) spectral analysis of random signals. Hilbert Transform

(3)

The Hilbert Transform computes a time-domain signal that is 90 degrees "out of phase" with the input signal. One-dimensional applications include computing the envelope of a modulated signal and the measurement of the decay rate of an exponentially decaying sinusoid often encountered in underdamped linear and non-linear systems.

Time Frequency Analysis

When you compute the Fourier spectrum (or Power Spectra) of a signal you dispose of all the phase information contained in the Fourier transform. You can find out which frequencies a signal contains but you do not know when these frequencies appear in the signal. For example, consider the signal:

The spectral representation of f(t) remains essentially unchanged if we interchange the two frequencies f1 and f2:

Clearly the Fourier spectrum is not the best analysis tool for signals whose spectra fluctuate in time.

One solution to this problem is the so-called "Short-time Fourier Transform" (or "Sonogram") in which you can compute the Fourier spectra using a sliding temporal window. By adjusting the width of the window you can determine the time resolution of the resulting spectra.

Other alternative tools are the Wigner transform, the Continuous Wavelet Transform (CWT), and the Discrete Wavelet Transform (DWT).

Sonogram: Also called the "Short-time Fourier Transform", a sonogram is a two-dimensional image created by computing the Fourier spectra

Winger Transform: he Wigner transform (also known as the Wigner Distribution Function or WDF) maps a 1D time signal U(t) into a 2D time-frequency representation.

Continuous Wavelet Transform: The Continuous Wavelet Transform (CWT) is a time-frequency representation of signals that graphically has a superficial similarity to the Wigner transform.

Discrete Wavelet Transform: The Discrete Wavelet Transform (DWT) is similar to the Fourier transform in that it is a decomposition of a signal in terms of a basis set of functions.

Convolution and Correlation

You can use convolution to compute the response of a linear system to an input signal. The linear system is defined by its impulse response. The convolution of the input signal and the impulse response is the output signal response. Digital filtering is accomplished by defining a linear system´s impulse response that when convolved with the signal accomplishes the desired result (low-pass or high-pass filter). The correlation

(4)

algorithm is very similar mathematically to convolution, but is used for different purposes. It is most frequently used to identify the time delay at which two signals "line up", or are "most similar".

Smoothing

Smoothing removes short-term variations, or "noise" to reveal the important underlying form of the data.

The simplest form of smoothing is the "moving average" which simply replaces each data value with the average of neighboring values. (Other terms for this kind of smoothing are "sliding average", "box smoothing", or "boxcar smoothing".)

Igor´s Smooth operation performs box smoothing, "binomial" (Gaussian) smoothing, and Savitzky-Golay (polynomial) smoothing. The different smoothing algorithms compute weighted averages that multiply neighboring values by differing weights or "coefficients" to compute the smoothed value.

Digital Filters

The digital filter is a discrete system, and it can do a series of mathematic processing to the input signal, and therefore obtain the desired information from the input signal. Digital filters are a natural tool when data is already digitized. Reasons for applying digital filtering to data include:

Elimination of unwanted signal components ("noise") Enhancing of desired signal components

Detecting the presence of certain signals

Simulation of linear systems (compute the output signal given the input signal and the system´s "transfer function")

Digital filters generally come in two flavors: Finite Impulse Response (FIR) and Infinite Impulse Response (IIR) filters.

The following are several steps of designing a digital filter:

1. Make sure of the property of a digital filter according to the given requirements. 2. Use a discrete linear time-invariant system function to approach to the properties. 3. Make use of algorithms to design the system function.

4. Use a computer simulation or hardware to achieve it.

FIR filter: The finite impulse response (FIR) filter is one of the most basic elements in a digital signal processing system, and it can guarantee a strict linear phase frequency characteristic with any kind of amplitude frequency characteristic. Besides, the unit impulse response is finite; therefore, FIR filters are stable system. The FIR filter has a 7 broad application in many fields, such as telecommunication, image processing, and so on.

IIR filter: The infinite impulse response (IIR) filter is recursive structure, and it has a feedback loop. The precision of amplitude frequency characteristic is very high, and IIR filters are not linear phase.

Comparison of FIR and IIR

(1) Under the same conditions as in the technical indicators, output of the IIR filter has feedback to input, so it can meet the requirements better than FIR. The storage units are less than those of IIR, the number of calculations is also less, and it’s more economical.

(2) The phase of FIR filter is strictly linear, while the IIR filter is not. The better the selectivity of IIR filter is, the more serious the nonlinearity of the phase will be.

(5)

(3) The FIR filter is non-recursive structure, finite precision arithmetic error is very small. While IIR filter is recursive structure, and parasitic oscillation may occur in the operation of IIR filter. (4) Fast Fourier Transformation can be used in FIR filter, while IIR cannot.

(5)The IIR filter can make use of the formulas, data and tables of the analog filter, and only a small amount of calculation. While FIR filter design may always make use of the computer to calculate, and the order of FIR filter could be large to meet the design specifications.

Level Detection

Level detection is the process of locating the X coordinate at which your data passes through or reaches a given Y value. This is sometimes called "inverse interpolation". Stated another way, level detection answers the question: "given a Y level, what is the corresponding X value?"

Igor provides two kinds of answers to that question. One answer assumes your Y data is a list of unique Y values that increases or decreases monotonically.

The other answer assumes that your Y data varies irregularly, as it would with acquired data. In this case, there may be multiple X values that cross the Y level. Important examples of this are edge and pulse statistics.

A related, but different question is "given a function y = f(x), find x where y is zero (or some other value)". This question is answered by the FindRoots operation.

Finite-Element Methods for PDEs

The finite element method (FEM) is a numerical technique for finding approximate solutions to boundary value problems for partial differential equations. It is also referred to as finite element analysis (FEA). FEM subdivides a large problem into smaller, simpler, parts, called finite elements. The simple equations that model these finite elements are then assembled into a larger system of equations that models the entire problem. FEM then uses variational methods from the calculus of variations to approximate a solution by minimizing an associated error function.

Applications:

A variety of specializations under the umbrella of the mechanical engineering discipline (such as aeronautical, biomechanical, and automotive industries) commonly use integrated FEM in design and development of their products. In a structural simulation, FEM helps tremendously in producing stiffness and strength visualizations and also in minimizing weight, materials, and costs.

FEM software provides a wide range of simulation options for controlling the complexity of both modeling and analysis of a system. FEM allows entire designs to be constructed, refined, and optimized before the design is manufactured.

Fast Fourier Transform (FFT) Introduction

DFTs with a million points are common in many applications. Direct application of the definition of the DFT to a data vector of length n requires n multiplications and n additions—a total of 2n2 floating-point operations. This does not include the generation of the powers of the complex nth root of unity ω.

(6)

Fast Fourier Transform (FFT) algorithms have computational complexity O(n log n) instead of O(n2). If n is a power of 2, a one-dimensional FFT of length n requires less than 3n log2n floating-point operations (times a proportionality constant). For n = 220, that is a factor of almost 35,000 faster than 2n2.

The MATLAB® functions fft, fft2, and fftn (and their inverses ifft, ifft2, and ifftn, respectively) all use fast Fourier transform algorithms to compute the DFT.

An FFT algorithm pads or chops the input to achieve the desired transform length. The following figure illustrates the two lengths.

The execution time of an FFT algorithm depends on the transform length. The FFT in One Dimension

Introduction

The MATLAB fft function returns the DFT y of an input vector x using a fast Fourier transform algorithm: y = fft(x);

In this call to fft, the window length m = length(x) and the transform length n = length(y) are the same. The transform length is specified by an optional second argument:

y = fft(x,n);

In this call to fft, the transform length is n. If the length of x is less than n, x is padded with trailing zeros to increase its length to n before computing the DFT. If the length of x is greater than n, only the first n elements of x are used to compute the transform.

Basic Spectral Analysis

The FFT allows you to efficiently estimate component frequencies in data from a discrete set of values sampled at a fixed rate. Relevant quantities in a spectral analysis are listed in the following table. For space-based data, replace references to time with references to space.

Quantity Description

x Sampled data

m = length(x) Window length (number of samples)

fs Samples/unit time

dt = 1/fs Time increment per sample

t = (0:m-1)/fs Time range for data

y = fft(x,n) Discrete Fourier transform (DFT)

abs(y) Amplitude of the DFT

(abs(y).^2)/n Power of the DFT

(7)

Quantity Description

f = (0:n-1)*(fs/n) Frequency range

fs/2 Nyquist frequency

Consider the following data x with two component frequencies of differing amplitude and phase buried in noise. fs = 100; % Sample frequency (Hz)

t = 0:1/fs:10-1/fs; % 10 sec sample

x = (1.3)*sin(2*pi*15*t) ... % 15 Hz component

+ (1.7)*sin(2*pi*40*(t-2)) ... % 40 Hz component

+ 2.5*gallery('normaldata',size(t),4); % Gaussian noise;

Use fft to compute the DFT y and its power. m = length(x); % Window length

n = pow2(nextpow2(m)); % Transform length

y = fft(x,n); % DFT

f = (0:n-1)*(fs/n); % Frequency range

power = y.*conj(y)/n; % Power of the DFT

nextpow2 finds the exponent of the next power of two greater than or equal to the window length (ceil(log2(m))) and pow2 computes the power. Using a power of two for the transform length optimizes the FFT algorithm, though in practice there is usually little difference in execution time from using n = m.

To visualize the DFT, plots of abs(y), abs(y).^2, and log(abs(y)) are all common. A plot of power versus frequency is called a periodogram.

plot(f,power)

xlabel('Frequency (Hz)') ylabel('Power')

title('{\bf Periodogram}')

The first half of the frequency range (from 0 to the Nyquist frequency fs/2) is sufficient to identify the component frequencies in the data, since the second half is just a reflection of the first half.

In many applications it is traditional to center the periodogram at 0. The fftshift function rearranges the output from fft with a circular shift to produce a 0-centered periodogram.

(8)

f0 = (-n/2:n/2-1)*(fs/n); % 0-centered frequency range

power0 = y0.*conj(y0)/n; % 0-centered power

plot(f0,power0)

xlabel('Frequency (Hz)') ylabel('Power')

title('{\bf 0-Centered Periodogram}')

The rearrangement makes use of the periodicity in the definition of the DFT.

Use the MATLAB angle and unwrap functions to create a phase plot of the DFT.

phase = unwrap(angle(y0)); plot(f0,phase*180/pi) xlabel('Frequency (Hz)') ylabel('Phase (Degrees)') grid on

Component frequencies are mostly hidden by the randomness in phase at adjacent values. The upward trend in the plot is due to the unwrap function, which in this case adds to the phase more often than it subtracts it.

The FFT in Multiple Dimensions Introduction

The MATLAB function fft2 computes two-dimensional DFTs using a fast Fourier transform algorithm. Y = fft2(X) is equivalent to Y = fft(fft(X).').', that is, to computing the dimensional DFT of each column X followed by the

one-dimensional DFT of each row of the result. The inverse transform of the two-one-dimensional DFT is computed by ifft2.

The MATLAB function fftn generalizes fft2 to N-dimensional arrays. Y = fftn(X) is equivalent to: Y = X;

for p = 1:length(size(X)) Y = fft(Y,[],p);

end

That is, to computing in place the one-dimensional DFT along each dimension of X. The inverse transform of the N-dimensional DFT is computed by ifftn.

Diffraction Patterns

The theory of optics predicts that the diffraction pattern produced by a plane wave incident on an optical mask with a small aperture is described, at a distance, by the Fourier transform of the mask.

Create a logical array describing an optical mask M with a circular aperture A of radius R.

n = 2^10; M = zeros(n);

(9)

I = 1:n; x = I-n/2; y = n/2-I;

[X,Y] = meshgrid(x,y); R = 10;

A = (X.^2 + Y.^2 <= R^2); M(A) = 1;

imagesc(M) axis image

title('{\bf Circular Aperture}')

Use fft2 to compute the two-dimensional DFT of the mask and fftshift to rearrange the output so that the zero-frequency component is at the center.

D1 = fft2(M); D2 = fftshift(D1); imagesc(abs(D2)) axis image

title('{\bf Diffraction Pattern}')

The logarithm helps to bring out details of the DFT in regions where the amplitude is small.

D3 = log2(D2); imagesc(abs(D3)) axis image

title('{\bf Enhanced Diffraction Pattern}')

Very small amplitudes are affected by numerical round-off. The lack of radial symmetry is an artifact of the rectangular arrangement of data.

Reference.

(10)

Experiment No. 1 Aim: To study sampling and waveform generation.

clc; clear all; t=0:0.01:10; anlg=sin(t); subplot(211); plot(t,anlg);

title('continuous time signal'); xlabel('time');

ylabel('amplitude'); n=0:0.1:10;

smp=sin(n); subplot(212); stem(n,smp);

title('sample signal'); xlabel('time');

ylabel('amplitude');

Experiment No. 2 Aim: To study the technique of quantization.

clc; clearall;

time=0:0.01:10; anlg=sin(time);

%sampling operation

dt=0:0.1:10; smp=sin(dt);

%quantization

partition=[-1,-0.5,0,0.5,1];

codebook=[-1,-0.75,-0.25,0.25,0.75,1];

[index,quants]=quantiz(smp,partition,codebook); subplot(3,1,1);

plot(time,anlg);

legend('analog signal'); xlabel('time');

ylabel('amplitude'); subplot(3,1,2); stem(dt,smp);

legend('sampled signal'); xlabel('time');

ylabel('amplitude'); subplot(3,1,3); stem(dt,quants);

legend('quantized signal'); xlabel('time');

ylabel('amplitude'); Result:

(11)

Experiment No. 3 Aim: To study the digital modulation scheme ASK.

clc; clear all;

F1=input('enter the frequency of carrier='); F2=input('enter the frequency of pulse='); A=3;%Amplitude

t=0:0.001:1;

x=A.*sin(2*pi*F1*t);%carrier sine wave

u=0.5*square(2*pi*F2*t)+0.5;%square wave message

v=x.*u; subplot(3,1,1); plot(t,x); xlabel('time'); ylabel('amplitude'); title('carrier'); grid on; subplot(3,1,2); plot(t,u); xlabel('time'); ylabel('amplitude'); title('square pulses'); grid on;

subplot(3,1,3); plot(t,v); xlabel('time'); ylabel('amplitude'); title('ASK Signal'); grid on;

enter the frequency of carrier=30 enter the frequency of pulse=6

Experiment No. 4 Aim: To study & compute DFT.

clc; clearall; x=[2 3 -1 4 5 7 3 -8]; N=length(x);

t=0:N-1; subplot(311); stem(t,x);

xlabel('time (s)'); ylabel('amplitude'); title('input sequence') subplot(312);

stem(t,abs(fft(x))); xlabel('frequency'); ylabel('|X(k)|');

title('magnitude response'); subplot(313);

stem(t,angle(fft(x))); xlabel('frequency'); ylabel('phase');

(12)

Experiment No. 5 Aim: To study the Delta Modulation.

clc; clearall; t=0:0.01:1; m=sin(2*pi*t); holdon

plot(t,m,'black'); d=2*pi/100; for n=1:length(t) if n==1

mq(n)=0; else

e(n)=m(n)-mq(n-1);

mq(n)=mq(n-1)+d*sign(e(n)); end

end

stairs(t,mq,'red');

legend('orignalsignal','stairs case approximated signal'); holdoff

Experiment No. 6 Aim: To study & implement FIR filter.

clc; clear all; close all;

n=59; %order of the filter %low pass filter

b1 = fir1(n,0.35); figure(1)

freqz(b1)

title('low pass filter')

%high pass filter

b2 = fir1(n,0.65,'high'); figure(2)

freqz(b2)

title('high pass filter')

%band pass filter

b3 = fir1(n,[0.35 0.65]); figure(3)

freqz(b3)

title('band pass filter')

%band stop flter

b4 = fir1(n,[0.35 0.65], 'stop'); figure(4)

freqz(b4)

(13)

0 5 10 15 20 25 30 35 40 45 50 -1 -0.5 0 0.5 1 Input Sequence

Time index n

A

m

pl

itu

de

0 5 10 15 20 25 30 35 40 45 50 -1

-0.5 0 0.5

1 Upsampled Sequence

Time index n

A

m

pl

itu

de

Experiment No. 7 Aim: To study & implement IIR filter.

clc; clearall;

closeall;

fp=input('Enter pass band frequency'); fs=input('Enter stop band frequency'); rp=input('Enter pass band ripple'); rs=input('Enter stop band attenuation'); f=input('Enter sampling frequency'); wp=2*fp/f; ws=2*fs/f; [n,wn]=buttord(wp,ws,rp,rs); [b,a]=butter(n,wn); figure(1) freqz(b,a)

title('Low Pass Filter'); [b1,a1]=butter(n,wn,'high'); figure(2)

freqz(b1,a1);

title('High Pass Filter');

Experiment No. 8

Aim:To study & implement DSP processor (Up-sampling).

clc; clearall; n=0:50;

x = sin(2*pi*0.12*n); y = zeros(1, 3*length(x)); y(1: 3: length(y)) = x; subplot(2,1,1)

stem(n,x);

title('Input Sequence'); xlabel('Time index n'); ylabel('Amplitude'); subplot(2,1,2)

stem(n,y(1:length(x))); title('Upsampled Sequence'); xlabel('Time index n'); ylabel('Amplitude');

References

Related documents

arm was employed followed by the mouse having to choose from among four test arms (see Fig. 12S, below), the FX mice were able to learn as effectively as the wt mice

Purpose: This study was carried out to investigate the effects of two doses (150 and 300 mg/kg) of ethanolic extract of strawberry leaves on antioxidant capacity of liver, kidney

Dashed lines represent mean values for traditional statistical measures of fire frequency (CMFI and MPFI), mean interval at which larger fires (&gt;20 % scarred) burned, and the

Als Untersuchungsjahre werden die Jahre 2012 und 2013 und die hierbei während der gesamten Jahre erfassten „Besonderen Vorkommnisse“ gewählt. Mit den markanten

In order to identify individual epigenetic changes involved in the transcriptional formation of clusters 2 and 3, significantly differentially methylated sites in these sam-

CUAJ ? July August 2013 ? Volume 7, Issues 7 8 ? 2013 Canadian Urological Association ORIGINAL RESEARCH E481 Cite as Can Urol Assoc J 2013;7(7 8) e481 5 http //dx doi org/10 5489/cuaj

The trend of the zooplankton population was noticed in all the stations of the river Kali, especially station 6 was found to have highest diversity of zooplanktons as it is a