Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Signal Visualization and Measurements in MATLAB

This example shows how to visualize and measure signals in the time and frequency domain in MATLAB using a time scope and spectrum analyzer.

Signal Visualization in Time and Frequency Domains

Create a sine wave with a frequency of 100 Hz sampled at 1000 Hz. Generate five seconds of the 100 Hz sine wave with additive white noise in one-second intervals. Send the signal to a time scope and spectrum analyzer for display and measurement.

SampPerFrame = 1000;
Fs = 1000;
SW = dsp.SineWave('Frequency', 100, ...
  'SampleRate', Fs, 'SamplesPerFrame', SampPerFrame);
TS = dsp.TimeScope('SampleRate', Fs, 'TimeSpan', 0.1, ...
    'YLimits', [-2, 2], 'ShowGrid', true);
SA = dsp.SpectrumAnalyzer('SampleRate', Fs);
tic;
while toc < 5
  sigData = SW() + 0.05*randn(SampPerFrame,1);
  TS(sigData);
  SA(sigData);
end

Time-Domain Measurements

Using the time scope, you can make a number of signal measurements.

The following measurements are available:

  • Cursor Measurements - puts screen cursors on all scope displays.

  • Signal Statistics - displays maximum, minimum, peak-to-peak difference, mean, median, RMS values of a selected signal, and the times at which the maximum and minimum occur.

  • Bilevel Measurements - displays information about a selected signal's transitions, overshoots or undershoots, and cycles.

  • Peak Finder - displays maxima and the times at which they occur.

You can enable and disable these measurements from the time scope toolbar or from the Tools > Measurements menu.

To illustrate the use of measurements in the time scope, simulate an ECG signal. Use the ecg function to generate 2700 samples of the signal. Use a Savitzky-Golay filter to smooth the signal and periodically extend the data to obtain approximately 11 periods.

x = 3.5*ecg(2700).';
y = repmat(sgolayfilt(x,0,21),[1 13]);
sigData = y((1:30000) + round(2700*rand(1))).';

Display the signal in the time scope and use the Peak Finder, Cursor and Signal Statistics measurements. Assume a sample rate of 4 kHz.

TS_ECG = dsp.TimeScope('SampleRate', 4000, ...
    'TimeSpanSource', 'Auto', 'ShowGrid', true);
TS_ECG(sigData);
TS_ECG.YLimits = [-4, 4];

Peak Measurements

Enable Peak Measurements by clicking the corresponding toolbar icon or by clicking the Tools > Measurements > Peak Finder menu item. Click Settings in the Peak Finder panel to expand the Settings pane. Enter 10 for Max Num of Peaks and press Enter. The time scope displays in the Peaks pane a list of 10 peak amplitude values and the times at which they occur.

There is a constant time difference of 0.675 seconds between each heartbeat. Therefore, the heart rate of the ECG signal is given by the following equation:

Cursor Measurements

Enable Cursor Measurements by clicking the corresponding toolbar icon or by clicking the Tools > Measurements > Cursor Measurements menu item. The Cursor Measurements panel opens and displays two cursors in the time scope. You can drag the cursors and use them to measure the time between events in the waveform. In the following figure, cursors are used to measure the time interval between peaks in the ECG waveform. The measurement in the Cursor Measurements panel demonstrates that the time interval between the two peaks is 0.675 seconds corresponding to a heart rate of 1.482 Hz or 88.9 beats/min.

Signal Statistics and Bilevel Measurements

You can also select Signal Statistics and Bilevel Measurements from the Tools > Measurements menu. Signal Statistics can be used to determine the signal's minimum and maximum values as well as other metrics like the peak-to-peak, mean, median, and RMS values. Bilevel Measurements can be used to determine information about rising and falling transitions, transition aberrations, overshoot and undershoot information, pulse width, and duty cycle. To read more about these measurements, see the Time Scope Measurements tutorial example.

Frequency-Domain Measurements

This section explains how to make frequency domain measurements with the spectrum analyzer.

The spectrum analyzer provides the following measurements:

  • Cursor Measurements - places cursors on the spectrum display.

  • Peak Finder - displays maxima and the frequencies at which they occur.

  • Channel Measurements - displays occupied bandwidth and ACPR channel measurements.

  • Distortion Measurements - displays harmonic and intermodulation distortion measurements.

  • CCDF Measurements - displays complimentary cumulative distribution function measurements.

You can enable and disable these measurements from the spectrum analyzer toolbar or from the Tools > Measurements menu.

Distortion Measurements

To illustrate the use of measurements with the spectrum analyzer, create a 2.5 kHz sine wave sampled at 48 kHz with additive white Gaussian noise. Evaluate a high-order polynomial (9th degree) at each signal value to model non-linear distortion. Display the signal in a spectrum analyzer.

Fs = 48e3;
SW = dsp.SineWave('Frequency', 2500, ...
  'SampleRate', Fs, 'SamplesPerFrame', SampPerFrame);
SA_Distortion = dsp.SpectrumAnalyzer('SampleRate', Fs, ...
    'PlotAsTwoSidedSpectrum', false);
y = [1e-6 1e-9 1e-5 1e-9 1e-6 5e-8 0.5e-3 1e-6 1 3e-3];
tic;
while toc < 5
  x = SW() + 1e-8*randn(SampPerFrame,1);
  sigData = polyval(y, x);
  SA_Distortion(sigData);
end
clear SA_Distortion;

Enable the harmonic distortion measurements by clicking the corresponding icon in the toolbar or by clicking the Tools > Measurements > Distortion Measurements menu item. In the Distortion Measurements, change the value for Num. Harmonics to 9 and check the Label Harmonics checkbox. In the panel, you see the value of the fundamental close to 2500 Hz and 8 harmonics as well as their SNR, SINAD, THD and SFDR values, which are referenced with respect to the fundamental output power.

Peak Finder

You can track time-varying spectral components by using the Peak Finder measurement dialog. You can show and optionally label up to 100 peaks. You can invoke the Peak Finder dialog from the Tools > Measurements > Peak Finder menu item, or by clicking the corresponding icon in the toolbar.

To illustrate the use of Peak Finder, create a signal consisting of the sum of three sine waves with frequencies of 5, 15, and 25 kHz and amplitudes of 1, 0.1, and 0.01 respectively. The data is sampled at 100 kHz. Add white Gaussian noise to the sum of sine waves and display the one-sided power spectrum in the spectrum analyzer.

Fs = 100e3;
SW1 = dsp.SineWave(1e0,   5e3, 0, 'SampleRate', Fs, 'SamplesPerFrame', SampPerFrame);
SW2 = dsp.SineWave(1e-1, 15e3, 0, 'SampleRate', Fs, 'SamplesPerFrame', SampPerFrame);
SW3 = dsp.SineWave(1e-2, 25e3, 0, 'SampleRate', Fs, 'SamplesPerFrame', SampPerFrame);
SA_Peak = dsp.SpectrumAnalyzer('SampleRate', Fs, 'PlotAsTwoSidedSpectrum', false);
tic;
while toc < 5
    sigData = SW1() + SW2() + SW3() + 1e-4*randn(SampPerFrame,1);
    SA_Peak(sigData);
end
clear SA_Peak;

Enable the Peak Finder to label the three sine wave frequencies. The frequency values and powers in dBm are displayed in the Peak Finder panel. You can increase or decrease the maximum number of peaks, specify a minimum peak distance, and change other settings from the Settings pane in the Peak Finder Measurement panel.

To learn more about the use of measurements with the spectrum analyzer, see the Spectrum Analyzer Measurements example.

Was this topic helpful?