帮我写一下调制识别2FSK,4FSK和8FSK的matlab代码
时间: 2023-06-16 20:06:07 浏览: 125
以下是调制识别2FSK、4FSK和8FSK的MATLAB代码:
```matlab
% 2FSK调制识别
clear all;
close all;
clc;
% 读取调制信号
[y, Fs] = audioread('2FSK_modulated_signal.wav');
% 设置参数
f1 = 1200; % 第一个频率
f2 = 2200; % 第二个频率
T = 1/Fs; % 采样间隔
N = length(y); % 采样点数
t = (0:N-1)*T; % 时间序列
% 生成两个正弦波
sin1 = sin(2*pi*f1*t);
sin2 = sin(2*pi*f2*t);
% 两个正弦波相乘
demod_signal = y .* (sin1 + sin2);
% 经过低通滤波
[b,a] = butter(4, 2*f1/Fs); % 设计滤波器
demod_signal = filter(b,a,demod_signal); % 滤波
% 经过包络检测
envelope = abs(hilbert(demod_signal));
% 阈值判断
threshold = 0.5 * max(envelope); % 阈值
output = envelope > threshold; % 判断
% 绘制结果
figure(1);
subplot(2,1,1);
plot(t, y);
xlabel('Time (s)');
ylabel('Amplitude');
title('2FSK Modulated Signal');
subplot(2,1,2);
plot(t, output);
xlabel('Time (s)');
ylabel('Amplitude');
title('2FSK Demodulated Signal');
% 4FSK调制识别
clear all;
close all;
clc;
% 读取调制信号
[y, Fs] = audioread('4FSK_modulated_signal.wav');
% 设置参数
f1 = 1000; % 第一个频率
f2 = 1500; % 第二个频率
f3 = 2000; % 第三个频率
f4 = 2500; % 第四个频率
T = 1/Fs; % 采样间隔
N = length(y); % 采样点数
t = (0:N-1)*T; % 时间序列
% 生成四个正弦波
sin1 = sin(2*pi*f1*t);
sin2 = sin(2*pi*f2*t);
sin3 = sin(2*pi*f3*t);
sin4 = sin(2*pi*f4*t);
% 四个正弦波相乘
demod_signal1 = y .* sin1;
demod_signal2 = y .* sin2;
demod_signal3 = y .* sin3;
demod_signal4 = y .* sin4;
% 经过低通滤波
[b,a] = butter(4, 2*f1/Fs); % 设计滤波器
demod_signal1 = filter(b,a,demod_signal1); % 滤波
demod_signal2 = filter(b,a,demod_signal2); % 滤波
demod_signal3 = filter(b,a,demod_signal3); % 滤波
demod_signal4 = filter(b,a,demod_signal4); % 滤波
% 经过包络检测
envelope1 = abs(hilbert(demod_signal1));
envelope2 = abs(hilbert(demod_signal2));
envelope3 = abs(hilbert(demod_signal3));
envelope4 = abs(hilbert(demod_signal4));
% 阈值判断
threshold = 0.5 * max([envelope1;envelope2;envelope3;envelope4]); % 阈值
output = zeros(1,N);
for i=1:N
if envelope1(i) > threshold(i)
output(i) = 1;
elseif envelope2(i) > threshold(i)
output(i) = 2;
elseif envelope3(i) > threshold(i)
output(i) = 3;
elseif envelope4(i) > threshold(i)
output(i) = 4;
end
end
% 绘制结果
figure(1);
subplot(2,1,1);
plot(t, y);
xlabel('Time (s)');
ylabel('Amplitude');
title('4FSK Modulated Signal');
subplot(2,1,2);
plot(t, output);
xlabel('Time (s)');
ylabel('Amplitude');
title('4FSK Demodulated Signal');
% 8FSK调制识别
clear all;
close all;
clc;
% 读取调制信号
[y, Fs] = audioread('8FSK_modulated_signal.wav');
% 设置参数
f1 = 1000; % 第一个频率
f2 = 1200; % 第二个频率
f3 = 1400; % 第三个频率
f4 = 1600; % 第四个频率
f5 = 1800; % 第五个频率
f6 = 2000; % 第六个频率
f7 = 2200; % 第七个频率
f8 = 2400; % 第八个频率
T = 1/Fs; % 采样间隔
N = length(y); % 采样点数
t = (0:N-1)*T; % 时间序列
% 生成八个正弦波
sin1 = sin(2*pi*f1*t);
sin2 = sin(2*pi*f2*t);
sin3 = sin(2*pi*f3*t);
sin4 = sin(2*pi*f4*t);
sin5 = sin(2*pi*f5*t);
sin6 = sin(2*pi*f6*t);
sin7 = sin(2*pi*f7*t);
sin8 = sin(2*pi*f8*t);
% 八个正弦波相乘
demod_signal1 = y .* sin1;
demod_signal2 = y .* sin2;
demod_signal3 = y .* sin3;
demod_signal4 = y .* sin4;
demod_signal5 = y .* sin5;
demod_signal6 = y .* sin6;
demod_signal7 = y .* sin7;
demod_signal8 = y .* sin8;
% 经过低通滤波
[b,a] = butter(4, 2*f1/Fs); % 设计滤波器
demod_signal1 = filter(b,a,demod_signal1); % 滤波
demod_signal2 = filter(b,a,demod_signal2); % 滤波
demod_signal3 = filter(b,a,demod_signal3); % 滤波
demod_signal4 = filter(b,a,demod_signal4); % 滤波
demod_signal5 = filter(b,a,demod_signal5); % 滤波
demod_signal6 = filter(b,a,demod_signal6); % 滤波
demod_signal7 = filter(b,a,demod_signal7); % 滤波
demod_signal8 = filter(b,a,demod_signal8); % 滤波
% 经过包络检测
envelope1 = abs(hilbert(demod_signal1));
envelope2 = abs(hilbert(demod_signal2));
envelope3 = abs(hilbert(demod_signal3));
envelope4 = abs(hilbert(demod_signal4));
envelope5 = abs(hilbert(demod_signal5));
envelope6 = abs(hilbert(demod_signal6));
envelope7 = abs(hilbert(demod_signal7));
envelope8 = abs(hilbert(demod_signal8));
% 阈值判断
threshold = 0.5 * max([envelope1;envelope2;envelope3;envelope4;...
envelope5;envelope6;envelope7;envelope8]); % 阈值
output = zeros(1,N);
for i=1:N
if envelope1(i) > threshold(i)
output(i) = 1;
elseif envelope2(i) > threshold(i)
output(i) = 2;
elseif envelope3(i) > threshold(i)
output(i) = 3;
elseif envelope4(i) > threshold(i)
output(i) = 4;
elseif envelope5(i) > threshold(i)
output(i) = 5;
elseif envelope6(i) > threshold(i)
output(i) = 6;
elseif envelope7(i) > threshold(i)
output(i) = 7;
elseif envelope8(i) > threshold(i)
output(i) = 8;
end
end
% 绘制结果
figure(1);
subplot(2,1,1);
plot(t, y);
xlabel('Time (s)');
ylabel('Amplitude');
title('8FSK Modulated Signal');
subplot(2,1,2);
plot(t, output);
xlabel('Time (s)');
ylabel('Amplitude');
title('8FSK Demodulated Signal');
```
请注意,以上代码仅为示例代码,实际使用时需要根据具体情况进行修改。
阅读全文