I am trying to implement the blew mentioned signal of PRS but unable to do can any one guide me, i stuck
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
dpb
am 30 Sep. 2023
Bearbeitet: dpb
am 30 Sep. 2023
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
% 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...
Antworten (0)
Siehe auch
Kategorien
Mehr zu Spectral Measurements 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!