code to sample a signal
조회 수: 68 (최근 30일)
이전 댓글 표시
x(t)=cos(180*π*t) at sampling rates of 200 and 1500 samples each second. Then plot the graphs.
답변 (3개)
William Rose
2021년 3월 4일
First, you know this cosine has a frequency of 90 Hz and therefore a period of 1/90 sec = 0.0111 sec, because the formula for a sine or cosine with freuqnecy f is
. Therefore a plot that goes to 0.04 sec will include almost 4 cycles of the wave, so we aim for that.
. Therefore a plot that goes to 0.04 sec will include almost 4 cycles of the wave, so we aim for that. SR1=200; %sampling rate
dt1=1/SR1; %sampling interval
t1=0:dt1:.04;
x1=cos(180*pi*t1);
SR2=1500; %sampling rate
dt2=1/SR2; %sampling interval
t2=0:dt2:.04;
x2=cos(180*pi*t2);
plot(t1,x1,'rx-',t2,x2,'bo-');
xlabel('Time (s)'); ylabel('x');
legend('SR=200','SR=1500');

댓글 수: 3
William Rose
2023년 4월 2일
@mandah batjargal, I chose a sampling time, or (equivalently) sampling duration, of 0.04 s because it would be enough to see several cycles of the sinusoidal wave.
I like the fact that this problem illustrates that sampling at a rate that slightly exceeds the Nyquist freuency is not sufficient to provide a good visual image of the signal. For this reason I always recommend to students that, if they are using an anti-aliasing filter, they sample at 5 to 10 times its cutoff frequency. (Another reason to oversample is that no lowpass filter is a perfect brick wall, so there's likely to be some power at frequencies above the cutoff.)
Hassaan
2023년 12월 21일
편집: Voss
2023년 12월 21일
% Define the signal frequency
signalFrequency = 90; % in Hz
% Define the number of cycles to plot
numberOfCycles = 3; % for example, to plot the first 3 cycles
% Define the sampling rates
SR1 = 200; % First sampling rate in Hz
SR2 = 1500; % Second sampling rate in Hz
% Calculate the period of the cosine signal
signalPeriod = 1 / signalFrequency; % Period of the signal in seconds
% Calculate the time span for N cycles
timeSpan = numberOfCycles * signalPeriod;
% Create time vectors for the first few cycles
t1 = 0:1/SR1:timeSpan; % Time vector for first sampling rate
t2 = 0:1/SR2:timeSpan; % Time vector for second sampling rate
% Sample the cosine wave for the first few cycles
x1 = cos(2 * pi * signalFrequency * t1); % Sampled signal at first sampling rate
x2 = cos(2 * pi * signalFrequency * t2); % Sampled signal at second sampling rate
% Plot the sampled signals
figure; % Create a new figure
plot(t1, x1, 'bo-', t2, x2, 'rx-'); % Plot both signals on the same graph
xlabel('Time (s)'); % Label for the x-axis
ylabel('Amplitude'); % Label for the y-axis
title('Sampled Cosine Signal for First Few Cycles'); % Title of the plot
legend('SR=200', 'SR=1500'); % Legend to distinguish the two sampled rates
In this code:
- The timeSpan variable is calculated to contain the time duration of N cycles of the cosine wave.
- The t1 and t2 vectors are created to span this duration at the respective sampling rates.
- The plot function is used to plot the first few cycles of the sampled signals.
If you liked the anwer and it solved your problem. Please do leave a upvote and a comment means a lot. Thank you.
댓글 수: 0
Yerramsetty
2024년 8월 12일
to write and execute a program to sample and reconstruct audio signals using matlab software simulation
댓글 수: 1
Walter Roberson
2024년 8월 12일
I don't understand how this Answer solves the problem that was originally posted??
참고 항목
카테고리
Help Center 및 File Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
