Vous êtes sur la page 1sur 11

Montadar Abas Taher Matlab Examples for Signal Representation P54852 Department of Electrical, Electronic & Systems Engineering

Faculty of Engineering & Built Environment National University of Malaysia %% Example 1 [Time domain for analogue signals] clear all;close all;clc;

Prof. Mahamod Ismail

Fs=8000; % Sampling Frequency fm=10; % the signal's frequency in Hz. t1=[0:0.1*Fs]'/Fs; % Sampling time for 0.1 second t2=[0:Fs]'/Fs; % Time vector for all the signal x=sin(2*pi*fm*t1); % representation of 0.1 second of signal x % so, there are one cycle in 0.1 second %because fm=10 Hz x2=sin(2*pi*fm*t2); % representation of 1 second of signal x % Hence, there are 10 cycles in each second according % to its frequency fm=10 Hz. subplot(211); plot(t1,x);grid; subplot(212);,plot(t2,x2);grid;

Montadar Abas Taher Matlab Examples for Signal Representation Prof. Mahamod Ismail P54852 Department of Electrical, Electronic & Systems Engineering Faculty of Engineering & Built Environment National University of Malaysia %% Example 2 [Time domain for analoge signals] clear all;close all;clc; Fs=8000; % Sampling Frequency fm=100; % the signal's frequency in Hz. Fc=2000; % Carrier frequency is 2 kHz. t1=[0:0.1*Fs]'/Fs; % Sampling time for 0.1 second t2=[0:Fs]'/Fs; % Time vector for all the signal x=sin(2*pi*fm*t1); % representation of 0.1 second of signal x % so, there are 10 cycles in 0.1 second %because fm=100 Hz y=x.*sin(2*pi*Fc*t1); % Modulated signal Fc=2 kHz. x2=sin(2*pi*fm*t2); % representation of 1 second of signal x % Hence, there are 100 cycles in each second %according % to its frequency fm=100 Hz. y2=x2.*sin(2*pi*Fc*t2); % Modulated signal Fc=2 kHz. subplot(221); plot(t1,x,'r');grid; subplot(222);,plot(t1,y,'r');grid; subplot(223); plot(t2,x2,'k');grid; subplot(224);,plot(t2,y2,'k');grid;

%% Example 3 [Time/Frequency domain for analoge signals] clear all;close all;clc; Fs=1000; % Sampling Frequency T=1/Fs; % sampling time L=1000; % length of signal %% Time Domain Plot t=[0:L-1]*T; % time vector

Montadar Abas Taher Matlab Examples for Signal Representation Prof. Mahamod Ismail P54852 Department of Electrical, Electronic & Systems Engineering Faculty of Engineering & Built Environment National University of Malaysia x=0.7*sin(2*pi*150*t)+sin(2*pi*250*t); % Original Signal y=x+2*randn(size(t)); % Noisy Signal subplot(221); plot(Fs*t(1:50),x(1:50),'r');grid; xlabel('time in ms') subplot(222);,plot(Fs*t(1:50),y(1:50),'r');grid; xlabel('time in ms') %% Frequency Domain Plot NFFT=L; % Length of FFT X=fft(y,NFFT)/L; % Fourier Transform of signal x Y=fft(y,NFFT)/L; % Fourier Transform of signal y f=Fs/2*linspace(0,1,NFFT/2+1); % Frequency index subplot(223);plot(f,2*abs(X(1:NFFT/2+1)));grid; xlabel('Frequency in Hz') subplot(224);plot(f,2*abs(Y(1:NFFT/2+1)));grid; xlabel('Frequency in Hz')

Montadar Abas Taher Matlab Examples for Signal Representation Prof. Mahamod Ismail P54852 Department of Electrical, Electronic & Systems Engineering Faculty of Engineering & Built Environment National University of Malaysia %% Example 4 [Time/Frequency domain for analoge signals] clear all;close all;clc; Fs=16000; % Sampling Frequency Fm=3.4e3; % message frequency t=(0:0.01*Fs)'/Fs; % time indexing x=0.35*sin(2*pi*Fm*t); % Original Signal L=length(t); X=fft(x,L)/L; f=Fs/2*linspace(0,1,L/2+1); % Frequency index subplot(211); plot(t,x,'r');grid; subplot(212);plot(f,2*abs(X(1:L/2+1)));grid; xlabel('Frequency in Hz')

Montadar Abas Taher Matlab Examples for Signal Representation Prof. Mahamod Ismail P54852 Department of Electrical, Electronic & Systems Engineering Faculty of Engineering & Built Environment National University of Malaysia %% Example 5 [Time/Frequency domain for analoge signals] clear all;close all;clc; Fs=8000; % Sampling Frequency Fm=1750; % message frequency t=(0:0.01*Fs)'/Fs; % time indexing N=length(t); x=0.8*square(2*pi*Fm*t); % Original Signal X=fft(x,N)/N; f=Fs/2*linspace(0,1,N/2+1); % Frequency index subplot(211); plot(t,x,'r');grid; subplot(212);plot(f,2*abs(X(1:N/2+1)));grid; xlabel('Frequency in Hz')

Montadar Abas Taher Matlab Examples for Signal Representation Prof. Mahamod Ismail P54852 Department of Electrical, Electronic & Systems Engineering Faculty of Engineering & Built Environment National University of Malaysia %% Example 6 [Time domain for Digital signals] clear all;close all;clc; Ts=1/1000; % Sampling Period is 1 ms N=2000; % Number of bits are 2000 bits data=randi([0 1],N,1); t=(0:1:N-1)*Ts; % Time vector subplot(211); stem(t(1:40),data(1:40),'^r','filled');grid; subplot(212); stairs(t(1:40),data(1:40),'k');grid;

%% Example 7 [Time domain for Digital signals] clear all;close all;clc; Ts=0.1; % Sampling Period is 0.1 s N=120; % Number of bits are 120 bits t=(0:1:N-1)*Ts; % Time vector data=randi([0 1],N,1); subplot(211); stem(t,data);grid; subplot(212); stairs(t,data);grid;

Montadar Abas Taher Matlab Examples for Signal Representation P54852 Department of Electrical, Electronic & Systems Engineering Faculty of Engineering & Built Environment National University of Malaysia

Prof. Mahamod Ismail

%% Example 8 [Time domain for Digital signals] clear all;close all;clc; Fs=8000; % Sampling rate N=512; % Number of bits are 512 symbols M=16; % Alphabit size data=randi([0 M-1],N,1); %Digital Symbols t=(0:0.01*Fs)'/Fs; % Time vector stem(t(1:10),data(1:10));grid; % % In this example, the plot was for only 10 ms. We saw the sampling % frequency Fs=8000 Hz, this means Ts=1/Fs=0.125 ms. Hence; in each 1.25 ms % there are 10 symbols.

Montadar Abas Taher Matlab Examples for Signal Representation P54852 Department of Electrical, Electronic & Systems Engineering Faculty of Engineering & Built Environment National University of Malaysia

Prof. Mahamod Ismail

Montadar Abas Taher Matlab Examples for Signal Representation P54852 Department of Electrical, Electronic & Systems Engineering Faculty of Engineering & Built Environment National University of Malaysia

Prof. Mahamod Ismail

%% Example 9 [Frequency domain for Digital signals] clear all;close all;clc; % A sinusoidal signal of frequency = 1 kHz, sampled at Fs=8 kHz. % This signal must be plotted in time domain and frequency domain both in % one-sided and two sided for 1000 points. Fs=8e3; % sampling frequency N=1000; % number of data points Fm=1e3; % signal frequency t=[0:1:N-1]'/Fs; % time index x=sin(2*pi*Fm*t); figure(1); plot(t(1:N/10),x(1:N/10));grid X=abs(fft(x))/N; P=X.*X; f=[0:1:N-1]*Fs/N; figure(2); subplot(211);plot(f,X);grid; xlabel('Frequency in Hz'); subplot(212);plot(f,P);grid; xlabel('Frequency in Hz'); %% converting to one side X(2:N)=2*X(2:N); P=X.*X; f=[0:1:N/2]*Fs/N; figure(3); subplot(211);plot(f,X(1:N/2+1));grid; xlabel('Frequency in Hz'); subplot(212);plot(f,P(1:N/2+1));grid; xlabel('Frequency in Hz'); % For those working with OFDM system, if you want to find the % Peak to Average Power Ratio of the signal: L=length(X); p=max(P); m=sum(abs(X.^2))/L; paprvalue=10*log10(p/m); msgbox(num2str(paprvalue),'PAPR') figure(4); a=real(X); b=imag(X); subplot(411);stem(a); subplot(412);stem(b); c=abs(X); d=angle(X); subplot(413);stem(c); subplot(414);stem(d); 9

Montadar Abas Taher Matlab Examples for Signal Representation P54852 Department of Electrical, Electronic & Systems Engineering Faculty of Engineering & Built Environment National University of Malaysia

Prof. Mahamod Ismail

10

Montadar Abas Taher Matlab Examples for Signal Representation P54852 Department of Electrical, Electronic & Systems Engineering Faculty of Engineering & Built Environment National University of Malaysia

Prof. Mahamod Ismail

11

Vous aimerez peut-être aussi