Płot sample of signal
27 views (last 30 days)
Show older comments
How to plot 20s sample signal of the overall signal counting 300000samples with sampling frequency 1000 sample per second?
0 Comments
Answers (2)
Manikanta Aditya
on 13 Nov 2024 at 16:40
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.
0 Comments
Star Strider
on 13 Nov 2024 at 18:17
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
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)')
.
0 Comments
See Also
Categories
Find more on Audio Processing Algorithm Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!