Lesson 30-Comprehensive Project Building a Complete Intelligent Signal Recognition System

Introduction: Bringing It All Together

You’ve made it to the final article of this comprehensive MATLAB course. Congratulations! Over the past 29 articles, you’ve learned:

  • MATLAB fundamentals (matrices, programming, visualization)
  • Domain-specific skills (signal processing, image processing, machine learning)
  • Advanced topics (Simulink, code generation, big data, communications)

Now it’s time to bring everything together in a capstone project that demonstrates your mastery of MATLAB.

The Project: Intelligent Signal Recognition System

In this project, we’re going to build a complete system that:

  1. Generates synthetic signals of different types (sine, chirp, square, AM, FM)
  2. Extracts features from these signals (time-domain and frequency-domain)
  3. Trains a machine learning classifier to recognize the signal type
  4. Evaluates performance (confusion matrix, precision/recall)
  5. Builds a Simulink model that uses the trained classifier
  6. Deploys as a standalone app with App Designer
  7. Generates C code for embedded deployment (optional)

This is a real-world project. Signal recognition is used in:

  • Cognitive radio: Automatically identifying and avoiding interference
  • Radar systems: Classifying targets based on their radar signatures
  • Biomedical engineering: Identifying arrhythmias from ECG signals
  • Vibration analysis: Detecting machine faults from vibration signatures

By the time you finish this article, you’ll have built a complete, end-to-end signal recognition system that you can actually use.

Step 1: Signal Generation — Creating a Dataset of Synthetic Signals

The first step in any machine learning project is data. We need a dataset of signals with known labels (so we can train a supervised classifier).

We’ll generate 5 types of signals:

  1. Sine wave: s(t)=Asin⁡(2πf0t)s(t) = A \sin(2\pi f_0 t)
  2. Chirp: s(t)=Asin⁡(2π(f0+kt)t)s(t) = A \sin(2\pi (f_0 + kt)t)
  3. Square wave: s(t)=A⋅sgn(sin⁡(2πf0t))s(t) = A \cdot \text{sgn}(\sin(2\pi f_0 t))
  4. AM (Amplitude Modulation): s(t)=(A+m(t))sin⁡(2πfct)s(t) = (A + m(t)) \sin(2\pi f_c t)
  5. FM (Frequency Modulation): s(t)=Asin⁡(2πfct+β∫m(τ)dτ)s(t) = A \sin(2\pi f_c t + \beta \int m(\tau) d\tau)

MATLAB Code: Signal Generation

%% Step 1: Generate dataset of synthetic signals
% This script generates 1000 examples of each signal type (5000 total)
% Each signal is 1 second long, sampled at 1000 Hz

fprintf('=== Step 1: Signal Generation ===\n');

%% Parameters
fs = 1000;          % Sampling frequency (Hz)
T = 1;              % Signal duration (seconds)
t = 0:1/fs:T-1/fs;  % Time vector
N = length(t);       % Number of samples per signal
numPerType = 1000;  % Number of examples per signal type
numTypes = 5;       % Number of signal types

% Preallocate cell arrays to store signals
signals = cell(numPerType * numTypes, 1);
labels = strings(numPerType * numTypes, 1);

fprintf('Generating %d signals of each type (%d total)...\n', ...
        numPerType, numPerType * numTypes);

%% Generate sine waves
fprintf('  Generating sine waves...\n');
for i = 1:numPerType
    % Random parameters
    A = 0.5 + 0.5 * rand();   % Amplitude: 0.5 to 1.0
    f0 = 10 + 40 * rand();    % Frequency: 10 to 50 Hz
    
    % Generate signal
    x = A * sin(2*pi*f0*t);
    
    % Add noise
    x = x + 0.1 * randn(size(x));
    
    % Store
    signals{(i-1)*numTypes + 1} = x;
    labels((i-1)*numTypes + 1) = "sine";
end

%% Generate chirp signals
fprintf('  Generating chirp signals...\n');
for i = 1:numPerType
    % Random parameters
    A = 0.5 + 0.5 * rand();   % Amplitude
    f0 = 10 + 20 * rand();    % Start frequency
    f1 = f0 + 30 * rand();    % End frequency
    
    % Generate chirp
    x = A * chirp(t, f0, T, f1);
    
    % Add noise
    x = x + 0.1 * randn(size(x));
    
    % Store
    signals{(i-1)*numTypes + 2} = x;
    labels((i-1)*numTypes + 2) = "chirp";
end

%% Generate square waves
fprintf('  Generating square waves...\n');
for i = 1:numPerType
    % Random parameters
    A = 0.5 + 0.5 * rand();   % Amplitude
    f0 = 5 + 25 * rand();     % Frequency: 5 to 30 Hz
    
    % Generate square wave
    x = A * square(2*pi*f0*t);
    
    % Add noise
    x = x + 0.1 * randn(size(x));
    
    % Store
    signals{(i-1)*numTypes + 3} = x;
    labels((i-1)*numTypes + 3) = "square";
end

%% Generate AM signals
fprintf('  Generating AM signals...\n');
for i = 1:numPerType
    % Random parameters
    A = 0.5 + 0.5 * rand();   % Carrier amplitude
    fc = 100 + 200 * rand();  % Carrier frequency: 100 to 300 Hz
    fm = 5 + 20 * rand();     % Message frequency: 5 to 25 Hz
    mu = 0.3 + 0.7 * rand(); % Modulation index: 0.3 to 1.0
    
    % Message signal
    m = sin(2*pi*fm*t);
    
    % AM signal
    x = A * (1 + mu*m) .* sin(2*pi*fc*t);
    
    % Add noise
    x = x + 0.1 * randn(size(x));
    
    % Store
    signals{(i-1)*numTypes + 4} = x;
    labels((i-1)*numTypes + 4) = "AM";
end

%% Generate FM signals
fprintf('  Generating FM signals...\n');
for i = 1:numPerType
    % Random parameters
    A = 0.5 + 0.5 * rand();   % Carrier amplitude
    fc = 100 + 200 * rand();  % Carrier frequency: 100 to 300 Hz
    fm = 5 + 20 * rand();     % Message frequency: 5 to 25 Hz
    beta = 0.5 + 4.5 * rand();% Modulation index: 0.5 to 5.0
    
    % Message signal
    m = sin(2*pi*fm*t);
    
    % FM signal (integrate message)
    x = A * cos(2*pi*fc*t + beta*cumsum(m)/fs);
    
    % Add noise
    x = x + 0.1 * randn(size(x));
    
    % Store
    signals{(i-1)*numTypes + 5} = x;
    labels((i-1)*numTypes + 5) = "FM";
end

fprintf('Signal generation complete!\n');
fprintf('  Total signals: %d\n', length(signals));
fprintf('  Signal length: %d samples (%.2f seconds)\n', N, T);

%% Visualize example signals of each type
fprintf('\nVisualizing example signals...\n');

figure('Name', 'Example Signals of Each Type', 'Color', 'w', ...
        'Position', [100, 100, 1200, 800]);

signalTypes = ["sine", "chirp", "square", "AM", "FM"];
for i = 1:numTypes
    % Find first example of this type
    idx = find(labels == signalTypes(i), 1);
    x = signals{idx};
    
    subplot(3, 2, i);
    plot(t(1:200), x(1:200), 'b-', 'LineWidth', 1.5);  % Plot first 200 samples
    xlabel('Time (s)');
    ylabel('Amplitude');
    title(sprintf('%s Wave (example)', string(signalTypes(i))));
    grid on;
end

% Plot all signals (small)
subplot(3, 2, 6);
hold on;
colors = {'b', 'r', 'g', 'm', 'c'};
for i = 1:numTypes
    idx = find(labels == signalTypes(i), 1);
    x = signals{idx};
    plot(t(1:200), x(1:200), colors{i}, 'LineWidth', 1.5, ...
         'DisplayName', string(signalTypes(i)));
end
xlabel('Time (s)');
ylabel('Amplitude');
title('All Signal Types (overlayn)');
legend('Location', 'best');
grid on;
hold off;

fprintf('Signal generation step complete.\n');

Understanding the Signal Generation Code

Let’s break down what we just did:

  1. Parameter randomization: Each signal type has parameters (amplitude, frequency, etc.) that are randomly varied. This creates a diverse dataset that will help our classifier generalize.
  2. Noise addition: We add Gaussian noise to each signal. This makes the classification task more realistic (real-world signals are always noisy).
  3. Label creation: We create a labels array that stores the signal type for each example. This is the ground truth that our classifier will learn to predict.
  4. Visualization: We plot example signals to verify that our generation code is working correctly.

Membership Required

You must be a member to access this content.

View Membership Levels

Already a member? Log in here
Share your love