- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
How to create and plot square wave on specified "Tau" value
2 views (last 30 days)
Show older comments
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1583461/image.png)
Message funciton of m(t) is basically two square wave. My question is how can i create one these square waves ?
(From duality property left square wave's formula become this =>2*sinc((t-1)*2) and then i can plot this equations graph, maybe ?)
0 Comments
Accepted Answer
Hassaan
on 5 Jan 2024
% Define the time vector from -10 to 10 with 1000 points
t = linspace(-10, 10, 1000);
% Define the square wave function
square_wave = @(t, center) double(abs(mod(t - center, 2)) < 1);
% Create the square waves with different centers
wave1 = square_wave(t, 1);
wave2 = square_wave(t, 3);
% Calculate the message function m(t) as the difference of the two square waves
m_t = wave1 - wave2;
% Plot the square waves and the message function m(t)
figure;
hold on;
plot(t, wave1, 'DisplayName', 'Square Wave 1 (centered at t=1)');
plot(t, -wave2, 'DisplayName', 'Square Wave 2 (centered at t=3)'); % Negative for subtraction
plot(t, m_t, 'DisplayName', 'Message Function m(t)');
hold off;
% Add title and axis labels
title('Square Waves and Message Function m(t)');
xlabel('Time t');
ylabel('Amplitude');
% Add grid and legend
grid on;
legend show;
Uses an anonymous function to define the square wave, then calculates the waveforms and the message function. Finally, it plots all the functions on the same graph, with a legend to distinguish them.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!