How to generate a discrete square pulse, lets say N times?
古いコメントを表示
Lets say sample rate =20kHz symbol rate =1khz
1 件のコメント
Naga Sai
2017 年 5 月 22 日
https://in.mathworks.com/matlabcentral/answers/155687-how-to-generate-a-discrete-square-pulse-lets-say-n-times#comment_238487
回答 (2 件)
Image Analyst
2014 年 9 月 21 日
Make up one cycle, then use repmat() to make as many copies as you want.
squareWave = repmat([1,1,1,1,0,0,0,0], [1, N]);
What is a "symbol rate"?
10 件のコメント
Prajan Pradhan
2014 年 9 月 21 日
Youssef Khmou
2014 年 9 月 21 日
it is the number of symbol change, the inverse of symbol duration time. simply from physics viewpoint, its the frequency of the waveform.
Image Analyst
2014 年 9 月 21 日
編集済み: Image Analyst
2014 年 9 月 21 日
I'm not familiar with that terminology. I see a period of 0.1 seconds, and a duty cycle of roughly 30%, and a sampling rate that can't be determined from the plot but he says it's 20,000 per second or 5e-05 seconds between samples.
Try this:
fontSize = 20;
% One cycle in a 1/10 of a second = 2000 samples
oneCycle = zeros(1, 2000);
% Have a duty cycle of 30%, or 15% at the start and 15% at the end
% 15% of the elements = 300
oneCycle(1:300) = 1;
oneCycle(end-300:end) = 1;
% Now we have one cycle, use repmat to make 10 copies
tenCycles = repmat(oneCycle, [1, 10]);
% Set up the t axis
t = linspace(0, 1, length(tenCycles));
plot(t, tenCycles, 'b-', 'LineWidth', 2);
grid on;
xlabel('Seconds', 'FontSize', fontSize);
ylabel('Amplitude', 'FontSize', fontSize);
ylim([-0.5, 1.5]);

Youssef Khmou
2014 年 9 月 21 日
the questioner said that he wants a discrete type of the square wave not the square wave itself, which is not clear yet.
Image Analyst
2014 年 9 月 21 日
I don't understand the difference. Everything in computers is discrete/binary/digitized/quantized. And my plot looks just like the one he said he wanted.
Youssef Khmou
2014 年 9 月 21 日
its true, waiting for some explanation.
Image Analyst
2014 年 9 月 22 日
I don't think he will. I think he's ignoring this thread because he posted the same question here an hour after I gave my answer. Well, who knows. Maybe he will come back some day.
Youssef Khmou
2014 年 9 月 22 日
i think 'discrete form' means a graph with '--' notation.
Naga Sai
2017 年 5 月 22 日
sir how to generate a power spectrum for this Wave form
Naga Sai
2017 年 5 月 22 日
Sir how to generate a power spectrum for this wave form
Youssef Khmou
2014 年 9 月 21 日
You can either write the function or use built-in function, here is an example using 1000 samples :
N=1e+3;
Fs=20e+3;
f=1e+3;
Ts=1./Fs;
t=0:Ts:N*Ts-Ts;
y=square(2*pi*f*t);
figure; plot(t,y);
2 件のコメント
Prajan Pradhan
2014 年 9 月 21 日
Image Analyst
2014 年 9 月 21 日
Yes, square() is in the Signal Processing Toolbox - do you have that toolbox? I have not heard of those two other functions you mention.
カテゴリ
ヘルプ センター および File Exchange で Waveform Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
