MATLAB中的频移键控不起作用
我的FSK调制工作不正常。而不是FSK频移,我只是得到一个更高频率的ASK信号。我需要改变什么?我在代码顶部有原始信号和数字量化。 解调后的位信号和解调后的信号都很好,但FSK图看起来不正确MATLAB中的频移键控不起作用,matlab,frequency,Matlab,Frequency,我的FSK调制工作不正常。而不是FSK频移,我只是得到一个更高频率的ASK信号。我需要改变什么?我在代码顶部有原始信号和数字量化。 解调后的位信号和解调后的信号都很好,但FSK图看起来不正确 clear all clc syms t n T = 10; f = 1/T; w = 2*pi*f; N = 25; fs = 2001; syms t n a = -t - 5; b = 4*t; c = t; d = -4*t + 20; A_0 = (1/T)*(int(a,t,-5
clear all
clc
syms t n
T = 10;
f = 1/T;
w = 2*pi*f;
N = 25;
fs = 2001;
syms t n
a = -t - 5;
b = 4*t;
c = t;
d = -4*t + 20;
A_0 = (1/T)*(int(a,t,-5,-1)+int(b,t,-1,0)+ ...
int(c,t,0,4)+int(d,t,4,5));
A_n = (2/T)*(int(a*cos(n*w*t),t,-5,-1)+int(b*cos(n*w*t),t,-1,0)+ ...
int(c*cos(n*w*t),t,0,4)+int(d*cos(n*w*t),t,4,5));
B_n = (2/T)*(int(a*sin(n*w*t),t,-5,-1)+int(b*sin(n*w*t),t,-1,0)+ ...
int(c*sin(n*w*t),t,0,4)+int(d*sin(n*w*t),t,4,5));
% summation loop to get An, Bn, Vt
for n = 1:N
An(n) = (2/T)*(int(a*cos(n*w*t),t,-5,-1)+int(b*cos(n*w*t),t,-1,0)+ ...
int(c*cos(n*w*t),t,0,4)+int(d*cos(n*w*t),t,4,5));
Bn(n) = (2/T)*(int(a*sin(n*w*t),t,-5,-1)+int(b*sin(n*w*t),t,-1,0)+ ...
int(c*sin(n*w*t),t,0,4)+int(d*sin(n*w*t),t,4,5));
v_t(n) = An(n)*cos(w*n*t) + Bn(n)*sin(w*n*t);
end
Cn = sqrt((An.^2)+(Bn.^2));
%Function of original signal
Vt = A_0 + sum(v_t);
t = 0:0.01:20;
Voft = eval(Vt);
%quantization
deltaXu = 2^(-(8));
deltaXuM = 1- deltaXu ;
s = [];
ts = [];
for i=1:100:2001
ts = [ts, t(i)];
s = [s, ((Voft(i)+4)/8)*deltaXuM];
end
bitstr = [];
for i = 1:21
s(i) = round(s(i)/deltaXu);
bitstr = [bitstr, dec2bin(s(i),8)];
end
tbs(1:1000) = 1;
voltbitstr = [];
Vzeroes = 0*tbs;
Vones = 1*tbs;
for i = 1:168
if bitstr(i)=='1'
voltbitstr = [voltbitstr, Vones];
else
voltbitstr = [voltbitstr, Vzeroes];
end
end
%% FSK mod
Fc = 16000 ;
delta = 2.5e-7;
Tbit = 0:delta:(2.5e-4)-delta;
biteqn = sin(2*pi*Fc*Tbit);
biteqn1 = sin(2*pi*Fc*4*Tbit);
TSK = 0:delta:0.042-delta;
v = [];
Vzero = 0*biteqn ;
Vone = 1*biteqn1 ;
for i = 1:168
if bitstr(i) == '1'
v = [v, Vone];
else
v = [v, Vzero];
end
end
%% FSK DEmod
vdemod = diff(v);
vdemod = [vdemod, vdemod(1,end)];
envl = abs(hilbert(vdemod));
dc = 0.04;
envl = envl - dc ;
demodulation_scale = 11 ;
envl = envl.*demodulation_scale;
[b,a] = butter(10,0.15,'low');
demod = (filtfilt(b,a,envl));
bitstr2 = [];
for i=500:1000:167500
bitstr2 = [bitstr2, round(demod(i))];
end
vout = [];
r = [];
for i = 1:21
for n = 1:8
r = [r, num2str(bitstr2(8*(i-1)+n))];
end
m(i) = bin2dec(r);
r = [];
vout(i) = (m(i)/128)-1;
end
vout = vout.*4;
%% Plots
%Plot of original signal
figure(1)
subplot(2,1,1);
plot(t,eval(Vt));
xlim([0,20]);
ylabel('Amplitude');
xlabel('time[s]');
title('Created Signal');
grid on;
%Plot of frequency domain
subplot(2,1,2);
stem(1:N,Cn);
ylabel('Amplitude');
xlabel('Number of components');
title('Frequency Plot');
grid on;
%Sampled Plot
figure(2)
subplot (2,1,1);
scatter(ts, s, 'b*');
xlim([0,10]);
xlabel("time[s]");
ylabel("Amplitude");
title("Quantized signal");
grid on;
subplot(2,1,2);
plot(TSK, voltbitstr);
axis([0 2.5e-3 -0.25 2.5]);
ylabel("Amplitude");
xlabel("time(s)");
title("Sampled Bit String");
grid on;
%FSK Plots
figure(3)
subplot(3,1,1);
plot(TSK, v);
axis([0 2.5e-3 -1.2 1.2]);
ylabel("Amplitude");
xlabel("Time [s]");
title("Mod Bit String");
grid on;
subplot(3,1,2);
plot(TSK, demod);
axis([0 2.5e-3 -0.25 2.5])
ylabel("Amplitude");
xlabel("Time[s]");
title("Demod Bit String");
grid on;
subplot(3,1,3);
plot(ts, vout);
ylabel("Amplitude");
xlabel("Time[s]");
title("Demod Signal");
grid on;