Płot sample of signal
조회 수: 18 (최근 30일)
이전 댓글 표시
How to plot 20s sample signal of the overall signal counting 300000samples with sampling frequency 1000 sample per second?
댓글 수: 0
답변 (2개)
Manikanta Aditya
2024년 11월 13일 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
Star Strider
2024년 11월 13일 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
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio Processing Algorithm Design에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!