How to generate a square wave with specif values
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Suraj Kumar
am 27 Mär. 2025
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 Kommentare
Siehe auch
Kategorien
Mehr zu Signal Processing Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
