How to create and plot square wave on specified "Tau" value

조회 수: 1 (최근 30일)
Emir Dönmez
Emir Dönmez 2024년 1월 5일
댓글: Hassaan 2024년 1월 8일
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 ?)

채택된 답변

Hassaan
Hassaan 2024년 1월 5일
% 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
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
  댓글 수: 2
Emir Dönmez
Emir Dönmez 2024년 1월 8일
I had solved this question after i asked in here but thanks for showing me another solution.
Hassaan
Hassaan 2024년 1월 8일
You are welcome

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by