How to generate a square wave with specif values
5 次查看(过去 30 天)
显示 更早的评论
How to generate a square wave witch start from c0 and reaches c0+Vmax? Thanks for the support
N=1e5
Np=3
Fx=Np/N
n=(0:N-1)';
wt=2*pi*Fx*n;
c0=2
Vmax=5
phi1=pi/3
x_square=
0 个评论
回答(1 个)
Suraj Kumar
2025-3-27
Hi Edoardo,
To generate a square wave in MATLAB that starts at a baseline value c0 and reaches a maximum value of c0 + Vmax, you can check the following steps:
1. Define the necessary parameters required for generating the square wave and create a time vector.
N = 1e5;
Np = 3;
Fx = Np / N;
n = (0:N-1)';
wt = 2 * pi * Fx * n;
c0 = 2;
Vmax = 5;
phi1 = pi/3;
2. Calculate the angular frequency component and generate the square wave using the square function. Transform the wave to oscillate between c0 and c0 + Vmax.
% Generate square wave
x_square = c0 + (Vmax/2) * (1 + square(wt + phi1));
3. Plot the square wave to visualize it.
% Plot the square wave
plot(n, x_square);
xlabel('Sample Index');
ylabel('Amplitude');
title('Square Wave');
grid on;
Hope this solves your query!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Signal Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!