📄 f_filter.m
字号:
% test_dmod.m
% Fc = 20; Fd = 10; Fs = 50;
% M = 4; % Use 4-ASK modulation.
% x = ones(Fd,1)*[0 1]; x=x(:);
% Modulate, keeping track of time.
% [y,t] = dmod(x,Fc,Fd,Fs,'ask',M);
%plot(t,y) % Plot signal versus time.
clc;
clear;
close all;
M = 16; % Use 16-ary modulation.
Fc = 10; % Carrier signal frequency is 10 Hz.
Fd = Fc/10; % Sampling rates of original and modulated signals
Fs = Fc*10; % are 1 and 50, respectively (samples per second).
ofdm_data = 32;
x = randint(ofdm_data,1,M); % Random digital message
xl = size(x)
figure(1); stem(x);ylabel(['x rand data M = ',num2str(M)]);
% plot(x);
%subplot(2,1,1);stem(x) %plot(x);
% Use M-ary PSK modulation to produce y.
% y = dmod(x,Fc,Fd,Fs,'ask',M);
[y,t] = dmod(x,Fc,Fd,Fs,'qask',M);
y_size = size(y)
% subplot(2,1,2);plot(t(1:100),y(1:100)) % Plot signal versus time.
%subplot(2,1,2);plot(t,y);
figure(2);
plot(t,y);ylabel(['y dmod data size = ',num2str(y_size)]);
% figure(3);
% plot(t(10:1000),y(10:1000));ylabel(['y dmod data size = ',num2str(yl)]);
% Add some Gaussian noise.
% ynoisy = y + .01*randn(Fs/Fd*100,1);
% Demodulate y to recover the message.
% fx = ifft(y);
fx = fft(y,2048);
figure(3);
plot(abs(fx)); %绘制x(n)的幅度谱
% subplot(2,1,1);plot((50:150),real(fx(50:150)));
% subplot(2,1,1);plot(real(fx)); ylabel('fx real data');
% subplot(2,1,2);plot(imag(fx)); ylabel('fx imag data');
figure(4);
N = length(fx);
fxx=fx(1:N/2+1); % F(k)=X(k)(k=1:N/2+1)
n=0:length(fxx)-1;
% f=fs*n/length(y);
% f= Fc*ofdm_data*n/length(fxx); %
f= Fs*n/length(fx);
plot(f,abs(fxx)); %绘制x(n)的幅度谱
% plot((250:400),real(fx(250:400)));
% z = ddemod(ynoisy,Fc,Fd,Fs,'ask',M);
% s = symerr(x,z) % Check symbol error rate.
%
ffx = fftshift(fxx);
figure(5);
plot(f,abs(ffx));
%
% magX=abs(X); %绘制x(n)的幅度谱
% subplot(3,1,2);stem(magX);title(‘理想采样信号序列的幅度谱’);
angX=angle(fx); %绘制x(n)的相位谱
figure(6);
plot(angX);
%
[m,i]=max(abs(y))
% fx的幅度是功率谱,画出功率谱和频率的对应关系就得出了周期图,去掉第一点,因为他只是所有数据的和,画图有:
N = length(fx); % 频谱分析
[mp index] = max(power);
period(index)
% 变换后的幅度和相位
% abs()和angle()是用来计算幅度和相位的
% 先创建一信号,再进行分析,unwarp()把相位大于π的变换为2π的补角:
% ------------------------------
fr = real(fx);
fr2 = fr(1:length(fr)/2);
fr_size = size(fr)
fx2 = fx./2; % 信号衰减一倍
% figure(5);
fix = fft(fx); % ofdm 解调
figure(6);
subplot(2,1,1);plot(real(fix)); ylabel('fx real data');
subplot(2,1,2);plot(imag(fix)); ylabel('fx imag data');
fir = real(fix); %取实数
% fir2 = ceil(fir.*1000)+1000; %整数
% fir2(1:20) %显示
z = ddemod(fir,Fc,Fd,Fs,'qask',M); %qask 解调
figure(7);
subplot(2,1,1);plot(x); ylabel('x data');
subplot(2,1,2);plot(z); ylabel('z data');
rx = reshape(x,1,length(x))
rz = reshape(z,1,length(z))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -