Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to extract the coefficient value and generate simulink block?

45 views
Skip to first unread message

Prashant Sandhi

unread,
May 31, 2012, 3:37:29 AM5/31/12
to
Dear All,

I have generated matlab code for sinc low pass filter and made some modifications.
I am using IWL = 32 bit; CWL = 30; in the code.

I want to extract the numerator values from 'Hd' i.e I want to extract the coefficients and write it into an excel sheet. How can I generate a simulink block out of this code?

Here is the code i use:

clear all;clc;
Data=inputdlg( {'Enter IWL:','Enter CWL:'})
IWL = str2num(Data{1}); % Enter Input Word Length
CWL = str2num(Data{2}); % Enter Coefficient Word Length
Fs = 2.677; % Sampling Frequency

N = 424; % Order
Fc = 0.1; % Cutoff Frequency
flag = 'scale'; % Sampling Flag

% Create the window vector for the design algorithm.
win = rectwin(N+1);

% Calculate the coefficients using the FIR1 function.
b = fir1(N, Fc/(Fs/2), 'low', win, flag);
Hd = dfilt.dffir(b);
% Set the arithmetic property.
set(Hd, 'Arithmetic', 'fixed', ...
'CoeffWordLength', CWL, ...
'CoeffAutoScale', true, ...
'Signed', true, ...
'InputWordLength', IWL, ...
'inputFracLength', 0, ...
'FilterInternals', 'FullPrecision');
denormalize(Hd);
k = 'coefficients'
fvtool(Hd,'Analysis','magnitude');figure(gcf)
xlswrite('coefficients.xls', coeff);

How can I do that?

It will be very helpful if some one can advise how it can be done.

Thanks in advance

prashant

Prashant Sandhi

unread,
May 31, 2012, 10:07:13 AM5/31/12
to
"Prashant Sandhi" wrote in message <jq773p$47u$1...@newscl01ah.mathworks.com>...
Hallo There,

I have found a way to read the filter coefficients and write into an excel sheet.

Here it is how I have done:
*****************************************************************
clear all;clc;
Data=inputdlg( {'Enter IWL:','Enter CWL:'})
IWL = str2num(Data{1}); % Enter Input Word Length
CWL = str2num(Data{2}); % Enter Coefficient Word Length
Fs = 2.677; % Sampling Frequency

N = 424; % Order
Fc = 0.1; % Cutoff Frequency
flag = 'scale'; % Sampling Flag

% Create the window vector for the design algorithm.
win = rectwin(N+1);

% Calculate the coefficients using the FIR1 function.
b = fir1(N, Fc/(Fs/2), 'low', win, flag);
Hd = dfilt.dffir(b);

% Set the arithmetic property.
set(Hd, 'Arithmetic', 'fixed', ...
'CoeffWordLength', CWL, ...
'CoeffAutoScale', true, ...
'Signed', true, ...
'InputWordLength', IWL, ...
'inputFracLength', 0, ...
'FilterInternals', 'FullPrecision');
denormalize(Hd);

read_coefficients = Hd.coeffs; %read_coefficients is structure type
class(read_coefficients);
conv_coefficients_CELL=struct2cell(read_coefficients);
conv_coefficients_MAT=cell2mat(conv_coefficients_CELL);
xlswrite('Sinc_Filter_Coefficients.xls', (conv_coefficients_MAT*2^IWL)');
COEFFICIENTS = (conv_coefficients_MAT*2^IWL)';
fvtool(Hd,'Analysis','freq');figure(gcf)
open ('Sinc_Filter_Coefficients.xls')
**************************************************************
Point that is missing now is how to realize the simulink block for this above filter?

Any idea there?
0 new messages