matlab lab




clear all; close all, clc;
% this clears your workspace, closes all figures, and clears command window

% This script demonstrates how to use MATLAB to generate 
% a simple signal plot. In this example, we construct
% and plot a signal x(t)=exp(-t)sin(6*pi*t)u(t+1)

% To graph a signal, the first step is to determine
% the t-axis and the x-axis to plot
% We can first decide the length of t-axis to plot
    t=[-2:0.01:3];   % "t" is from -2 to 3 in 0.01 increment
% Then evalute the signal over the range of "t" to plot

%x = exp(-t).*sin(6*pi*t).*ustep(t+1);
%%1

%x = triangle(t).*sin(6*pi*t);
%%2

x = exp(-t/2).*rect(t+1).*sin(12*pi*(t+1))+triangle(t-1).*sin(6*pi*(t-1));
%%3

figure(1); fig1=plot(t,x); % plot t vs x in figure 1
set(fig1,'Linewidth',2); % choose a wider line-width
xlabel('\it t'); % use italic 't' to label t-axis
ylabel('{\bf x}({\it t })'); % use boldface 'x' to label x-axis
title('{\bf x}_{\rm time domain}');

% ustep.m implements the unit step function u(t)
% rect.m implements the standard rectangular function rect(t)
% triangle.m implements standard triangle function triangle(t)

% Quadrature Amplitude Modulation
clc; clear all; close all;

fc = 40; % Carrier frequency in Hz
fm1 = 2; % Modulating frequency in Hz
fm2 = 5 % Modulating frequency in Hz
Fs = 1000; % Sampling frequency in Hz

t=0:1/Fs:1;
m1=cos(2*pi*fm1*t)+2*cos(3*pi*fm1*t); % Message signal 1
m2=cos(2*pi*fm2*t)+2*cos(5*pi*fm2*t); % Message signal 2

c1=cos(2*pi*fc*t); % In-phase carrier signal
c2=sin(2*pi*fc*t); % Quadrature-phase carrier signal

% Modulation
x1=m1.*c1; % Modulated signal 1
x2=m2.*c2; % Modulated signal 2
x=x1+x2;

%Demodulation
y = x.*cos(2*pi*fc*t);
[num,den] = butter(5,2*fc/Fs); % IIR lowpass filter
y = filtfilt(num,den,y)*2; % Demodulated signal


z = x.*sin(2*pi*fc*t);
[num,den] = butter(5,2*fc/Fs); % IIR lowpass filter
z = filtfilt(num,den,z)*2; % Demodulated signal





% plots
figure(1),
subplot(321); plot (t,m1)
ylabel('Amplitude'); xlabel('Time');
title('Message signal 1');
%
subplot(322); plot (t,m2)
ylabel('Amplitude'); xlabel('Time');
title('Message signal 2');
%
subplot(323); plot (t,c1)
ylabel('Amplitude'); xlabel('Time');
title('Carrier signal');
%
subplot(324); plot (t,x)
ylabel('Amplitude'); xlabel('Time');
title('QAM signal');

subplot(325); plot (t,y)
ylabel('Amplitude'); xlabel('Time');
title('QAM demodulated signal 1');

subplot(326); plot (t,z)
ylabel('Amplitude'); xlabel('Time');
title('QAM demodulated signal 2');

转载于:https://www.cnblogs.com/ronnielee/p/10489420.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值