Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
49 views

All All: %generation of Sine Signals

The document contains MATLAB code that generates and plots various sinusoidal signals, performs convolution of sequences using both conv and filter functions, and plots the results. Code segments generate sums of sinusoidal signals with different frequencies, convolve input sequences entered by the user, and demonstrate convolution using conv, filter, and by implementing the convolution operation with a for loop. Plots of the original and convolved sequences are displayed.

Uploaded by

Ravi Purne
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

All All: %generation of Sine Signals

The document contains MATLAB code that generates and plots various sinusoidal signals, performs convolution of sequences using both conv and filter functions, and plots the results. Code segments generate sums of sinusoidal signals with different frequencies, convolve input sequences entered by the user, and demonstrate convolution using conv, filter, and by implementing the convolution operation with a for loop. Plots of the original and convolved sequences are displayed.

Uploaded by

Ravi Purne
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

clc;

clear all;
close all;
t=0:.01:2*pi;
%generation of sine signals
y1 = sin(t);
y2 = sin(2*t)/2;
y3 = sin(3*t)/3;
y4 = sin(4*t)/4;
y5 = sin(5*t)/5;
y = y1 + y2 + y3 + y4 + y5;
plot(t,y,t,y1,t,y2,t,y3,t,y4,t,y5);
legend('y','y1','y2','y3','y4','y5');
title('Generation of sum of sinusoidal signals');
ylabel('Amplitude');
xlabel('Time');
grid;

Sum of sinusoidal signal;


clc;
close all;
clear all;
t=0:0.05:3*pi;
x1 = sin(t*5);
%sine wave with period 5
x2=sin(t*9);
%sine wave with period 7
x3=x1+x2;
%sum of x1 and x2
subplot(3,1,1);
plot(t,x1);
xlabel('time');
ylabel('amplitude');
title('sin signal-');
subplot(3,1,2);
plot(t,x2);
xlabel('time');
ylabel('amplitude');
title('sin signal-2');
subplot(3,1,3);
plot(t,x3);
xlabel('time');
label('amplitude');
title('sum of sin signals');

clc;
clear all;
x=[1 2 3 4 5];
h=[1 2];
y1=conv(x,h);
len1=length(y1);
plot(y1);

x=[ 1 2 3 4 5 ];
h=[ 1 8 0 0 0 ];
%y=conv(x,h);
y1=filter(x,[1],h);
%stem(y);
stem(y1);
t=0:1:10;
plot(y1); t=0:1:10;
plot(y1);

Assign 4 : Convolution
Write a program to perform convolution of two finite length causal
sequence
Verify your answer using Conv function MATLAB
Perform the convolution using filter function

x = input('Enter x: ');
h = input('Enter h: ');
n = length(x);
k = length(h);
x1 = [x, zeros(1,k)];
h1 = [h,zeros(1,n)]; % zero padding of both x[n] and h[n] if size of
x[n] ? size of h[n]
for r =1: n+ k -1
y(r) = 0;
for i=1:n
if(r - i+1> 0)
y(r) = y(r) + x1(i)*h1(r -i+1);
m(r) = y(r);
else
end
end
end
display('Output is:' ); m
stem(m);
ylabel('y[n]');
xlabel('n');
title('Convolution without using conv function');

%Program to find the linear convolution of two sequences

x1=[1 2 6 2 3 1 4];
x2=[3 1 4 5 2];
l1=length(x1);
l2=length(x2);
ln=l1+l2-1;
t=0:1:10;
yn=conv(x1,x2);

%a=t1+l1-1;
%t=t1:a;
plot(t,x1);
%stem(t,x1);
grid on;
xlabel('time--->');
ylabel('amplitude--->');
title('First sequence');

a=t2+l2-1;
t=t2:a;
subplot(312);
stem(t,x2);
grid on;
xlabel('time--->');
ylabel('amplitude--->');
TITLE('Second sequence');

tn=t1+t2;
a=tn+ln-1;
t=tn:a;
subplot(313);
stem(t,yn);
grid on;
xlabel('time--->');
ylabel('amplitude--->');
TITLE('Convolved output');
x = input('Enter x: ');
h = input('Enter h: ');
n = length(x);
k = length(h);
x1 = [x, zeros(1,k)];
h1 = [h,zeros(1,n)]; % zero padding of both x[n] and h[n] if size of
x[n] ? size of h[n]
for r =1: n+ k -1
y(r) = 0;
for i=1:n
if(r - i+1> 0)
y(r) = y(r) + x1(i)*h1(r -i+1);
m(r) = y(r);
else
end
end
end

display('Output is:' );
figure(3);

stem(m);
y=filter(x1,1,h1);
z=conv(x,h);
display('Output is:' );
figure(1);
stem(y);ylabel('y[n]');
xlabel('n');
title('Convolution using conv function');
figure(2);
stem(z);
ylabel('y[n]');
xlabel('n');
title('Convolution using filter function');

You might also like