Random Time-domain pulse in MATLAB

Status
Not open for further replies.

Ata_sa16

Full Member level 6
Joined
Mar 29, 2016
Messages
343
Helped
59
Reputation
118
Reaction score
58
Trophy points
28
Location
Milky Way Galaxy, 179° 56′ 39.4″
Activity points
2,221
Hi,

Could some one help me with writing code for Random pulse train in MATLAB

I need it in time domain. I used pulsetran function but it does not give random pulse.

 

Use randn() as y-vector.
Then generate x-vector.
And interpolate y-vector according to x-vector.
 

Code:
p=[randi([0 1],1,100)]

Fs = 1000;
T=1/Fs
t = 0:T:99*T;

x = interp1(t,p);

plot(t,x);


Did not work

- - - Updated - - -

I wrote code to get spectrum of pulse train


As you see, pulse is periodic but I want to make it random like the figure I've uploaded in my first post.

Code:
Fs = 1e9;
T=1/Fs

t = 0:T:(10*4e-6);

pulsewidth = (1e-6)
pulseperiods = [0:50]*3e-6;

x = pulstran(t,pulseperiods,'rectpuls',pulsewidth);

L=40001;
subplot(2,1,1)
plot(t,x);

NFFT = 2048;
X = fftshift(fft(x,NFFT)); %FFT with FFTshift for both negative & positive frequencies
f = Fs*(-NFFT/2:NFFT/2-1)/NFFT; %Frequency Vector

subplot(2,1,2)
plot(f,abs(X)/(L),'r');
title('Magnitude of FFT');
xlabel('Frequency (Hz)')
ylabel('Magnitude |X(f)|');

How can I change pulse train to random pulse train ?
 
Last edited by a moderator:

Code:
close all, clear all
set(0, 'language', 'english')

set(gcf, 'numbertitle', 'off')
set(gcf, 'MenuBar', 'none')
set(gcf, 'name', mfilename)

% p = [randi([0 1], 1, 100)]
% Fs = 1000;
% T = 1 / Fs
% t = 0:T:99*T;
% x = interp1(t, p);
% plot(t, x);

x0 = 1:40;
y0 = int32( randn( size(x0) ) >= 0.0 );

OverSamples = 10;
x1 = 1:OverSamples*x0(end);

ix = fix((x1-1)/OverSamples) + 1;
y1 = y0(ix);

plot(x1, y1, 'color', 'g', 'LineWidth', 2)
grid on
 

Attachments

  • 171126-193530.png
    7.2 KB · Views: 169
Last edited:

Thank you for your time. I know how to make this with another method. It is discrete. I want to make continuous pulse.

Imagine minimum pulse width = Tb=1u S and Fs=1n S

So imagine that you have a continuous time domain random pulse domain and you want to modulation on it.

Lets say we are doing basic and simple ask modulation.




I wrote this code. I just want to replace this periodic pulse with the one I mentioned above.

- - - Updated - - -

- - - Updated - - -

Code:
Fs = 1e9;
T=1/Fs

t = 0:T:(10*4e-6);

pulsewidth = (1e-6)
pulseperiods = [0:50]*3e-6;

x = 1*pulstran(t,pulseperiods,'rectpuls',pulsewidth);
L=40001;
fc=10e6;
c=sin(2*3.14*fc*t);
y=x.*c;

subplot(5,1,1)
plot(t,x);
subplot(5,1,2)
plot(t,c);
subplot(5,1,3)
plot(t,y);

NFFT = 2048;
X = fftshift(fft(x,NFFT)); %FFT with FFTshift for both negative & positive frequencies
f = Fs*(-NFFT/2:NFFT/2-1)/NFFT; %Frequency Vector

subplot(5,1,4)
plot(f,abs(X)/(L),'r');
title('Magnitude of FFT');
xlabel('Frequency (Hz)')
ylabel('Magnitude |X(f)|');       
%
X2 = fftshift(fft(y,NFFT)); %FFT with FFTshift for both negative & positive frequencies
f = Fs*(-NFFT/2:NFFT/2-1)/NFFT; %Frequency Vector

subplot(5,1,5)
plot(f,abs(X2)/(L),'r');
title('Magnitude of FFT');
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…