0% found this document useful (0 votes)
68 views8 pages

Example # 1:-: Matlab Code

This document contains 5 MATLAB code examples that demonstrate concepts related to signal processing including: 1) Shifting sinusoidal waves by changing the time parameter in the function. 2) Changing the frequency of a sinusoidal wave by multiplying the time parameter by a constant. 3) Demonstrating time inversion by flipping the time vector and inverting its values. 4) Separating signals into even and odd components about the time axis. 5) Implementing the evenodd function to classify a signal as even or odd.

Uploaded by

Umair Gujjar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views8 pages

Example # 1:-: Matlab Code

This document contains 5 MATLAB code examples that demonstrate concepts related to signal processing including: 1) Shifting sinusoidal waves by changing the time parameter in the function. 2) Changing the frequency of a sinusoidal wave by multiplying the time parameter by a constant. 3) Demonstrating time inversion by flipping the time vector and inverting its values. 4) Separating signals into even and odd components about the time axis. 5) Implementing the evenodd function to classify a signal as even or odd.

Uploaded by

Umair Gujjar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

LAB #5

EXAMPLE # 1:MATLAB CODE:inc=0.01; t=-10:inc:10; f=0.1; to=2; x=sin(2*pi*f*t); y=sin(2*pi*f*(t-to)); subplot(311); hold on; plot(t,x); plot(t,y,'r:'); grid subplot(312); plot(t,x); grid subplot(313); plot(t,y,'r:'); grid

RESPONSE:1

-1 -1 0 1

-8

-6

-4

-2

1 0

-1 -1 0 1

-8

-6

-4

-2

1 0

-1 -1 0

-8

-6

-4

-2

1 0

COMMENTS:In this matlab code we can see the shifting of two waves. Wave x=sin(2*pi*f*t). Is shifted by 2 unit time as y=sin(2*pi*f*(t-to)) shown in figure as doted line. Whish is shifted to times. EXAMPLE # 2:MATLAB CODE:inc=0.01; t=-10:inc:10; f=0.1; a=2; x=sin(2*pi*f*t); y=sin(2*pi*f*(a*8*t)); subplot(311); hold on; plot(t,x); plot(t,y,'r:');

grid subplot(312); plot(t,x); grid subplot(313); plot(t,y,'r:'); grid RESPONSE:1

-1 -10 1

-8

-6

-4

-2

10

-1 -10 1

-8

-6

-4

-2

10

-1 -10

-8

-6

-4

-2

10

COMMENTS:We check the shifted response of a sin wav x=sin(2*pi*f*t) if we change in time as a*8 is multiply with time in angle of sin. So we see that by multiplying with a*8 its amplitude is same but frequencyis changed.

EXAMPLE 3:MATLAB CODE:-

inc=0.01; t=-10:inc:10; f=0.1; x=sin(2*pi*f*t); rx=fliplr(x); rt=fliplr(t); rt=-1*rt; l=length(x); subplot(311); hold on; plot(t(l/2:l),x(l/2:l)); plot(rt(1:l/2),rx(1:l/2),'r:'); grid title('example of time inversibale'); subplot(312); plot(t,x); grid ylabel('orignal signal'); subplot(313); plot(t,rx,'r:'); grid ylabel('time inversibale signal');

RESPONSE:example of time inversibale 1

-1 -10 1 orignal signal

-8

-6

-4

-2

10

-1 -10 1

-8

-6

-4

-2

10

time inversibale signal

-1 -10

-8

-6

-4

-2

10

COMMENTS:It is an example of time inversibale system.

EXAMPLE 4:-

MATLAB CODE:function[even,odd]=evenodd(signal,time,cod); revsignal=fliplr(signal); revtime=fliplr(time); revtime=-1*revtime; even=0.5*(signal+revsignal); odd=0.5*(signal-revsignal); if(cod=='d')

subplot(511); stem(time,signal,'r'); ylabel('signal'); subplot(512); stem(revtime,revsignal,'k'); ylabel('time reversal'); subplot(513); stem(time,odd); ylabel('odd'); subplot(515); stem(time,even+odd); ylabel('time reversal'); elseif(cod=='c') subplot(511); plot(time,signal,'r'); ylabel('signal'); subplot(512); plot(revtime,revsignal,'k'); ylabel('time reversal'); subplot(513); plot(time,odd); ylabel('odd'); subplot(515); plot(time,even+odd); ylabel('time reversal'); end

COMMENTS:It is a function file of checking even od signal.

EXAMPLE 5:-

MATLAB CODE:inc=0.01; t=-10+inc:inc:10-inc; f=0.2; x=sin(2*pi*f*t); [even,odd]=evenodd(x,t,'c'); RESPONSE:-

1 signal 0 -1 -1 0 1 0 -1 -1 0 1 0 -1 -1 0 -8 -6 -4 -2 0 2 4 6 8 10 -8 -6 -4 -2 0 2 4 6 8 10 -8 -6 -4 -2 0 2 4 6 8 10

odd tim e reversal

tim e reversal

1 0 -1 -1 0 -8 -6 -4 -2 0 2 4 6 8 10

COMMENTS:It is the implementation file of example 4. In this we check whether the signal is even or odd and its time invariance.

You might also like