code to sample a signal
71 ビュー (過去 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!
