is the code right?

if true
% code fm
clc; clear all; close all;
fm = input('fm = ');
fc = input('fc = ');
m_index = input('Mod_index = ');
t = 0:0.001:3;
ct = cos(2*pi*fc*t);
mt = cos(2*pi*fm*t);
st = cos(2*pi*fc*t + (m_index.*sin(2*pi*fm*t)));
subplot(3,1,1)
plot(t,ct)
title('Car sig');
subplot(3,1,2)
plot(t,mt)
title('Msg sig');
subplot(3,1,3)
plot(t,st)
title(['FM for Mod_index = ', num2str(m_index)]);
%fm NB WB
clc; clear all; close all;
fm = 30;
fc = 300;
t = 0:0.0001:0.1;
B1 = 0.3;
B2 = 6;
mt = sin(2*pi*fm*t);
ct = sin(2*pi*fc*t);
nbfm = cos(2*pi*fc*t + B1*sin(2*pi*fm*t));
wbfm = cos(2*pi*fc*t + B2*sin(2*pi*fm*t));
N=1000;
w = [(-N/2)+1 : N/2];
nbfm_s = abs(fftshift(fft(nbfm,N)));
wbfm_s = abs(fftshift(fft(wbfm,N)));
subplot(5,1,1)
plot (t,mt);
title ('MsgSig');
subplot(5,1,2)
plot(t,nbfm)
title('NBFM')
subplot(5,1,3)
plot(t,wbfm)
title('WBFM')
subplot(5,1,4)
plot(w, nbfm_s);
title('FreBand - NBFM')
subplot(5,1,5)
plot(w, wbfm_s);
title('FreBand - WBFM')
%fm Mod-DeMod
clc; clf; clear all; close all;
Fm = 5;
Fc = 50;
Fs = 1000;
t = [0: Fs]/Fs;
dev = 30;
B = dev/Fm;
x = sin(2*pi*Fm*t);
y = fmmod(x,Fc,Fs,dev);
z = fmdemod(y,Fc,Fs,dev);
N= 1000;
w = [(-N/2)+1 : N/2];
fm_s = abs(fftshift(fft(y,N)));
subplot(4,1,1);
plot(t,x);
title('Mesage signal')
subplot(4,1,2)
plot(t,y);
title('FM mod')
subplot(4,1,3)
plot(t,z);
title('FM demod')
subplot(4,1,4)
plot(w, fm_s);
title(['Fre band= ', num2str(B)])
%pm
clc; clear all; close all;
t = 0:0.001:3;
fc = 7;
fm = 1;
kp = pi/2;
mt = 1 + square(2*pi*fm*t);
ct = cos(2*pi*fc*t);
st = cos(2*pi*fc*t + kp*mt);
subplot(3,1,1)
plot(t,mt);
title('Message Signal');
subplot(3,1,2)
plot(t,ct);
title('Carrier Signal');
subplot(3,1,3)
plot(t,st);
title('Phase Modulated Signal');
%pm Mod-deMod
clc; clear all; close all;
t = 0:0.001:3;
fs = 1000;
fc = 7;
fm = 1;
kpm = pi/2;
mt = 1 + square(2*pi*fm*t);
ct = cos(2*pi*fc*t);
x = pmmod(mt,fc,fs,kpm);
y = abs(pmdemod(x,fc,fs,kpm));
subplot(4,1,1)
plot(t,mt);
title('Message Signal');
subplot(4,1,2)
plot(t,ct);
title('Carrier Signal');
subplot(4,1,3)
plot(t,x);
title('Phase Modulated Signal');
subplot(4,1,4)
plot(t,y);
title('Phase Demodulated Signal');
%pam
clc; clear all; close all;
t = linspace(0,1,100000);
mt = sin(2*pi*2*t);
square_pulse = 0.5*(1+square(2*pi*16*t,15));
PAM_sig = mt.*square_pulse;
subplot(3,1,1)
plot(t, mt);
ylim([-1.5 1.5])
title('Message Signal')
subplot(3,1,2)
plot(t, square_pulse);
title('Pulse Train')
subplot(3,1,3)
plot(t,PAM_sig);
title('PAM signal')
%pcm
clc; close all; clear all;
t = 0:0.001:3;
msg = cos(2*pi*1*t);
partition = -1: 0.2: 1;
codebook = -1: 0.2: 1.2;
[index, sample_msg] = quantiz(msg,partition,codebook);
n = input('Enter bit: ');
q_msg = uencode(sample_msg, n);
bin_msg = dec2bin(q_msg, n);
subplot(3,1,1)
plot(t,msg);
title('Message Signal')
subplot(3,1,2)
plot(t,sample_msg);
title('Sampled Signal')
subplot(3,1,3)
plot(t,q_msg);
title( ['Quantized Signal for Bit = ', num2str(n)] )
%ask
clc; clear all;
b = [0 1 1 0 1 0 0 1 1 0];
n = length(b);
mt = [];
for i = 0: 1: n-1;
mt( (i*100)+1: 1: ((i+1)*100)+1 ) = b(i+1);
end
t = 0:0.01:n;
ct = sin(2*pi*3*t);
ask = mt.*ct;
subplot(3,1,1);
plot(t,ct);
title('Carrier Wave');
subplot(3,1,2);
plot(t,mt);
title('Input Bit Stream');
subplot(3,1,3);
plot(t,ask);
title('ASK Wave');
%fsk
clc; clear all; close all;
b = [0 1 1 0 1 0 0 1 1 0];
n = length(b);
mt = [];
for i = 0: 1: n-1;
mt( (i*100)+1: 1: ((i+1)*100)+1 ) = b(i+1);
end
t = 0: 0.01: n;
fc = 2;
f_dev = 4;
ct = sin(2*pi*fc*t);
fsk = sin(2*pi*(fc + f_dev*mt).*t);
subplot(3,1,1);
plot(t,ct);
title('Carrier Wave');
subplot(3,1,2);
plot(t,mt);
title('Input Bit Stream');
subplot(3,1,3);
plot(t,fsk);
title('BFSK Wave');
%psk
clc; clear all; close all;
b = [0 1 1 0 1 0 0 1 1 0];
n = length(b);
mt = [];
for i = 0: 1: n-1;
mt( (i*100)+1: 1: ((i+1)*100)+1 ) = b(i+1);
end
t = 0: 0.01: n;
fc = 3;
ct = sin(2*pi*fc*t);
psk = sin(2*pi*fc*t + pi.*mt);
subplot(3,1,1);
plot(t,ct);
title('Carrier Wave');
subplot(3,1,2);
plot(t,mt);
title('Input Bit Stream');
subplot(3,1,3);
plot(t,psk);
title('PSK Wave');
end

2 comentarios

Jan
Jan el 5 de Abr. de 2017
@Md Parves: Stop this. The bunch of meaningles question has been removed already. Use the debugger to check your code by your own and ask a specific question in a forum, if you see a problem. But posting a bunch of codes and asking, if they are "right" ist not a fair usage of the forum. As long as your code do not contain useful comments, we cannot even guess the intention of the code.
Stephen23
Stephen23 el 5 de Abr. de 2017
@Md Parves: Not a question. Needs explanation and an actual question.

Respuestas (1)

Jan
Jan el 5 de Abr. de 2017

0 votos

Perhaps. It depends on what it should calculate. The lack of comments impede the understanding of its intention.
But the code runs and the diagrams look nice. The performed operation is meaningful. I would guess: Yes, it is right.
Note: The "if true, end" is inserted as dummy contents only when teh "{} Code" button was hit without selected code. It would be nicer to delete this.

La pregunta está cerrada.

Etiquetas

Aún no se han introducido etiquetas.

Preguntada:

el 5 de Abr. de 2017

Comentada:

el 5 de Abr. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by