I have written a code for binary ASK in matlab... The code is as follows:

clc;

close all;

clear all;

no_of_bits=100;

no_of_samples=20;

threshold = 0.5;

Fs=70;

A1=5; % Amplitude

t1=linspace(0, 1, no_of_samples);

fc=cos(2*pi*1000*t1);

rand('state',123);

A = rand(1,no_of_bits); % Generate a random sequence

for i=1:no_of_bits

if (A(i)>=threshold)

A(i)=1;

else

A(i)=0;

end

end

d=A(1:no_of_bits);

for j=1:length(d)

d(j);

if (d(j)==1)

baskmod=A1.*cos(2*pi*1000*t1);

else

baskmod=0.*cos(2*pi*1000*t1);

end

baskmod;

received = baskmod;

end

subplot(2,1,1);

Q = zeros(1,length(d)); %No Quadrature Component for BASK

stem(d,Q);

xlabel('Inphase Component');

ylabel('Quadrature Phase component');

title('BASK Constellation at Transmitter');

axis([-1.5,1.5,-1,1]);

subplot(2,1,2);

h=spectrum.welch %Welch spectrum estimator

Hpsd = psd(h,baskmod,'Fs',Fs)

plot(Hpsd);

title('PSD of BASK modulated Data');

After running the above code, it is giving me following error:

h =

EstimationMethod: 'Welch'

SegmentLength: 64

OverlapPercent: 50

WindowName: 'Hamming'

SamplingFlag: 'symmetric'

??? Error using ==> signal\private\welchparse at 36

The length of the segments cannot be greater than the length of the input signal.

Error in ==> test_ask at 40

Hpsd = psd(h,baskmod,'Fs',Fs)

Can anyone tell me what is wrong in the program and why I am getting such error