How to create animations with scatterplot and scatter?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
sig_complex = hilbert(sig); % get the analytic signal
duration = 10 %seconds
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
0 Kommentare
Antworten (1)
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;
0 Kommentare
Siehe auch
Kategorien
Mehr zu Animation 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!