sine wave with frequency up to 1MHz

31 ビュー (過去 30 日間)
Alhassane Sylla
Alhassane Sylla 2024 年 12 月 5 日 18:06
コメント済み: Alhassane Sylla 2024 年 12 月 5 日 21:40
I am trying to generate a sine wave with a frequency up to 1MHz, my code below can work for a frequency up to 300kHz, for frequency above no wave is generated, can someone help please? here is my code and screeshot.
sig_amp = 2.8; %amplitude
fs = 1e+6; %signal frequency Hz
sampleRate = 1e+6;
numSamplesPerCycle = floor(sampleRate/(fs));
T = 1/(fs); %sampling period
timestep = T/numSamplesPerCycle;
t = (0 : timestep : 5-timestep)';
x = sig_amp*sin(2*pi*fs*t)';
plot(t,x,'.-');
s.queueOutputData(x');
xlabel('temps (s)');
ylabel('Tension de sortie (V)');
title('Signal versus Time');
grid on
zoom xon;
s.ScansQueued

採用された回答

Subhajyoti
Subhajyoti 2024 年 12 月 5 日 19:45
It is my understanding that you are trying to plot a sine wave with a frequency up to 1MHz.
According to the Nyquist–Shannon sampling theorem, the sample rate must be at least twice the bandwidth of the signal to avoid aliasing, a type of distortion that occurs when the sample rate is too low.
Here, in the following implementation, I have increased the sampling rate for better resolution.
sig_amp = 2.8; %amplitude
fs = 1*1000*1000; %signal frequency Hz
sampleRate = 4*1000*1000;
numSamplesPerCycle = floor(sampleRate/(fs));
T = 1/(fs); %sampling period
timestep = T/numSamplesPerCycle;
t = (0 : timestep : 5-timestep)';
x = sig_amp*sin(2*pi*fs*t)';
plot(t,x,'.-');
xlabel('temps (s)');
ylabel('Tension de sortie (V)');
title('Signal versus Time');
grid on
  3 件のコメント
Subhajyoti
Subhajyoti 2024 年 12 月 5 日 21:05
Yes, you are correct.
Alhassane Sylla
Alhassane Sylla 2024 年 12 月 5 日 21:40
Thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWaveform Generation についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by