I am trying to implement the blew mentioned signal of PRS but unable to do can any one guide me, i stuck

조회 수: 1 (최근 30일)
Fs = 120; % Sampling frequency, 50 Hz
t = 0:1/Fs:1; % Time vector from 0 to 1 second
% Create the signal according to the given intervals
step = zeros(size(t));
step(t >= 0 & t < 0.05) = 1;
step(t >= 0.05 & t < 0.021) = -1;
step(t >= 0.021 & t < 0.041) = 1;
step(t >= 0.041 & t < 0.061) = -1;
step(t >= 0.061 & t < 0.1) = -1;
step(t >= 0.1 & t < 0.2) = 1;
step(t >= 0.2 & t < 0.3) = -1;
step(t >= 0.3 & t < 0.35) = 1;
step(t >= 0.35 & t < 0.38) = 1;
step(t >= 0.38& t < 0.4) = 1;
step(t >= 0.4 & t < 0.5) = -1;
step(t >= 0.5 & t < 0.55) = -1;
step(t >= 0.55 & t < 0.6) = -1;
step(t >= 0.6 & t < 0.8) = -1;
step(t >= 0.8 & t < 0.85) = 1;
step(t >= 0.85 & t < 0.9) = 1;
step(t >= 0.9 & t <= 1) = 1;
% Plot the signal in the time domain using stairs
figure;
stairs(t, step);
xlabel('Time (s)');
ylabel('Amplitude');
title('Signal in Continuous Time Domain');
% Compute the FFT of the signal
n = length(t);
f = Fs*(0:(n/2))/n; % Frequency vector
Y = fft(step)/n; % Normalized FFT
Y = Y(1:n/2+1); % Single-sided spectrum
% Plot the stem-like FFT of the signal
figure;
stem(f, abs(Y));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('FFT of Signal');
  댓글 수: 1
dpb
dpb 2023년 9월 30일
편집: dpb 2023년 9월 30일
Fs = 120; % Sampling frequency, 50 Hz
t = 0:1/Fs:1; % Time vector from 0 to 1 second
% Create the signal according to the given intervals
step = zeros(size(t));
step(t >= 0 & t < 0.05) = 1;
step(t >= 0.05 & t < 0.021) = -1;
step(t >= 0.021 & t < 0.041) = 1;
step(t >= 0.041 & t < 0.061) = -1;
step(t >= 0.061 & t < 0.1) = -1;
step(t >= 0.1 & t < 0.2) = 1;
step(t >= 0.2 & t < 0.3) = -1;
step(t >= 0.3 & t < 0.35) = 1;
step(t >= 0.35 & t < 0.38) = 1;
step(t >= 0.38& t < 0.4) = 1;
step(t >= 0.4 & t < 0.5) = -1;
step(t >= 0.5 & t < 0.55) = -1;
step(t >= 0.55 & t < 0.6) = -1;
step(t >= 0.6 & t < 0.8) = -1;
step(t >= 0.8 & t < 0.85) = 1;
step(t >= 0.85 & t < 0.9) = 1;
step(t >= 0.9 & t <= 1) = 1;
% Plot the signal in the time domain using stairs
figure;
subplot(3,2,1)
stairs(t, step);
ylim([-1.5 1.5])
xlabel('Time (s)');
ylabel('Amplitude');
title('Signal in Continuous Time Domain');
% Compute the FFT of the signal
n = length(t);
f = Fs*(0:(n/2))/n; % Frequency vector
Y = fft(step)/n; % Normalized FFT
Y = Y(1:n/2+1); % Single-sided spectrum
Warning: Integer operands are required for colon operator when used as index.
% Plot the stem-like FFT of the signal
%figure;
subplot(3,2,2)
stem(f, abs(Y));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('FFT of Signal');
This is (as I'm sure you've noticed) a very inefficient way to generate a varying frequency square wave -- it's essentially a hopeless task from just the info you've provided; you need a definition of what the frequency signal actually is for each example which one would presume is in the text or homework problem definition besides just the figure...

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by