Matlab Example Programs
Matlab Example Programs
Triangular Window
clear all
clc
fs=5000;
f1=2*1000/fs;
f2=2*2000/fs;
fn=[f1 f2];
n=30;
win=window(@triang, n+1);
subplot(221);
stem(win,r);
grid on;
xlabel(time);
ylabel(amp);
title(Triangular Window);
b=firl(n,fn,bandstop,win);
subplot(222);
stem(b,k);
grid on;
xlabel(time);
ylabel(amp);
title(Impulse Response);
[h om]=freqz(b);
subplot(223);
plot(om/(2*pi)*fs,20*log10(abs(h)),m);
grid on;
xlabel(frequency);
ylabel(mag);
title(Magnitude Response);
subplot(224);
plot(om/(2*pi)*fs,unwrap(angle(h))*57.3,b);
grid on;
xlabel(frquency);
ylabel(phase);
title(Phase Reasponse);
title(Impulse Response);
[h om]=freqz(b,1,512);
subplot(223);
plot(om/(2*pi)*fs,20*log10(abs(h)),m);
grid on;
xlabel(frequency);
ylabel(mag);
title(Magnitude Response);
subplot(224);
plot(om/(2*pi)*fs,unwrap(angle(h))*57.3,b);
grid on;
xlabel(frequency);
ylabel(phase);
title(Phase Response);
stem(b,k);
grid on;
xlabel(time);
ylabel(amp);
title(Impulse Response);
[h om]=freqz(b);
subplot(223);
plot(om/(2*pi)*fs,20*log10(abs(h)),m);
grid on;
xlabel(frequency);
ylabel(mag);
title(Magnitude Response);
subplot(224);
plot(om/(2*pi)*fs,unwrap(angle(h))*57.3,b);
grid on;
xlabel(frequency);
ylabel(phase);
title(Phase Response);
ylabel(amp);
title(Flattop Window);
b=firl(n,fn,lowpass,win);
subplot(222);
stem(b,k);
grid on;
xlabel(time);
ylabel(amp);
title(Impulse Response);
[h om]=freqz(b);
subplot(223);
plot(om/(2*pi)*fs,20*log10(abs(h)),m);
grid on;
xlabel(frequency);
ylabel(mag);
title(Magnitude Response);
subplot(224);
plot(om/(2*pi)*fs,unwrap(angle(h))*57.3,b);
grid on;
xlabel(frequency);
ylabel(phase);
title(Phase Response);
subplot(211);
plot(zx);
grid on;
xlabel(Time(sec));
ylabel(Amplitude);
title(Cross Correlation);
za=xcorr(x,x)
subplot(212);
plot(zx);
grid on;
xlabel(Time(sec));
ylabel(Amplitude);
title(Auto Correlation);
C=conv(A,B);
subplot(311);
plot(A,r);
xlabel(Time(sec));
ylabel(Amplitude);
title(Signal-A);
subplot(312);
plot(A);
xlabel(Time(sec));
ylabel(Amplitude);
title(Signal-B);
subplot(313);
plot(A,m);
xlabel(Time(sec));
ylabel(Amplitude);
title(Convolution A & B);
samp_freq=100*freq;
t=0:(1/samp_freq):1;
x=sin(2*pi*freq*t);
subplot(311);
plot(t,x);
grid on;
xlabel(Time(sec));
ylabel(Amplitude);
title(Sine signal with Freq=10);
freq=50;
samp_freq=10*freq;
t=0:(1/samp_freq):1;
y=sin(2*pi*freq*t);
subplot(312);
plot(t,y);
grid on;
xlabel(Time(sec));
ylabel(Amplitude);
title(Sine signal with Freq=50);
freq=100;
samp_freq=10*freq;
t=0:(1/samp_freq):1;
z=sin(2*pi*freq*t);
subplot(313);
plot(t,z);
grid on;
xlabel(Time(sec));
ylabel(Amplitude);
title(Sine signal with Freq=100);
HDFC
4617
8653
0042
7096
4/16
K MANIKYALA RAO
412
PAVMANI11@