Filter löschen
Filter löschen

How to create animations with scatterplot and scatter?

3 Ansichten (letzte 30 Tage)
Giuseppe
Giuseppe am 4 Nov. 2023
Beantwortet: Walter Roberson am 4 Nov. 2023
I import a .wav file with audioread function. It's a real signal that then I convert to analytical one since I need to plot the constellation diagram (I-Q plane) and phase; in particular I need to show how IQ samples and phase evolves in time: I want to show the current diagram with time step of 1 second and display the time inside the plots.
Here is a MWE:
clc; clear all; close all;
sig = rand(100,1); %signal channel signal
num_sampl = numel(sig) %number of samples
num_sampl = 100
sig_complex = hilbert(sig); % get the analytic signal
duration = 10 %seconds
duration = 10
F_s = num_sampl/duration; %sampling frequency 5 samples = 1 sec -> F_s = 3Hz)
time_vec = 1:1:duration;
% Movie of IQ samples
figure;
for i = 1:length(time_vec)
xlim([-1,1]); ylim([-1,1]);
sam_start = (i - 1) * F_s + 1;
sam_end = i * F_s;
samples_current = sam_start:1:sam_end;
scatterplot(sig_complex(samples_current)); hold on
%pause(1);
str = "t = "+ num2str(time_vec(i)) + "s";
subtitle(str);
drawnow;
end
% Movie of phase
figure;
for i = 1:length(time_vec)
xlim([-1,1]); ylim([-1,1]);
sam_start = (i - 1) * F_s + 1;
sam_end = i * F_s;
samples_current = sam_start:1:sam_end;
phase = angle(sig_complex(samples_current));
scatter(time_vec(samples_current),phase); hold on
pause(1);
str = "t = "+ num2str(time_vec(i)) + "s";
subtitle(str);
drawnow;
end
Index exceeds the number of array elements. Index must not exceed 10.

Antworten (1)

Walter Roberson
Walter Roberson am 4 Nov. 2023
time_vec = 1:1:duration;
That is not correct. It should be
time_vec = (0:num_samp-1)/Fs;

Kategorien

Mehr zu Animation finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by