File Exchange

image thumbnail

Modulation BASK

version 1.0.0.0 (1.33 KB) by Ali Kamal
Modulation of Binary Amplitude Shift Keying

6 Downloads

Updated 12 Jun 2016

View License

Digital Modulation of Binary Amplitude Shift Keying

Cite As

Ali Kamal (2021). Modulation BASK (https://www.mathworks.com/matlabcentral/fileexchange/57619-modulation-bask), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (11)

James Gridley

arbaoui noussaiba

this works really good for me , thank you , otherwise i want to demodulate this signal, any ideas?

Ali Kamal

@Rob Campbell
you are right, code need to be more organized with spaces to make it easy to read, I will keep this in consideration in the future submissions.

Rob Campbell

Much better. Something that helps with readability is to space out your lines for emphasis. e.g. http://www.mathworks.com/matlabcentral/fileexchange/26323-addfitline/content/addFitLine.m

Similar length to your code but more readable because of the spaces between lines.

Ali Kamal

@Rob Campbell
I have submitted the updated code...thank you for all your notes, suggestion and time...best wishes

Rob Campbell

Perhaps there is just a delay on the website, but do you realise that you can update the code you have submitted instead of posting the new version as a comment?

Ali Kamal

@Rob Campbell
thank you for your time to explain I really appreciate your suggestions .. I will try to apply it to the future submissions ... for now I made these changes as you suggest and I hope it would be useful to you.

function[v]=Modulation_BASK(F1,F2,A)

% Modulation_BASK: is one of the digital modulation techniques in which the amplitude of carrier is switched according to the binary data
%
% function arguments
% input: F1 the frequency of carrier
% F2 the frequency of message signal
% A the amplitude of the signal
% output: v the modulated signal
%
% Example: Modulation_BASK(8,4,3);

t=0:0.001:1; %Sampling Interval time 0 ≤ t ≤ 1
x=A.*sin(2*pi*F1*t); %Carrier Sine wave A sin(2πfct) fc:frequency of carrier
u=A/2.*square(2*pi*F2*t)+(A/2); %Square wave message with peak of amplitude A and and peak of zero (binary data)
v=x.*u; %Modulation Process by multiply message with carrier v(t) = A u(t) sin 2πfct
%Plot Carrier Signal
figure('name','BASK MODULATION','numbertitle','off');
subplot(3,1,1);
plot(t,x,'c','linewidth',2);
xlabel('Time');
ylabel('Amplitude');
title('Carrier');
grid on;
%Plot Message Singal
subplot(3,1,2);
plot(t,u,'r','linewidth',2);
xlabel('Time');
ylabel('Amplitude');
title('Square Pulses');
axis([0 1 0 4]);
grid on;
%Plot Modulated Signal
subplot(3,1,3);
plot(t,v,'linewidth',2);
xlabel('Time');
ylabel('Amplitude');
title('BASK Signal');
legend('BASKSIGNAL');
grid on;
end

Rob Campbell

@Ali Kamal

Let me explain: say that someone downloads your code and just runs it to see what it will do and didn't read it first. The first thing your code will do is wipe their workspace and close their figures. What if they wanted what was in their workspace? Now you've cleared it all without warning. Same with the figure windows. What reason do you even have for closing the figures?

Instead what you should do is put your code into a function using the function keyword. Now you have all your variables in their own scope and there is no need to do unexpected things with the workspace.

You say your function is clear and commented, but it isn't really. Take a look at this submission and compare it to yours: http://www.mathworks.com/matlabcentral/fileexchange/8998-surface-fitting-using-gridfit/content/gridfitdir/gridfit.m

What are the differences? You have commented the first three lines that do completely trivial things (ie clear windows). Those lines don't need comments. Your next few comments are stuff like "Amplitude" and "Sampling Interval". These also aren't helpful comments. Why? Because you could have named your variables so and removed the need for even these comments.

Thus, we are effectively left with code that has no comments at all. Since you don't even hint at what BASK is, we don't know the relevance of of the parameters you mention as comments.

To improve your code, I suggest you put in in a function and use input arguments. Have help text similar to that shown in the link I give, above. Have a section that briefly describes what BASK is. Provide a link, maybe. Describe your input arguments. etc. Provide examples in the help text.

The way you have written the function right now is not very useful.

I would also suggest you pool all your code together into one submission instead of having a dozen or so closely related submissions, as you currently do.

Ali Kamal

@Rob Campbell I don't understand the reason for your negative review ... you can remove the clear and close command if you want or make them as comment ... the code is easy and clear and there is comment on every line .. if you didn't understand something in code or have questions feel free to ask.

Rob Campbell

Actually, what on earth even is this? There are no real comments and no introduction. The first thing it does is clear the workspace and close all the user's figure windows. Bad.

Rob Campbell

You really should consider pooling all these files into one submission. They look almost identical.

MATLAB Release Compatibility
Created with R2008a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!