Code covered by the BSD License  

Highlights from
basic signal processing functions

basic signal processing functions

by

 

h.fft(x,N,W) h.ifft(x,N) h.conv(x,y) h.freqz(b,a,N,W) h.interp(x,N) h.decimate(x,N)

use_mydsp.m
clear all; close all; clc
h = mydsp % initialize my function set
%% fft
x = rand(1,100) + 1j*rand(1,100);
N = 512;
X1 = fft(x,N); % build-in
X2 = h.fft(x,N); % my func
figure;
subplot(2,1,1);
plot(10*log10(abs(X1))); hold on;
plot(10*log10(abs(X2)),'r--'); hold on;
xlim([1 N]);
ylabel('Magnitude [dB]');
title('fft function')
subplot(2,1,2);
plot(angle(X1)); hold on;
plot(angle(X2),'r--'); hold on;
xlim([1 N]);
ylabel('Phase');
legend('built-in','implemented')
%% conv
x = rand(1,100)+1j*rand(1,100);
y = rand(1,200)+1j*rand(1,200);
z1 = conv(x,y);
z2 = h.conv(x,y);
figure;
subplot(2,1,1);
plot(10*log10(abs(z1))); hold on;
plot(10*log10(abs(z2)),'r--'); hold on;
ylabel('Magnitude [dB]');
title('conv function')
subplot(2,1,2);
plot(angle(z1)); hold on;
plot(angle(z2),'r--'); hold on;
ylabel('Phase');
legend('built-in','implemented')
%% freqz
b = [1 2 3];
a = [4 5 6 7 8 9];
[H1,W1] = freqz(b,a,512,'whole');
[H2,W2] = h.freqz(b,a,512);
figure;
subplot(2,1,1);
plot(W1,20*log10(abs(H1))); hold on;
plot(W2,20*log10(abs(H2)),'r--'); hold on;
ylabel('Magnitude [dB]');
title('freqz function')
subplot(2,1,2);
plot(W1,angle(H1)); hold on;
plot(W2,angle(H2),'r--'); hold on;
ylabel('Phase');
legend('built-in','implemented')
%% interp
x = cos(2*pi*(0:0.2:20));
x2 = interp(x,4);
x3 = h.interp(x,4);
t = 0:length(x)-1;
plot(t,x,'b*'); hold on;
plot((0:length(x2)-1)/4,x2,'r'); hold on;
plot((0:length(x3)-1)/4,x3,'k--'); hold on;
legend('input data','built-in','implemented')
%% decimate
x = cos(2*pi*(0:0.01:10));
x2 = decimate(x,4);
x3 = h.decimate(x,4);
t = 0:length(x)-1;
figure;
plot(t,x,'b'); hold on;
plot((0:length(x2)-1)*4,x2,'r'); hold on;
plot((0:length(x3)-1)*4,x3,'k-'); hold on;

Contact us