How to plot rectanular puls

45 Ansichten (letzte 30 Tage)
Yasser toni am 31 Jan. 2022
Beantwortet: Neelanshu am 8 Feb. 2024
Using the matlab, represent the rectangular pulse A rect (t /  ) in Time- Domain and in Frequency-Domain. - (use the range of T-axis (-10 : +10) with step 0.001 seconds) - Let the signal duration = 4 sec. and the amplitude A = 2 - PROCEDURE: 1- Generating rectangular pulse in T – Domain. 2- Transforming the signal from T-domain into F-Domain 3- Plot the signal in T and F domains
1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Image Analyst am 31 Jan. 2022

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Neelanshu am 8 Feb. 2024
Hi Yaseer,
I see you're interested in visualizing a rectangular pulse in both the time and frequency domains.
To get started, you can use MATLAB's "fft" function, which stands for Fast Fourier Transform. This function will help you convert your time-domain signal into the frequency domain, showing you how the signal's energy is distributed across different frequencies.
The following code creates a rectangular pulse with an amplitude of 2 and a duration of 4 seconds. It then computes the Fourier transform of the pulse to represent it in the frequency domain and plots both the time domain and frequency domain representations :
clear;
clc;
% Define parameters
A = 2; % Amplitude of the rectangular pulse
tau = 4; % Duration of the rectangular pulse in seconds
t_step = 0.001; % Time step in seconds
t_range = -10:t_step:10; % Time range from -10 to 10 seconds
% 1. Generating rectangular pulse in the time domain
rect_pulse = A * (abs(t_range) < (tau/2));
% 2. Transforming the signal from the time domain into the frequency domain
N = length(t_range); % Number of points in the signal
f_signal = fft(rect_pulse, N); % Compute the FFT of the signal
f_signal = fftshift(f_signal); % Shift the zero frequency component to the center
f_range = (-N/2:N/2-1)*(1/(t_step*N)); % Frequency range
% 3. Plot the signal in the time domain
figure;
subplot(2,1,1);
plot(t_range, rect_pulse);
title('Rectangular Pulse in Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Plot the magnitude of the signal in the frequency domain
subplot(2,1,2);
plot(f_range, abs(f_signal)/N); % Normalized magnitude
title('Rectangular Pulse in Frequency Domain');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;
If you want to dive deeper into the "fft" and "fftshift" functions, you can check out MATLAB's documentation for a more detailed explanation:
Hope this helps
0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB 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!

Translated by