Visualize and compare multiple signals and spectra
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, duplicate, extract, and rename signals without having to leave the app
Visualize and compare multiple waveform, spectrum, persistence, spectrogram, and scalogram representations of signals 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.
For more information, see Using Signal Analyzer App.
You need a Wavelet Toolbox™ license to use the scalogram view.
MATLAB Toolstrip: On the Apps tab, under Signal Processing and Communications, click the app icon.
MATLAB command prompt: Enter
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
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.
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.
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.
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:
Remove the original signal by clearing the check box next to its name.
On the Display tab, click Time-Frequency to add a spectrogram view and click Time to remove the time view.
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:
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.
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.
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
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.
signalAnalyzer opens the Signal Analyzer
signalAnalyzer( 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
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:
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.
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.
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
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.
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
specifies a vector,
tv, with time values corresponding to the
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
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.