I'm running signal processing simulations in Simulink. What's the proper way to set the solver step size?(I've attached my .slx file, tks!)

6 visualizzazioni (ultimi 30 giorni)
1. Solver Configuration for AM Modulation/Demodulation
I'm building an AM modulation/demodulation model in Simulink using the DSP System Toolbox. My signal source is a Sine Wave (continuous mode) block.
  • Solver Type: Should I use fixed-step or variable-step solver for this scenario?
  • Step Size Issue: When I set a fixed step size of 1e-04, the Spectrum Analyzer block correctly shows the power spectrum of a 50Hz sine wave. However, if I reduce the step to 1e-06, the spectrum becomes distorted. Why does a smaller step size lead to incorrect results? (Intuitively, shouldn't smaller steps improve accuracy?)
2. Discrete Mode vs. Solver Step
Even though I currently use Sine Wave in continuous mode, I'd like to understand how to configure it in discrete mode:
  • In discrete mode, the Sine Wave block requires a sample time parameter. How does this sample time relate to the solver's step size?
  • What’s the rule for setting the solver step when the signal source is discrete?
3. Modeling Signal Propagation Delay
In my current model, the receiver starts demodulating the signal immediately after the transmitter generates it (no propagation delay). This is unrealistic. How can I simulate a time delay between transmission and reception?
  • Is there a specific block (e.g., Delay or Variable Transport Delay) recommended for this purpose?
  • Should the delay time be aligned with the solver step size or the signal's sample time?
Additional Context:
  • MATLAB Version: R2024a
  • Toolboxes: Simulink, DSP System Toolbox
Below is my model and the blocks used, with relevant parameters annotated in the diagram.
When I set step = 1e-04:
when I set step = 1e-06:

Risposte (2)

Samhitha
Samhitha il 22 Apr 2025
For signal processing applications especially when using Spectrum Analyzer you should fixed-step solver. Because fixed-step solvers give a consistent sample time, which is important for correct frequency analysis.
  1. Sine Wave in continuous mode generate samples at each simulation step. Spectrum Analyzer expects a uniformly sampled, discrete-time signal, where the sample rate is determined by the solver step size. For step size 1e-04, Sample rate = 1/1e-4 = 10,000 Hz. For a 50 Hz sine wave, this is more than enough according to Nyquist criterion, so the spectrum is accurate. For step size 1e-06, Sample rate = 1/1e-6 = 1,000,000 Hz. Now, the Sine Wave block is generating way more samples than needed.  The spectrum appears distorted because the signal is oversampled.
  2. For discrete systems, the solver step size should match the fastest sample time in your model. For more details you can go through the following documentation https://www.mathworks.com/help/simulink/ug/compare-solvers.html#f7-14323
  3. To simulate propagation delay, use the Delay block (for discrete signals) or the Transport Delay block (for continuous signals). For discrete signals, set the delay as an integer of number of samples, which should match your signal’s sample time. For continuous signals, set the delay in seconds, but accuracy improves if the solver step is much smaller than the delay.
For more details look into this following documentation
Hope this helps!
  2 Commenti
ColdRabbit
ColdRabbit il 24 Apr 2025
Thank you for your helpful answers! However, I still have some follow-up questions.
I’m confused about why the spectrum appears distorted when the signal is oversampled. Theoretically, oversampling should only slow down the processing due to the increased number of points, requiring more memory and computational resources—but it shouldn’t lead to incorrect results.
To verify this, I wrote the following code (see below). The results show that, regardless of the sampling frequency (fs), the spectrum remains correct—I can clearly identify the baseband signal and carrier frequencies. However, this differs from what I observe in my Simulink model.
I suspect there might be some Simulink-specific behavior that I’m missing, possibly related to the Spectrum Analyzer settings. Could you help me understand why the results differ between MATLAB and Simulink?
Thank you in advance for your insights!
clc;clear;
close all;
T = 1e-01; % sample time 0.1s
cnt = 1;
for fs = [1e04 1e06]
ts = 1 / fs;
N = T * fs;
f_m = 50; % Hz
sig_m = cos(2 * pi * f_m .* [0 : N - 1] .* ts);
f_c = 1e03;
sig_c = cos(2 * pi * f_c .* [0 : N - 1] .* ts);
sig_modulated = sig_m .* sig_c;
sig_modulated_f = fft(sig_modulated);
figure(cnt);
plot(linspace(-fs/2, fs/2, N), mag2db(abs(fftshift(sig_modulated_f))));
xlabel('Hz');ylabel('dB');
title(['Spectrum, fs = ', num2str(fs), 'Hz']);
xlim([-2000 2000])
cnt = cnt+1;
end
ColdRabbit
ColdRabbit il 24 Apr 2025
Actually, I realized that the Spectrum Analyzer in Simulink uses a filter bank approach. Perhaps I should apply the same method to analyze the signal in my code example. However, I’m still not entirely clear on how filter banks work, so I’ll need some time to study the principle before providing a conclusive result.

Accedi per commentare.


Paul
Paul il 26 Apr 2025
Hi ColdRabbit,
As long as the Sample Time parameter of the ZOH block is set to the sampling period for which you want to compute the spectrum, it won't matter if you use a variable or fixed-step solver. If the ZOH block Sample Time is set to -1, then one should use a fixed-step solver and the ZOH output will be sampled at the solver steps. Sample Time set to -1 with a variable step solver would probably be undesriable. Probably best to speficy the ZOH Sample Time explicitly instead of inherited.
The Spectrum Analyzer block will operate at the sample time of the input signal unless it's set explicitly under the Scope tab. Based on the pictures, it looks like you're using the default parameters for the Spectrum Analyzer block. Note that in both cases (Ts = 1e-4, Ts = 1e-6), the analyzer is using 1024 samples per update. With Ts = 1e-4, with 1024 samples we have
Nperiods = 1024*1e-4*[50 1000]
Nperiods = 1×2
5.1200 102.4000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
of data per update. But for T = 1e-6, we have
Nperiods = 1024*1e-6*[50 1000]
Nperiods = 1×2
0.0512 1.0240
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
which probably isn't enough information to compute the spectrum.
Try exploring the parameters under the Estimation -> Freqeuency Resolution to get more samples per update.
  3 Commenti
Paul
Paul il 26 Apr 2025
Modificato: Paul il 26 Apr 2025
The parameters under the Frequency Resolution tab have interdpendencies on each other (and on parameters under other tabs). According to the doc page, whether or not the Window Length parameter is enabled depends on the settings of the Estimation Method and the Resolution Method. I only scanned the doc age and played around with the model tyring different parameters. I suggest reading the relevant portions of the doc page in detail to achieve whatever is needed.
ColdRabbit
ColdRabbit il 27 Apr 2025
Okay, thank you so much, Paul! I guess I should go through the documentation more carefully. Wait for my good news—hahaha!

Accedi per commentare.

Prodotti


Release

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by