plotting of power spectral density (PSD) of Binary ASK in matlab

Status
Not open for further replies.

Shruti01

Member
Joined
Aug 22, 2011
Messages
26
Hello,

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
 

jplyler

Member
Premium Subscriber
Joined
Jul 30, 2003
Messages
269
Location
Cornelius, NC
The problem is the length of the input array compared to the fft length being used. Check the length of 'baskmod' compared to the fft length.

Sent from my PC36100 using Tapatalk
 

jplyler

Member
Premium Subscriber
Joined
Jul 30, 2003
Messages
269
Location
Cornelius, NC
I meant to say segment length not fft length. There is a segment length setting in the pwelch object.

Sent from my PC36100 using Tapatalk
 

jplyler

Member
Premium Subscriber
Joined
Jul 30, 2003
Messages
269
Location
Cornelius, NC
Semicolons are optional in matlab, unlike c. The lack of a semicolon will cause the output to echo to the command line.

Sent from my PC36100 using Tapatalk
 
Status
Not open for further replies.
Top