How to create animations with scatterplot and scatter?

조회 수: 9 (최근 30일)
Giuseppe
Giuseppe 2023년 11월 4일
답변: Walter Roberson 2023년 11월 4일
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.

답변 (1개)

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

카테고리

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

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by