FM modulation, demodulation Matlab code

problem statement

To be completed. . . . . It's too late, it's early morning, tomorrow will be the whole day.

write picture description here

write picture description here

write picture description here

write picture description here

write picture description here


%-------------------------------------
%2FSK调制

s=[1 0 1 1 0 0 1 0]; %原始数据
f1= 200 ;%261.6256*2*pi;
f2= 400 ;%391.9954*2*pi;
Fs =  11025;
t=0:1/(Fs-1)*10:1;
m1=[];
c1=[];
B1=[];
for n=1:length(s)
    if s(n)==0;
        m=ones(1,length(t));
        c=sin(2*pi*f1*t);
        b=zeros(1,length(t));
    else s(n)==1;
        m=ones(1,length(t));
        c=sin(2*pi*f2*t);
        b=ones(1,length(t));
    end
    m1=[m1 m]; 
    c1=[c1 c];
    B1=[B1 b];
end


fsk=c1.*m1;
gcf = figure(1);
subplot(311);
plot(B1,'r')
axis([1,length(B1),-0.2,1.2]);
title('原始信号');
%axis([0 100*length(s) -0.1 1.1]);
grid on;
subplot(312);
plot(fsk(1:1000))
title('2FSK信号');
grid on; 


%sound(fsk,Fs,8);
%wavwrite(fsk,Fs,8,'a.wav');
%------------------------
%高斯噪声
no=0.1*randn(1,length(fsk));        %噪声
fsk= 0.4*(fsk+no);%噪声加衰减
subplot(313);
plot(fsk(1:1000));
title('噪声加衰减信号');

saveas(gcf,'fm_01.png');
%---------------------------------------------------------------------------
%解调  


% 使用带通滤波进行过滤
b1=fir1(101,[0.1 0.6]);
b2=fir1(101,[0.6 0.8]);  %设置带通参数
H1=filter(b1,1,fsk);
H2=filter(b2,1,fsk);          %经过带通滤波器后的信号
gcf = figure(2);
subplot(211);

plot(H1);
title('带通0.1-0.6 结果');
subplot(212);
title('带通0.6-0.8 结果');
plot(H2);

saveas(gcf,'fm_02.png');


% 求绝对值(就是所谓的整流。。。)
H1 = abs(H1);
H2 = abs(H2);
gcf = figure(3);
subplot(211);
title('低频整流');
plot(H1);
subplot(212);
title('高频整流');
plot(H2);

%低通滤波器
b3=fir1(101,0.1);
H1_low=filter(b3,1,H1);
H2_low=filter(b3,1,H2);
saveas(gcf,'fm_03.png');

gcf = figure(4);
subplot(211);
plot(H1_low);
title('低频整流H1经过低频滤波');
subplot(212);
plot(H2_low);
title('高频整流H1经过低频滤波');

saveas(gcf,'fm_04.png');
% 表决器

z = ones(size(H1));
z(H1_low>H2_low) = 0;

%b4=fir1(101,0.1);
b3=fir1(101,0.05);
z=filter(b3,1,z);
z(z>=0.5) = 1;
z(z<0.5) = 0;
gcf = figure(5);

subplot(211);
plot(B1);
axis([1,length(z),-0.2,1.2]);
title('原始信号');
subplot(212);
plot(z);
axis([1,length(z),-0.2,1.2]);
title('解调后信号');
saveas(gcf,'fm_05.png');

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325607068&siteId=291194637