How to give different colors to different regions of a signal(extracted from an audio amplitude-Fs)?

1 view (last 30 days)
Adi Ayoub
Adi Ayoub on 23 Nov 2021
Answered: Mathieu NOE on 23 Nov 2021
i need to give different colors with an interval of 1 second

Answers (1)

Mathieu NOE
Mathieu NOE on 23 Nov 2021
hello
maybe this ?
clc
clearvars
% signal
Fs = 100;
dt= 1 /Fs;
samples = 5*Fs; % 5 seconds of signal
freq = 3;
t = (0:samples-1)*dt;
x = sin(2*pi*freq*t);
buffer_seconds = 1; % buffer length in seconds
buffer = buffer_seconds*Fs; % buffer length in samples
figure(1),hold on
for ci = 1:fix(samples/buffer)
start_index = 1+(ci-1)*buffer;
stop_index = min(start_index+ buffer,samples);
tt = t(start_index:stop_index); %
xx = x(start_index:stop_index); %
plot(tt,xx)
end
hold off

Community Treasure Hunt

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

Start Hunting!