0
votes

so I have the following code for an all-pass FIR filter in matlab, I have a couple of quesitons.

Firstly is the way I convolute the two together correct? The resulting signal is a few samples longer than the original.

Secondly how would I go about getting a magnitude vs. phase diagram like this one? from the coefficients I have already?

Magnitude and Phase

%% Initialise
clear all
close all
N=256;% filter tap length
Fs = 44100;      %# Samples per second
toneFreq = 50;  %# Tone frequency, in Hertz
nSeconds = 2;   %# Duration of the sound
y = sin(linspace(0, nSeconds*toneFreq*2*pi, round(nSeconds*Fs)));

rng(1, 'twister');% 
a=pi/2;
b=-a;

%% method

A = ones(N,1);%magnitude response set to 1
B = (b-a).*rand(N,1) + a;% random phase

hf=A.*(cos(B)+1j*sin(B)); %create coefficients
hn=ifft(hf); %convert to time domain
final=conv(hn,input); %filter?
1

1 Answers

0
votes
  1. Use conv(x,y,'same'). You can use help conv or doc conv to see it's documentation. RTM
  2. If you have the signal processing toolbox, use freqz. Again, RTM.