Generating trapezoidal wave given plateau duration and total length of impulse train

3 次查看(过去 30 天)
Hello,
I want to plot a trapezoidal wave train knowing only the plateau times, meaning the duration of the "flat part" of the trapezoidal wave, and the total duration of the impulse train, depending on another data vector I have. I do not have the equation of the ascending or descending parts, even though I can calculate them. But I need an easy way to plot this in matlab.
The plateaus need to be 60 seconds long and total number of points needs to be equal to the length of a data vector A.
So far I only found the trapezoidal equation with some parameters:
a = 0.5 %Amplitude
m = 9.55 % Time Period
l = 3*pi/2 % phase
c = a/2 % offset
x = 0:.1:100 %Sample Points
Trapezoidal_Wave = a/pi*(asin(sin((pi/m)*x+l))+acos(cos((pi/m)*x+l)))-a/2+c;
plot(x, Trapezoidal_Wave)
However I cannot control the plateau duration (or I don't understand how). Any help and any better way to do this would be greatly appreciated. Thank you!

回答(1 个)

Aniket
Aniket 2024-10-7
Hi @Howard,
From your description, I understand that you have a data vector and on the basis of number of points in that vector, you want to have a trapezoidal wave composed of rise, plateau and fall with plateau to last for a specific duration (ex 60 secs).
A = rand(1, 1000); % Example data vector A
total_points = length(A);
% Adjust below parameters
plateau_duration = 60;
total_duration = 180;
a = 0.5;
The number of points assigned to each segment is proportional to its duration. Since the total number of points is equal to the length of the data vector, the number of points for the plateau is calculated based on how long the plateau lasts compared to the total time.
Kindly follow the below code to generate a single pulse and extrapolate it to meet the requirements:
% Calculate points for each segment
plateau_points = floor(total_points * (plateau_duration / (total_duration)));
rise_fall_points = (total_points - plateau_points) / 2;
% Generate the trapezoidal wave
t_rise = linspace(-pi/2, pi/2, rise_fall_points);
t_fall = linspace(pi, 0, rise_fall_points);
rise = (a/pi) * (asin(sin(t_rise)) + pi/2);
plateau = a * ones(1, plateau_points);
fall = (a/pi) * (acos(cos(t_fall)) - 0);
% Concatenate segments
trapezoidal_wave = [rise, plateau, fall];
% Plot the trapezoidal wave
t = linspace(0, total_points, numel(trapezoidal_wave)); % Time vector
plot(t, trapezoidal_wave);
xlabel('Time');
ylabel('Amplitude');
title('Trapezoidal Wave Train');
grid on;
This method resembles the given equation and enables control over the plateau's duration and the overall length of the wave train by adjusting the data vector's length. The parameters can be tweaked to achieve the desired waveform.
I hope this points you in the right direction!
  1 个评论
Howard
Howard 2024-10-8
thank you, that is exactly what I want. However, I need to be able to build an impulse train with a set number of repetitions. And this needs to be the same dimension of data vector A. So if I want for example 4 repetitions of this trapzoidal impulse, the trapezoidal_wave vector must still be 1000 points in length. How can I do it?

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by