Impulse Response of a piecewise function

Is it possible to take the impulse response of a piecewise function?
I am wanting to produce frequency and impulse responses for a plot with a roll off factor. My roll off factors have been defined as r1, r2, and r3 (being the ideal condition). I created a piecewise function to show the graph, but this shows it in the frequency domain.
When I use the ifft(ifftshift ) command to get the impulse response of my plot I get an error. Is there a way to make this work?
Note, the first half of my code works the way I want it to
%generate roll off plot
syms f
Pf1 = piecewise(abs(f)<(Rb/2)-fx1, 1, abs(f-Rb/2)<fx1, (1/2)*(1-sin(pi*((f-(Rb/2))/(2*fx1)))), abs(f)>(Rb/2)+fx1, 0);
Pf2 = piecewise(abs(f)<(Rb/2)-fx2, 1, abs(f-Rb/2)<fx2, (1/2)*(1-sin(pi*((f-(Rb/2))/(2*fx2)))), abs(f)>(Rb/2)+fx2, 0);
Pf3 = piecewise(abs(f)<(Rb/2)-fx3, 1, abs(f-Rb/2)<fx3, (1/2)*(1-sin(pi*((f-(Rb/2))/(2*fx3)))), abs(f)>(Rb/2)+fx3, 0);
figure
fplot(Pf1,'r')
axis([-5, 5, -5, 5]);
grid on
hold on
fplot(Pf2,'b')
hold on
fplot(Pf3,'k')
title('Frequency Response')
hold off
%Generate the impulse respnose
%Code up to this point works, error past this point
IR_Pf1 = ifft(ifftshift(Pf1));
IR_Pf2 = ifft(ifftshift(Pf2));
IR_Pf3 = ifft(ifftshift(Pf3));
figure
fplot(IR_Pf1,'r')
axis([-5, 5, -5, 5]);
grid on
hold on
fplot(IR_Pf2,'b')
hold on
fplot(IR_Pf3,'k')
title('Impulse Response')
hold off

Answers (1)

ifft() requires numerical approach wheras you feed in symbolic values therefore you need to convert the variables using subs() and then double() to make it of class double.

1 Comment

How would you approach converting a piecewise function like this?
In my case I am not wanting to sub my old value with anything, but I am wanting to evaluate it from -5 to 5.
sub1 = subs(Pf1,f, [-5:.01:5]);
double1 = double(sub1);
This code seems to return what I am wanting, but if I substitude 'double1' into my code
IR_Pf1 = ifft(ifftshift(double1));
It gives me a large amount of errors in several referencing toolboxes

Sign in to comment.

Asked:

on 11 Dec 2018

Edited:

on 11 Dec 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!