Skip to content

matlab/matlab-agentic-toolkit / skills-catalog/matlab-software-development/matlab-modernize-code

matlab-modernize-code

Verified

Modernize removed or discouraged MATLAB functions and patterns. Use when the check_matlab_code MCP tool reports that a function "is not recommended", "will be removed in a future release", or "has been removed" — at any severity (info, warning, or error) — when migrating legacy code, or when replacing removed or discouraged APIs with current equivalents. Also applies to discouraged patterns Code Analyzer does not flag (containers.Map, bsxfun, str2num, eval, clear all) and to removed or discouraged functions such as trainNetwork, csvread, xlsread, datenum, guide, svmtrain, ltln2val, webmap.

references/signal-processing-guidance.md

View on GitHub
# Signal Processing Modernization

## Quick Reference: Function Mappings

| Topic | Recommendation | Since | Status |
|---|---|---|---|
| `pkurtosis` | `spectralKurtosis` | R2024b | Not Recommended, will be removed |
| `poctave` (positional args) | `poctave` (name-value) | R2021a | Not Recommended (syntax change) |
| `sgolay` (positional args) | `sgolay` (name-value) | R2021a | Not Recommended (syntax change) |

## Spectral Analysis Modernization

### pkurtosis → spectralKurtosis

**Status:** Not recommended as of R2024b. Will be removed in a future release.

**Old Pattern (Avoid):**
```matlab
% Discouraged: pkurtosis will be removed
[K, F] = pkurtosis(x, fs);
[K, F] = pkurtosis(x, fs, 'FrequencyLimits', [20 2000]);

% Discouraged: Spectrogram-based analysis using pkurtosis
[S, F, T] = spectrogram(x, window, noverlap, nfft, fs);
K = pkurtosis(S);
```

**Modern Pattern (Use This):**
```matlab
% Time-domain signal input
[K, F] = spectralKurtosis(x, fs);
[K, F] = spectralKurtosis(x, fs, FrequencyLimits=[20 2000]);

% Spectrogram input
[S, F, T] = spectrogram(x, window, noverlap, nfft, fs);
K = spectralKurtosis(S);
```

**Why Modern is Better:**
- `spectralKurtosis` uses modern name-value argument syntax
- Better integration with Audio Toolbox workflows
- Consistent naming convention with other spectral functions
- Enhanced performance and reliability

**Migration Notes:**
- Direct replacement for most use cases
- Parameter names remain the same
- Output format is identical

**Key Difference:** Function naming follows modern spectral analysis conventions (camelCase with "spectral" prefix).

---

### poctave → poctave (with modern syntax)

**Status:** Legacy positional syntax discouraged. Use modern name-value pairs.

**Old Pattern (Avoid):**
```matlab
% Legacy positional argument syntax
[p, cf] = poctave(x, fs, 'BandsPerOctave', 3, 'FrequencyLimits', [20 20000]);
```

**Modern Pattern (Use This):**
```matlab
% Modern name-value syntax (R2021a+)
[p, cf] = poctave(x, fs, BandsPerOctave=3, FrequencyLimits=[20 20000]);
```

**Why Modern is Better:**
- Clearer, more readable syntax
- Consistent with modern MATLAB conventions
- Better IDE support and code completion

---

## Filter Design Modernization

### Filter Design with Recommended Patterns

**Status:** Various legacy filter design patterns should be updated.

**Old Pattern (Less Preferred):**
```matlab
% Using filter object (older approach)
Hd = dfilt.df2sos(sos, g);
y = filter(Hd, x);
```

**Modern Pattern (Use This):**
```matlab
% Direct filtering with sos
y = sosfilt(sos, x);

% Or use designfilt for complete workflow
d = designfilt("lowpassiir", ...
    FilterOrder=8, ...
    HalfPowerFrequency=0.2, ...
    DesignMethod="butter");
y = filtfilt(d, x);
```

**Why Modern is Better:**
- `sosfilt` is more memory efficient
- `designfilt` provides a unified design interface
- Better numerical stability with SOS form

---

## Spectral Estimation Best Practices

### Use Modern Spectral Functions

**Recommended Spectral Analysis Functions:**

```matlab
% Power spectral density
[pxx, f] = pwelch(x, window, noverlap, nfft, fs);
[pxx, f] = pspectrum(x, fs);

% Spectrogram analysis
[s, f, t] = spectrogram(x, window, noverlap, nfft, fs);
[p, f, t] = pspectrum(x, fs, 'spectrogram');

% Spectral features (modern approach)
K = spectralKurtosis(x, fs);       % Use this, NOT pkurtosis
S = spectralSkewness(x, fs);
C = spectralCentroid(x, fs);
F = spectralFlatness(x, fs);
R = spectralRolloffPoint(x, fs);
```

---

## Windowing and Preprocessing

### Modern Window Functions

**All standard windows are available:**

```matlab
% Modern approach - specify window type by name
win = hann(256);           % Hann window
win = hamming(256);        % Hamming window
win = blackmanharris(256); % Blackman-Harris window
win = kaiser(256, 5);      % Kaiser window with beta=5

% Or use window function for flexibility
win = window(@hamming, 256);
```

---

## Signal Generation

### Modern Signal Generation Patterns

**Recommendation:** Use signal generation functions with modern syntax.

```matlab
% Chirp signal generation
t = 0:1/fs:1;
y = chirp(t, f0, 1, f1, 'Method', 'linear');

% Modern approach with name-value arguments (R2021a+)
y = chirp(t, f0, 1, f1, Method="linear");

% Noise generation
noise = randn(size(signal));  % White Gaussian noise
pinkNoise = dsp.ColoredNoise(Color="pink", SamplesPerFrame=length(signal));
```

---

## Real-Time Processing Patterns

### System Objects for Streaming

**Modern Pattern for Real-Time Signal Processing:**

```matlab
% Create System objects for streaming
lowpassFilter = dsp.LowpassFilter(SampleRate=fs, PassbandFrequency=1000);
specAnalyzer = spectrumAnalyzer(SampleRate=fs);

% Process in a loop
while ~isDone(audioIn)
    frame = audioIn();
    filtered = lowpassFilter(frame);
    specAnalyzer(filtered);
end

% Release resources
release(lowpassFilter);
release(specAnalyzer);
```

**Why This Matters:**
- System objects maintain state between calls
- Optimized for streaming/real-time processing
- Consistent interface across DSP System Toolbox

----

Copyright 2026 The MathWorks, Inc.

----

deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
Agent Cost Reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
Agent Cost Reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall