Plot binary sequence of type char (MATLAB)

9 vues (au cours des 30 derniers jours)
high speed
high speed le 2 Déc 2022
Commenté : high speed le 2 Déc 2022
Dear,
I have this binary sequence '011010001000000001010011' of type char, and I want to plot it to obtain a graph like that for example:
  2 commentaires
Fifteen12
Fifteen12 le 2 Déc 2022
What have you tried so far? Love to help, but not sure what you're confused on!
high speed
high speed le 2 Déc 2022
@John Morris After sampling, quantifying and encoding the original signal, I want just to plot the obtainedd binary sequence

Connectez-vous pour commenter.

Réponse acceptée

Askic V
Askic V le 2 Déc 2022
This is how I would do it:
bin_sq = '011010001000000001010011';
N = length(bin_sq); % nr of characters
pulse_duration = 2; % 2 sec
total_duration = N * pulse_duration;
% Initialize array
pulse_arr = ones(1,N);
% put zeros on appropriate places
pulse_arr(bin_sq == '0') = 0;
dt = 0.01; % choose step size
t = 0:dt:total_duration;
% Initialize output signal
output_sig = zeros(size(t));
for ii = 0:N-1
start_point = ii*pulse_duration;
end_point = (ii+1)*pulse_duration;
output_sig(t>=start_point & t < end_point) = pulse_arr(ii+1);
end
% Plot output signal
plot(t,output_sig, 'LineWidth',2)
  1 commentaire
high speed
high speed le 2 Déc 2022
@Askic V That's more practical. Thank you

Connectez-vous pour commenter.

Plus de réponses (1)

Fifteen12
Fifteen12 le 2 Déc 2022
Modifié(e) : Fifteen12 le 2 Déc 2022
seq = randi(2, [1, 20]) - 1;
y = seq(1);
x = 0;
for i = 1:length(seq)-1
y(end+1) = seq(i);
x(end+1) = i;
if seq(i+1) ~= seq(i)
y(end+1) = seq(i+1);
x(end+1) = i;
end
end
plot(x, y)
axis([0, x(end), -2, 3])

Catégories

En savoir plus sur Descriptive Statistics dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by