# Documentation

### This is machine translation

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

# Signal Analyzer

Visualize and compare multiple signals and spectra

## Description

The Signal Analyzer app is an interactive tool for visualizing, 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

• Interact simultaneously with waveform, spectrum, persistence, and spectrogram representations of signals

• Visualize and compare multiple signals, spectra, persistence spectra, and spectrograms at once

The Signal Analyzer app provides a way to work with many signals of varying durations at the same time and in the same 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

Visualize an interference narrowband signal embedded within a broadband signal.

Generate a chirp sampled at 1 kHz for 500 seconds. The frequency of the chirp increases from 180 Hz to 220 Hz during the measurement.

```fs = 1000; t = (0:1/fs:500)'; x = chirp(t,180,t(end),220) + 0.15*randn(size(t)); ```

The signal also contains a 210 Hz sinusoid. The sinusoid has an amplitude of 0.05 and is present only for 1/6 of the total signal duration.

```idx = floor(length(x)/6); x(1:idx) = x(1:idx) + 0.05*cos(2*pi*t(1:idx)*210); ```

Save the signal as a MATLAB® timetable.

```S = timetable(seconds(t),x); ```

Open Signal Analyzer and drag the timetable from the Workspace browser to a display. Click the Spectrogram button to add a spectrogram view. On the Spectrogram tab, under Time Resolution, select Specify and enter a time resolution of 1 second. Set the Frequency Limits to 100 Hz and 290 Hz. Both signal components are visible.

Go back to the Display tab. Click the Time button to remove the time view and click the Spectrum button to add a power spectrum view. The frequency range continues to be from 100 Hz to 290 Hz. The weak sinusoid is obscured by the chirp.

Click the Spectrum ▼ button to change the `Spectrum` view to a `Persistence Spectrum` view. On the Persistence Spectrum tab, under Time Resolution, select Specify and enter a time resolution of 1 second. Specify zero overlap between adjoining segments. Set the Power Limits to –50 dB and 0 dB and the Density Limits to 0.1 and 4. Now both signal components are clearly visible.

On the Display tab, under Share, click Generate Script ▼ and select `Persistence Spectrum Script`. The script appears in the MATLAB Editor.

```% Compute persistence spectrum % Generated by MATLAB(R) 9.3 and Signal Processing Toolbox 7.5. % Generated on: 15-Jul-2017 18:43:37 % Parameters timeLimits = seconds([0 500]); % seconds frequencyLimits = [100 290]; % Hz timeResolution = 1; % seconds overlapPercent = 0; % Index into signal time region of interest S_x_ROI = S(:,'x'); S_x_ROI = S_x_ROI(timerange(timeLimits(1),timeLimits(2)),1); % Compute spectral estimate % Run the function call below without output arguments to plot the results [P,F,PWR] = pspectrum(S_x_ROI, ... 'persistence', ... 'FrequencyLimits',frequencyLimits, ... 'TimeResolution',timeResolution, ... 'OverlapPercent',overlapPercent); ```

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 Spectrogram 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 4.57 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.

## 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:

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.