تطبيقات على ماتلاب

EX:1

High pass filter

للتحميل بصيغة ماتلاب إضغط هنا

الكود البرمجي :

% Highpass FIR Filters 
%
% *Equiripple Design*

Fstop = 350;
Fpass = 400;
Astop = 65;
Apass = 0.5;
Fs = 1e3;

d = designfilt('highpassfir','StopbandFrequency',Fstop, ...
'PassbandFrequency',Fpass,'StopbandAttenuation',Astop, ...
'PassbandRipple',Apass,'SampleRate',Fs,'DesignMethod','equiripple');

fvtool(d)




EX:2

low pass filter

للتحميل بصيغة ماتلاب إضغط هنا

الكود البرمجي :

%% Lowpass FIR Filters 
%
% *Equiripple Design*

Fpass = 100;
Fstop = 150;
Apass = 1;
Astop = 65;
Fs = 1e3;

d = designfilt('lowpassfir', ...
'PassbandFrequency',Fpass,'StopbandFrequency',Fstop, ...
'PassbandRipple',Apass,'StopbandAttenuation',Astop, ...
'DesignMethod','equiripple','SampleRate',Fs);

fvtool(d)




EX:3

simulate Pulse Position Modulation (PPM) as per message signal amplitude

للتحميل بصيغة ماتلاب إضغط هنا

الكود البرمجي:

% This file simulate Pulse Position Modulation (PPM) as per message signal amplitude
% 
% Created By: JCBRO Labs
% Date: 03/06/2017
% website: www.jcbrolabs.org
% mail: jcbrolabs@gmail.com
clc; clear all; close all;
fc = 20;    %carrier frequency
fm = 2;     % message frequency
fs = 1000;  % sampling frequency
t = 1;  
n = [0:1/fs:t];
n = n(1:end - 1);
duty = 10;
% no. of samples in one square wave period
per = fs/fc;
% no. of samples in on time
on_t = per/duty;

s = square(2*pi*fc*n,duty);
s(find(s<0)) = 0;
% message signal
m = sin(2*pi*fm*n);

% Triangular wave
A=1.25;
c=A.*sawtooth(2*pi*fc*n);%Carrier sawtooth

% 
ppm = zeros(1,length(s));

% find ids where carrier is greater than message
id = find(c > m);
idd = diff(id);
iddd = find(idd ~= 1);
temp(1) = id(1);
temp(2:length(iddd)+1) = id(iddd + 1);

% ppm signal
for i = 1:length(temp)
ppm(temp(i) : temp(i) + on_t - 1) = 1;
end
% Plot
subplot(3,1,1);plot(n,m,'LineWidth',2);title('Message Signal');hold on; plot(n,c,'r','LineWidth',2);grid on;
subplot(3,1,2);plot(n,s,'LineWidth',2);title('Pulse Train');grid on; ylim([-0.2 1.2]);
subplot(3,1,3);plot(n,ppm,'LineWidth',2);title('PPM Signal'); grid on; ylim([-0.2 1.2])



EX:4

Demonstrate Amplitude Modulation.m

للتحميل اضغط هناا


الكود البرمجي:

%% Disceret Time Modulation
clc
close all
clear all 
%%X[2n]
n1=-5:1:4;
Y1=[0 -1 -0.5 0.5 1 1 1 1 0.5 0];
subplot (211)
stem (n1,Y1);
grid on
xlabel ('Time')
ylabel('Amplitude')
title('Disceret Time Signal Xn')
clc
n1=-5:1:4;
Y1=[0 -1 -0.5 0.5 1 1 1 1 0.5 0];
subplot (212)
stem ((n1+2),Y1);
grid on
xlabel ('Time')
ylabel('Amplitude')
title('Disceret Time Signal X2n')

clc
close all
clear al
%%X[n-2]
n1=-5:1:4;
Y1=[0 -1 -0.5 0.5 1 1 1 1 0.5 0];
subplot (211)
stem (n1,Y1);
grid on
xlabel ('Time')
ylabel('Amplitude')
title('Disceret Time Signal')
n1=-5:1:4;
Y1=[0 -1 -0.5 0.5 1 1 1 1 0.5 0];
subplot (212)
stem (n1+2,Y1);
grid on
xlabel ('Time')
ylabel('Amplitude')
title('Disceret Time Signal')




EX:5

Demonstration of amplitude modulation.m

للتحميل اضغط هناا



الكود البرمجي:

% Demonstrate Amplitude Modulation 
n= (1:1000);
fc=1/10;
ac=2;
y=ac*cos(2*pi*fc*n);
subplot(311)
plot(y);
title('signal')
n=(1:1000);
ac=2;
fc=1/10;
y=ac*cos(2*pi*fc*n);
bm= 1;
fm=1/100;
x= bm * sin(2*pi*fm*n);
am=(ac+x).*y/ac;
subplot(312)
plot(am);
title ('under modulation')
bm=2.5;
x= bm*sin(2*pi*fm*n);
am=(ac+x).*y/ac;
subplot(313)
plot (am);
title('Modulated wave')




EX:6

Disceret Time Modulation1.m

للتحميل اضغط هناا


الكود البرمجي:

% Demonstration of amplitude modulation 
clc 
close all;
clear all;
m = 1;
Am=5;
fa =2000 % frequency of modulating signal
Ta=1/fa;
t=0:Ta/999:6*Ta;
ym=Am*sin(2*pi*fa*t);
figure(1)
subplot(3,1,1);
plot(t,ym)
title('modulating signal')

Ac=Am/m;
fc=fa*10;
Tc=1/fc;
Yc=Ac*sin(2*pi*fc*t);
subplot(3,1,2)
plot(t,Yc)
grid on;
title ('carrier signal');

% AM modulation
Y=Ac+(1+m*sin(2*pi*fa*t)).*sin(2*pi*fc*t);
subplot(313)
plot(t,Y)
title ('Amplitude Modulated Signal')
grid on; 




7:EX

Discrete Time Modulation2.m

للتحميل اضغط هناا


الكود البرمجي:

%% Disceret Time Modulation
% EX 1 X[n]
clc
close all 
clear all 
n1=-5:1:4;
Y1=[0 -1 -0.5 0.5 1 1 1 1 0.5 0];
subplot (211)
stem (n1,Y1);
grid on
xlabel ('Time')
ylabel('Amplitude')
title('Disceret Time Signal')
clc
n1=-5:1:4;
Y1=[0 -1 -0.5 0.5 1 1 1 1 0.5 0];
subplot (212)
stem (-n1,Y1);
grid on
xlabel ('Time')


EX:8

Disceret Time Modulation3.m

للتحميل اضغط هناا


الكود البرمجي:

% Discrete -Time modulation 


% EX-1 plot a discrete time signal with a step function from -5 to 5

n = [-5 -4 -3 -2 -1 0 1 2 3 4 5];
f_one = 2*0.5.^n.* heaviside(n+2)
subplot(211)
stem(n,f_one)



EX:9

removes noise from the signal using filter.m

للتحميل اضغط هناا

الكود البرمجي:

% This file removes noise from the signal using filter
% 
% Created By: JCBRO Labs
% Date: 28/02/2018
% website: www.jcbrolabs.org
% mail: jcbrolabs@gmail.com
close all; clear all;
% 
%% simulate noisy signal
Fs = 500;
f = 20;
n = [1/Fs:1/Fs:1];
x = sin(2*pi*f*n) + sin(2*pi*f*n/5);
% add noise to the signal
y = x + rand(1,length(x));
% plot the noisy signal
subplot(2,2,1); plot(n,y);
title('Noisy Signal');
xlabel('Time (s)');
ylabel('Amplitude');

%% Spectral analysis of the signal
L = length(y);
NFFT = 2^nextpow2(L);
y_fft = abs(fft(y,NFFT));
% creating frequency axis
freq = Fs/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
subplot(2,2,2);
plot(freq,y_fft(1:NFFT/2+1)); 
title('Single-Sided Amplitude Spectrum of y(t)');
xlabel('Frequency (Hz)');
ylabel('|Y(f)|');

%% Design Filter and apply on the sequence
o = 5;
wn = [3 7]*2/Fs;
[b,a] = butter(o,wn,'bandpass');
% see frequency response of the filter
[h,w] = freqz(b,a,1024,Fs);
subplot(2,2,3);
plot(w,20*log10(abs(h)));
title('Magnitude Response of the Filter');
xlabel('Frequency (Hz)');
ylabel('Magnitude');grid on;

% Filter the signal
y_filt = filter(b,a,y);
subplot(2,2,4);
plot(n,y_filt);
title('Filtered Signal');
xlabel('Time (s)');
ylabel('Amplitude');




EX:10

Bandpass FIR Filters.m

للتحميل اضغط هناا


الكود البرمجي:

%% Bandpass FIR Filters
%
% *Equiripple Design*

Fstop1 = 150;
Fpass1 = 200;
Fpass2 = 300;
Fstop2 = 350;
Astop1 = 65;
Apass  = 0.5;
Astop2 = 65;
Fs = 1e3;

d = designfilt('bandpassfir', ...
'StopbandFrequency1',Fstop1,'PassbandFrequency1', Fpass1, ...
'PassbandFrequency2',Fpass2,'StopbandFrequency2', Fstop2, ...
'StopbandAttenuation1',Astop1,'PassbandRipple', Apass, ...
'StopbandAttenuation2',Astop2, ...
'DesignMethod','equiripple','SampleRate',Fs);

fvtool(d)


تم عمل هذا الموقع بواسطة