Skip to main content
Engineering LibreTexts

6.3: Discrete data conversion and filtering

  • Page ID
    121979
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\dsum}{\displaystyle\sum\limits} \)

    \( \newcommand{\dint}{\displaystyle\int\limits} \)

    \( \newcommand{\dlim}{\displaystyle\lim\limits} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \(\newcommand{\longvect}{\overrightarrow}\)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)
    1. Usefulness with discrete data
      1. Also possible to use complex exponential and Euler formula \[ \mathbf{e}^{\pm i\theta} =\cos\theta \pm i\sin\theta \] \[\cos \theta = \frac{[\mathbf{e}^{i\theta}+\mathbf{e}^{-i\theta}]}{2} \] \[ \sin \theta = \frac{[\mathbf{e}^{i\theta}-\mathbf{e}^{-i\theta}]}{2}\]
      2. Complex formulation simplifies multiplication of real and imaginary components through complex conjugates
      3. When the integration is expanded beyond single period to \(\infty\), then conversion of data from time domain to frequency domain possible \[Y(\omega) = \int_{-\infty}^{+\infty}y(t)\mathbf{e}^{-i\omega t}dt \]
        1. Exercise \(\PageIndex{1}\)

          What does plot of simple periodic appear in frequency domain?

          Answer

          Show single stem plot.

        2. Exercise \(\PageIndex{2}\)

          What happens if multiple frequencies are present?

          Answer

          Image of multiple stems of multi-frequency image.

      4. Tool for discrete data is fast Fourier transform (FFT)
        1. developed in 1940s when computation was laborious
        2. divides data in half and sums over \(N/2\) steps instead of \(N^{2}\) process
        3. Simple fft call in Matlab
    2. Using the FFT
      1. Input is the real data array collected of length \(N\) points
      2. Output is equal length complex (real + imaginary) array
        1. similar to \(A_{n}\) and \(B_{n}\) of Fourier coefficients when \(y(t)\) was known
        2. BUT exists at ALL frequency points, not just harmonics of integer frequency value \(n\omega\)
      3. Displaying the data on plot
        1. Horizontal axis is now cyclic frequency (\(f\))
        2. Lowest frequency: at \(f_{min} = 0 \) the peak represents mean value
        3. Largest frequency is resolution of smallest time step \(f_{max} =1/ \delta t\)
        4. Frequency increment is total time of collection \[ df = \frac{1}{N \delta t} = \frac{1}{t_{end}-t_{0}}\]
        5. Which part to plot, real or imaginary?
          • Can use both through absolute value: \[z = |x + yi| = \sqrt{x^{2} + y^{2}} \] \[C = |Y(\omega)| = \sqrt{\Re(Y(\omega))^{2} + \Im(Y(\omega))^{2}} \]
        6. Since no data are known between the \(df\), acts as a comb function (stem plot in Matlab) rather than continuous curve
        7. Note that the FFT causes a folding symmetry about the \(N/2\) point
        8. Hence, magnitude of stem is half of amplitude at that particular frequency
      4. Introduces potential for amplitude ambiguity
        1. When full period is collected, single peak appears AT particular frequency
        2. Portions of periods cause spread of peak to adjacent frequencies
          Exercise \(\PageIndex{3}\)

          Figures need to be incorporated through example

          Answer

          Add texts here. Do not delete this text first.

        3. Acts similarly to the statistics functions from Section 2.1 where time range affected value
        4. How to reduce ambiguity? Increase total time to make ambiguity a smaller percentage of overall data collected (i.e., have MORE total periods).
        5. What about signals with discontinuities (i.e., \(\infty\) frequencies)? There will always be spreading.
    3. Filtering in frequency domain
      1. With raw data in temporal or spatial domain, the Fourier Transform converts to a frequency
      2. Recall types of filtering from MEE 321 (vibrations) and/or MEE 322 (dynamic systems and control)
        1. Describe a band-pass filter in terms of low-pass versus high-pass conditions
        2. Analogy of window of visibility into a room
      3. Using the FFT data, user may select either:
        1. particular frequencies that stand out (include side shoulders for amplitude ambiguity described from Section 6.2.E)
        2. amplitudes above some noise level
      4. Practical considerations that must be implemented:
        1. Must utilize FFT symmetry though
          1. every \(f_{r}\) retained, must also include \(f_{max}-f_{r}\)
          2. other frequency domain values made zero in both real and imaginary domains
        2. Use the inverse fast Fourier transform (ifft) to return to time domain
          • Output will retain complex number elements, but only the real portion has value (imaginary should be \(\rightarrow 0\))
        3. Plotting noisy versus filtered data in Matlab examples 
          Matlab script

          clear all; close all;
          Input_freq = 78; % Hz 
          num_cycs = 5;
          mth_order = 10;
          omega = Input_freq*2*pi;
          T = 1/Input_freq;
          final_time = num_cycs*T+0*T;
          dt = final_time/(2^mth_order);
          t = dt:dt:final_time;
          N = length(t);
          V_org = (sin(omega*t));
          V = V_org+1.5*randn(1,N);
          plot(t,[V;V_org],'.'); 
          pause; % all of the previous stuff is just building data; 
          % Yours will come from the digital data acquisition

          vbar = mean(V); % simple statistics
          sigma_vbar = std(V);

          X = 1/N*fft(V); % Converting to frequency domain
          df = 1/final_time; % step sizes for frequency plotting
          f = df*(0:N-1); % creating the frequency array
          Xvals = abs(X); % Combining the real and imaginary components
          figure(2);
          stem(f,Xvals); % Plotting in frequency domain
          hold on;

          low_end = 0.4*Input_freq; % Defining range of frequencies to be kept
          high_end = 1.8*Input_freq;
          I = find(f<low_end | (f >high_end & f < df*N/2) | ...
              (f>(max(f)-low_end)& f>=df*N/2) | (f>=df*N/2 & f<(max(f)-high_end)));
          % This selection of the frequencies is critical. You want values in the
          % window both for range f<N/2 and the range f>N/2;
          stem(f([I]),Xvals([I]),'g');
          xlabel('Frequency (Hz)');
          pause;
          xlim([0,high_end*2.5]);
          pause;

          filtered_X = X;
          filtered_X(I) = 0+0i;
          filtered_V = real(N*ifft(filtered_X)); % inverting back to the time domain
          figure(1); hold on;
          plot(t,filtered_V,'ro'); % plotting the filtered data
          ylim([-2,2]);


    6.3: Discrete data conversion and filtering is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?