Płot sample of signal

13 visualizaciones (últimos 30 días)
Elzbieta
Elzbieta el 13 de Nov. de 2024
Respondida: Star Strider el 13 de Nov. de 2024

How to plot 20s sample signal of the overall signal counting 300000samples with sampling frequency 1000 sample per second?

Respuestas (2)

Manikanta Aditya
Manikanta Aditya el 13 de Nov. de 2024
Hi,
Please refer to the following script to plot a 20-second sample of a signal with a total of 300,000 samples and a sampling frequency of 1000 samples per second:
% Define parameters
total_samples = 300000;
sampling_frequency = 1000; % in Hz
duration = 20; % in seconds
% Generate a time vector for the entire signal
t = (0:total_samples-1) / sampling_frequency;
% Generate a sample signal (for example, a sine wave)
signal = sin(2 * pi * 5 * t); % 5 Hz sine wave
% Extract the 20-second sample
sample_duration = 20; % in seconds
sample_samples = sample_duration * sampling_frequency;
sample_signal = signal(1:sample_samples);
sample_time = t(1:sample_samples);
% Plot the 20-second sample
figure;
plot(sample_time, sample_signal);
xlabel('Time (s)');
ylabel('Amplitude');
title('20-Second Sample of the Signal');
grid on;
Hope this helps.

Star Strider
Star Strider el 13 de Nov. de 2024
The number of samples you need to plot is equal to the sampling frequeency multiplied by the number of seconds.
Fs = 1000;
td = 20;
nr_samples = Fs * td
nr_samples = 20000
t = linspace(0, 300000-1, 300000)/Fs;
s = sin(2*pi*t/20) .* cos(2*pi*t/5);
figure
plot(t,s)
xlabel('Time')
ylabel('Amplitude')
title('Entire Signal')
v = 1:nr_samples;
figure
plot(t(v),s(v))
xlabel('Time')
ylabel('Amplitude')
title('20s Signal')
Lv = (t >= 0) & (t<=20); % Use Time Vector To Select Part Of The Signal You Want To Plot
figure
plot(t(Lv),s(Lv))
xlabel('Time')
ylabel('Amplitude')
title('20s Signal (Logical Subscript)')
.

Categorías

Más información sobre Audio Processing Algorithm Design en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by