This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Signal Analyzer

Visualize and compare multiple signals and spectra

Description

The Signal Analyzer app is an interactive tool for visualizing, preprocessing, measuring, analyzing, and comparing signals in the time domain, in the frequency domain, and in the time-frequency domain. Using the app, you can:

  • Easily access all the signals in the MATLAB® workspace

  • Smooth, filter, resample, duplicate, extract, and rename signals without leaving the app

  • Add and apply custom preprocessing functions

  • Visualize and compare multiple waveform, spectrum, persistence, spectrogram, and scalogram representations of signals simultaneously

The Signal Analyzer app provides a way to work with many signals of varying durations at the same time and in the same view.

For more information, see Using Signal Analyzer App.

You need a Wavelet Toolbox™ license to use the scalogram view.

Open the Signal Analyzer App

  • MATLAB Toolstrip: On the Apps tab, under Signal Processing and Communications, click the app icon.

  • MATLAB command prompt: Enter signalAnalyzer.

Examples

expand all

Implement a basic digital music synthesizer and use it to play a traditional song in a three-voice arrangement. Specify a sample rate of 2 kHz. Save the song as a MATLAB® timetable.

fs = 2e3;
t = 0:1/fs:0.3-1/fs;

l = [0 130.81 146.83 164.81 174.61 196.00 220 246.94];
m = [0 261.63 293.66 329.63 349.23 392.00 440 493.88];
h = [0 523.25 587.33 659.25 698.46 783.99 880 987.77];
note = @(f,g) [1 1 1]*sin(2*pi*[l(g) m(g) h(f)]'.*t);

mel = [3 2 1 2 3 3 3 0 2 2 2 0 3 5 5 0 3 2 1 2 3 3 3 3 2 2 3 2 1]+1;
acc = [3 0 5 0 3 0 3 3 2 0 2 2 3 0 5 5 3 0 5 0 3 3 3 0 2 2 3 0 1]+1;

song = [];
for kj = 1:length(mel)
    song = [song note(mel(kj),acc(kj)) zeros(1,0.01*fs)];
end
song = song'/(max(abs(song))+0.1);

% To hear, type sound(song,fs)

tune = timetable(seconds((0:length(song)-1)'/fs),song);

Open Signal Analyzer and drag the timetable from the Workspace browser to the Signal table. Click Display Grid ▼ to create a two-by-two grid of displays. Select the top two displays and the lower left display and click the Spectrum button to add a spectrum view. Select the lower right display, click Time-Frequency to add a spectrogram view, and click Time to remove the time view. Drag the song to all four displays. Select the lower right display, and in the Spectrogram tab, specify a time resolution of 0.31 second (310 ms) and 0% overlap between adjoining segments. Set the Power Limits to dB and dB.

On the Analyzer tab, click Duplicate three times to create three copies of the song. Rename the copies as high, medium, and low by double-clicking the Name column in the Signal table. Move the copies to the top two and lower left displays.

Preprocess the duplicate signals using filters.

  1. Select the high signal by clicking its name in the Signal table. On the Analyzer tab, click Highpass. On the Highpass tab that appears, enter a passband frequency of 450 Hz and increase the steepness to 0.95. Click Highpass.

  2. Select the medium signal by clicking its name in the Signal table. On the Analyzer tab, click Preprocessing ▼ and select Bandpass. On the Bandpass tab that appears, enter 230 Hz and 450 Hz as the lower and upper passband frequencies, respectively. Increase the steepness to 0.95. Click Bandpass.

  3. Select the low signal by clicking its name in the Signal table. On the Analyzer tab, click Lowpass. On the Lowpass tab that appears, enter a passband frequency of 230 Hz and increase the steepness to 0.95. Click Lowpass.

On each of the three displays containing filtered signals:

  1. Remove the original signal by clearing the check box next to its name.

  2. On the Display tab, click Time-Frequency to add a spectrogram view and click Time to remove the time view.

  3. On the Spectrogram tab, specify a time resolution of 0.31 second and 0% overlap between adjoining segments. Set the Power Limits to dB and dB.

Select the three filtered signals by clicking their Name column in the Signal table. On the Analyzer tab, click Export and save the signals to a MAT-file called music.mat. In MATLAB, load the file to the workspace. Plot the spectra of the three signals.

load music

pspectrum(low)
hold on
pspectrum(medium)
pspectrum(high)
hold off

% To hear the different voices, type 
% sound(low.Var1,fs), pause(5), sound(medium.Var1,fs), pause(5), sound(high.Var1,fs)

Load a file that contains audio data from a Pacific blue whale, sampled at 4 kHz. The file is from the library of animal vocalizations maintained by the Cornell University Bioacoustics Research Program. The time scale in the data is compressed by a factor of 10 to raise the pitch and make the calls more audible. Convert the signal to a MATLAB® timetable.

whaleFile = fullfile(matlabroot,'examples','matlab','bluewhale.au');
[w,fs] = audioread(whaleFile);

whale = timetable(seconds((0:length(w)-1)'/fs),w);

% To hear, type soundsc(w,fs)

Open Signal Analyzer and drag the timetable to a display. Four features stand out from the noise. The first is known as a trill, and the other three are known as moans.

On the Display tab, click Spectrum to open a spectrum view and click Panner to activate the panner. Use the panner to create a zoom window with a width of about 2 seconds. Drag the zoom window so that it is centered on the trill. The spectrum shows a noticeable peak at around 900 Hz.

Extract the three moans to compare their spectra:

  1. Center the panner zoom window on the first moan. The spectrum has eight clearly defined peaks, located very close to multiples of 170 Hz. Click Extract Signals ▼ and select Between Time Limits.

  2. Click Panner to hide the panner. Press the space bar to see the full signal. Click Zoom in X and zoom in on a 2-second interval of the time view centered on the second moan. The spectrum again has peaks at multiples of 170 Hz. Click Extract Signals ▼ and select Between Time Limits.

  3. Press the space bar to see the full signal. Click Data Cursors ▼ and select Two. Place the time-domain cursors in a 2-second interval around the third moan. Again, there are peaks at multiples of 170 Hz. Click Extract Signals ▼ and select Between Time Cursors.

Remove the original signal from the display by clearing the check box next to its name in the Signal table. Display the three regions of interest you just extracted. Their spectra lie approximately on top of each other. Move the frequency-domain cursors to the locations of the first and third spectral peaks. Asterisks in cursor labels indicate interpolated signal values.

Load a datafile containing an echolocation pulse emitted by a big brown bat (Eptesicus fuscus) and measured with a sampling interval of 7 microseconds. Create a MATLAB® timetable using the signal and the time information.

load batsignal

t = (0:length(batsignal)-1)*DT;
sg = timetable(seconds(t)',batsignal);

Open Signal Analyzer and drag the timetable from the Workspace browser to the Signal table. Click Display Grid ▼ to create two side-by-side displays. Select each display and click the Time-Frequency button to add a spectrogram view.

Drag the timetable to both displays.

Select the Spectrogram tab. On the display at right, check Reassign. For each display:

  • Set the time resolution to 280 microseconds and specify 85% overlap between adjoining segments.

  • Use the Leakage slider to increase the leakage until the RBW is about 4.5 kHz.

  • Set the power limits to –45 dB and –20 dB.

The reassigned spectrogram clearly shows three time-frequency ridges. To track the ridges, select the display at right. On the Display tab, click Generate Script and select Spectrogram Script. The script appears in the Editor.

% Compute spectrogram

% Generated by MATLAB(R) 9.3 and Signal Processing Toolbox 7.5.
% Generated on: 13-Jul-2017 19:32:31

% Parameters
timeLimits = seconds([3.805177e-06 0.002796805]); % seconds
frequencyLimits = [0 71428.57]; % Hz
leakage = 0.9;
timeResolution = 0.00028; % seconds
overlapPercent = 85;
reassignFlag = true;

% Index into signal time region of interest
sg_batsignal_ROI = sg(:,'batsignal');
sg_batsignal_ROI = sg_batsignal_ROI(timerange(timeLimits(1),timeLimits(2)),1);

% Compute spectral estimate
% Run the function call below without output arguments to plot the results
[P,F,T] = pspectrum(sg_batsignal_ROI, ...
    'spectrogram', ...
    'FrequencyLimits',frequencyLimits, ...
    'Leakage',leakage, ...
    'TimeResolution',timeResolution, ...
    'OverlapPercent',overlapPercent, ...
    'Reassign',reassignFlag);

Run the script. Plot the reassigned spectrogram.

mesh(seconds(T),F,P)
xlabel('Time')
ylabel('Frequency')
axis tight
view(2)
colormap pink

Use the tfridge function to track the ridges.

[fridge,~,lridge] = tfridge(P,F,0.01,'NumRidges',3,'NumFrequencyBins',10);

hold on
plot3(seconds(T),fridge,P(lridge),':','linewidth',3)
hold off

Thanks to Curtis Condon, Ken White, and Al Feng of the Beckman Center at the University of Illinois for the bat data and permission to use it in this example.

Sensors can return clipped readings if the data are larger than a given saturation point. To reconstruct the readings, you can fit a polynomial through the points adjacent to the saturated intervals. Write a function that performs the reconstruction and integrate it into Signal Analyzer.

Generate a three-channel signal sampled at 1 kHz for 14 seconds. The signal has several peaks of varying sizes and shapes. A sensor that reads the signal saturates at 0.1 V.

fs = 1000;
t = 0:1/fs:14-1/fs;

sig = [chirp(t-1,0.1,17,2,'quadratic',1).*sin(2*pi*t/5);
    chirp(t-2,2,2,2.1,'quadratic',100).*exp(-(t-6.5).^2/20).*sin(2*pi*t*2);
    0.85*besselj(0,5*(sin(2*pi*(t+1.5).^2/20).^2)).*sin(2*pi*t/9)]';

sigsat = sig;
stv = 0.1;
sigsat(sigsat >= stv) = stv;

Open Signal Analyzer and drag the original signal and the saturated signal to the Signal table. Drag each original and saturated channel to its own display.

Write a function that uses a polynomial to reconstruct the signal peaks:

  • The first input argument, x, is the input signal. This argument must be a vector and is treated as a single channel.

  • The second input argument, tIn, is a vector of time values. The vector must have the same length as the signal. If the input signal has no time information, the function reads this argument as an empty array.

  • Use varargin to specify additional input arguments. If you do not have additional input arguments, you can omit varargin. Enter the additional arguments as an ordered comma-separated list in the Preprocess tab.

  • The first output argument, y, is the preprocessed signal.

  • The second output argument, tOut, is a vector of output time values. If the input signal has no time information, tOut is returned as an empty array.

  • To implement your algorithm, you can use any MATLAB® or Signal Processing Toolbox™ function.

function [y,tOut] = declip(x,tIn,varargin)
% Declip saturated signal by fitting a polynomial

    % Initialize the output signal

    y = x;

    % For signals with no time information, use sample numbers as abscissas
    
    if isempty(tIn)
        tOut = [];
        t = (1:length(x))';
    else
        t = tIn;
        tOut = t;
    end
    
    % Specify the degree of the polynomial as an optional input argument
    % and provide a default value of 4
    
    if nargin<3
        ndx = 4;
    else
        ndx = varargin{1};
    end

    % To implement your algorithm, you can use any MATLAB or Signal
    % Processing Toolbox function
    
    % Find the intervals where the signal is saturated and generate an 
    % array containing the interval endpoints
    idx = find(x==max(x)); 
    fir = [true;diff(idx)~=1];
    ide = [idx(fir) idx(fir([2:end 1]))];
    % For each interval, fit a polynomial of degree ndx over the ndx+1 points
    % before the interval and the ndx+1 points after the interval
    for k = 1:size(ide,1)
        bef = ide(k,1); aft = ide(k,2);
        intv = [bef-1+(-ndx:0) aft+1+(0:ndx)];
        [pp,~,mu] = polyfit(t(intv),x(intv),ndx);
        y(bef:aft) = polyval(pp,t(bef:aft),[],mu);
    end

end

Add the function to Signal Analyzer as a custom preprocessing function. On the Analyzer tab, click Preprocessing ▼ and select Add Custom Function. Input the function name and description. Paste the text of your function in the editor window that appears. Save the file. The function appears in the preprocessing gallery.

Demonstrate that the function you created reconstructs the saturated regions.

  1. Select the first channel of the saturated signal in the Signal table.

  2. On the Analyzer tab, click Preprocessing ▼ and select declip.

  3. On the Preprocessing tab that appears, click Preprocess.

Verify that the preprocessing function works when the signals have time information.

  1. Select all signals in the Signal table.

  2. On the Analyzer tab, click Time Values, select Sample Rate and Start Time, and specify fs as the sample rate.

  3. The signal in the top panel, including the reconstructed regions, has time information.

Check that the function works when you specify optional inputs.

  1. Select the second and third channels of the saturated signal in the Signal table.

  2. On the Preprocessing tab, enter 8 in the Arguments field and click Preprocess. The preprocessing function uses a polynomial of degree 8 to reconstruct the saturated regions.

Related Examples

Programmatic Use

expand all

signalAnalyzer opens the Signal Analyzer app.

signalAnalyzer(sig) opens the Signal Analyzer app and imports and plots the signal sig. If the app is already open, then it plots sig in the current display. If sig is already plotted but has changed, then the function call updates the plot.

sig can be a variable in the workspace or a MATLAB expression. sig can be:

  • A vector or a matrix with independent signals in each column.

  • A timetable with time values specified as durations.

  • A timeseries object.

See Data Types Supported by Signal Analyzer for more details.

By default, the app plots the signal as a function of sample index. If you provide time information, or if the signal has inherent time information, then the app plots the signal as a function of time.

signalAnalyzer(sig1,...,sigN) imports N signal vectors or matrices and plots them in the current display. The app does not support importing signals with inherent time information and signals without inherent time information in the same function call.

signalAnalyzer(___,'SampleRate',fs) specifies a sample rate, fs, as a positive scalar expressed in Hz. The app uses the sample rate to plot one or more signals against time, assuming a start time of zero. You can specify a sample rate for signals with no inherent time information.

signalAnalyzer(___,'SampleTime',ts) specifies a sample time, ts, as a positive scalar expressed in seconds. The app uses the sample time to plot one or more signals against time, assuming a start time of zero. You can specify a sample time for signals with no inherent time information.

signalAnalyzer(___,'StartTime',st) specifies a signal start time, st, as a scalar expressed in seconds. If you do not specify a sample rate or sample time, then the app assumes a sample rate of 1 Hz. You can specify a start time for signals with no inherent time information.

signalAnalyzer(___,'TimeValues',tv) specifies a vector, tv, with time values corresponding to the data points. tv can be a real numeric vector with values expressed in seconds. tv can also be a duration array. The values in tv must be unique and cannot be NaN, but they need not be uniformly spaced. All input signals must have the same length as tv. You can specify a vector of time values for signals with no inherent time information.

Filtering and scalogram view do not support nonuniformly sampled signals.

Introduced in R2016a