Effacer les filtres
Effacer les filtres

deal signal in simulink

4 vues (au cours des 30 derniers jours)
洪宇
洪宇 le 19 Juin 2024
Commenté : 洪宇 le 20 Juin 2024
You can see that my original signal is the yellow line in the picture, similar to a series of pulses. I want to process the original signal to look like the red in the picture, a ramp signal with a class period. After a peak, it immediately decreases to 0 and then linearly increases from 0 to a new peak
i use matlab function in simulink ,but can‘t work like i expect
my english is not that good ,if you have any question,please let me know
  2 commentaires
洪宇
洪宇 le 19 Juin 2024
function processed_signal = process_signal(peak_signal)
num_samples = length(peak_signal); % 获取输入信号的长度
processed_signal = zeros(num_samples, 1); % 初始化输出信号为零
% 找到峰值点
peak_times = find(peak_signal); % 找到所有峰值点的时间索引
if isempty(peak_times)
return; % 如果没有峰值点,直接返回
end
% 线性上升到达每个峰值点
for i = 1:length(peak_times)
peak_index = peak_times(i);
peak_height = peak_signal(peak_index);
% 计算线性上升的斜率
slope = peak_height / peak_index; % 斜率 = 峰值高度 / 达到峰值的点数
% 应用线性上升
for j = 1:peak_index
processed_signal(j) = slope * j;
end
end
% 由于在每个峰值点后信号立即下降到0,我们不需要额外的代码来设置为0
end
洪宇
洪宇 le 19 Juin 2024
this is my code, it can run ,but the output in scope block is the same as my original signal

Connectez-vous pour commenter.

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 19 Juin 2024
Modifié(e) : Fangjun Jiang le 19 Juin 2024
It does not work like that. A MATLAB Function block is like any other Simulink block. It is executed at every time step. At t=5, it is not supposed to know the peak value of the input sigal at t=6. You could provie all the peak values of the input signal for the entire 30 seconds at once, but again, do you want the MATLAB Function block to do the same processing again and again at every simulation step?
I suggest using the Signal Builder block. Add a sawtooth signal, then you can adjust those data points (either x or y value) to match your data.
If there are too many data points, then you can use a Lookup Table block to specify the data. Then providing the Clock signal as the input and the output of the Lookup Table block will be the signal you need. The only issue is that you need to specify the time for the peak and then the time for the "zero" be really close.
  1 commentaire
洪宇
洪宇 le 20 Juin 2024
thanks a lot

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by