Digital Modulation of Binary Amplitude Shift Keying
Ali Kamal (2021). Modulation BASK (https://www.mathworks.com/matlabcentral/fileexchange/57619-modulation-bask), MATLAB Central File Exchange. Retrieved .
this works really good for me , thank you , otherwise i want to demodulate this signal, any ideas?
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.
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.
I have submitted the updated code...thank you for all your notes, suggestion and time...best wishes
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?
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.
% 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
%Plot Message Singal
axis([0 1 0 4]);
%Plot Modulated Signal
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.
@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.
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.
You really should consider pooling all these files into one submission. They look almost identical.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!